feedback_widget: Allow undo opts to be undefined.

There's existing logic that assumes `on_undo` can be `undefined`.
(see the `opts.on_undo === undefined` if clause)

This commit updates some types to let it actually be `undefined`,
which it is in `message_edit`, which we're about to convert to
typescript.
This commit is contained in:
evykassirer 2024-08-15 10:45:42 -07:00 committed by Tim Abbott
parent b2400496fd
commit d5eb997242
1 changed files with 5 additions and 4 deletions

View File

@ -28,14 +28,14 @@ type FeedbackWidgetMeta = {
$container: JQuery | null; $container: JQuery | null;
opened: boolean; opened: boolean;
handlers_set?: boolean; handlers_set?: boolean;
undo?: () => void; undo: (() => void) | undefined;
}; };
type FeedbackWidgetOptions = { type FeedbackWidgetOptions = {
populate: (element: JQuery) => void; populate: (element: JQuery) => void;
title_text: string; title_text: string;
undo_button_text: string; undo_button_text?: string;
on_undo: () => void; on_undo?: () => void;
}; };
const meta: FeedbackWidgetMeta = { const meta: FeedbackWidgetMeta = {
@ -43,6 +43,7 @@ const meta: FeedbackWidgetMeta = {
alert_hover_state: false, alert_hover_state: false,
$container: null, $container: null,
opened: false, opened: false,
undo: undefined,
}; };
const animate = { const animate = {
@ -171,7 +172,7 @@ export function show(opts: FeedbackWidgetOptions): void {
meta.hide_me_time = Date.now() + 4000; meta.hide_me_time = Date.now() + 4000;
meta.$container.find(".feedback_title").text(opts.title_text); meta.$container.find(".feedback_title").text(opts.title_text);
meta.$container.find(".feedback_undo").text(opts.undo_button_text); meta.$container.find(".feedback_undo").text(opts.undo_button_text ?? "");
opts.populate(meta.$container.find(".feedback_content")); opts.populate(meta.$container.find(".feedback_content"));
animate.fadeIn(); animate.fadeIn();