widgetize: Fix type of data field.

This commit is contained in:
Varun Singh
2024-08-11 22:19:43 +05:30
committed by Tim Abbott
parent 2cf09602df
commit fcb9c7be26
2 changed files with 20 additions and 6 deletions

View File

@@ -5,7 +5,9 @@ import * as channel from "./channel";
import type {MessageList} from "./message_lists";
import * as message_store from "./message_store";
import type {Message} from "./message_store";
import type {PollWidgetOutboundData} from "./poll_widget";
import {todo_widget_extra_data_schema} from "./todo_widget";
import type {TodoWidgetOutboundData} from "./todo_widget";
import * as widgetize from "./widgetize";
export type Submessage = {
@@ -215,8 +217,14 @@ export function handle_event(submsg: Submessage): void {
export function make_server_callback(
message_id: number,
): (opts: {msg_type: string; data: string}) => void {
return function (opts: {msg_type: string; data: string}) {
): (opts: {
msg_type: string;
data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
}) => void {
return function (opts: {
msg_type: string;
data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
}) {
const url = "/json/submessage";
void channel.post({

View File

@@ -3,7 +3,8 @@ import $ from "jquery";
import * as blueslip from "./blueslip";
import * as message_lists from "./message_lists";
import type {Message} from "./message_store";
import type {Event, PollWidgetExtraData} from "./poll_widget";
import type {Event, PollWidgetExtraData, PollWidgetOutboundData} from "./poll_widget";
import type {TodoWidgetOutboundData} from "./todo_widget";
// TODO: This ZFormExtraData type should be moved to web/src/zform.js when it will be migrated
type ZFormExtraData = {
@@ -26,13 +27,16 @@ type WidgetOptions = {
events: Event[];
$row: JQuery;
message: Message;
post_to_server: (data: {msg_type: string; data: string}) => void;
post_to_server: (data: {
msg_type: string;
data: string | PollWidgetOutboundData | TodoWidgetOutboundData;
}) => void;
};
type WidgetValue = Record<string, unknown> & {
activate: (data: {
$elem: JQuery;
callback: (data: string) => void;
callback: (data: string | PollWidgetOutboundData | TodoWidgetOutboundData) => void;
message: Message;
extra_data: WidgetExtraData;
}) => (events: Event[]) => void;
@@ -66,7 +70,9 @@ export function activate(in_opts: WidgetOptions): void {
return;
}
const callback = function (data: string): void {
const callback = function (
data: string | PollWidgetOutboundData | TodoWidgetOutboundData,
): void {
post_to_server({
msg_type: "widget",
data,