Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
zform (trivia bot): Extract zform_data.
Steve Howella1115a6594a2
diff --git a/web/src/submessage.ts b/web/src/submessage.tsindex c7a2dfb5ca4..92b98a7fc32 100644--- a/web/src/submessage.ts+++ b/web/src/submessage.ts@@ -10,24 +10,12 @@ import type {PollWidgetOutboundData} from "./poll_data.ts";import {todo_widget_extra_data_schema} from "./todo_widget.ts";import type {TodoWidgetOutboundData} from "./todo_widget.ts";import * as widgetize from "./widgetize.ts";+import {zform_widget_extra_data_schema} from "./zform_data.ts";export type Submessage = z.infer<typeof message_store.submessage_schema>;type WidgetOutboundData = PollWidgetOutboundData | TodoWidgetOutboundData;-export const zform_widget_extra_data_schema = z.object({- choices: z.array(- z.object({- type: z.string(),- long_name: z.string(),- reply: z.string(),- short_name: z.string(),- }),- ),- heading: z.string(),- type: z.literal("choices"),-});-const widget_data_event_schema = z.object({sender_id: z.number(),data: z.discriminatedUnion("widget_type", [diff --git a/web/src/widgetize.ts b/web/src/widgetize.tsindex 83140773c0d..ccf33c8c492 100644--- a/web/src/widgetize.ts+++ b/web/src/widgetize.ts@@ -6,7 +6,7 @@ import type {Message} from "./message_store.ts";import type {PollWidgetExtraData, PollWidgetOutboundData} from "./poll_data.ts";import type {TodoWidgetExtraData, TodoWidgetOutboundData} from "./todo_widget.ts";import type {Event} from "./widget_data.ts";-import type {ZFormExtraData} from "./zform.ts";+import type {ZFormExtraData} from "./zform_data.ts";export type WidgetExtraData = PollWidgetExtraData | TodoWidgetExtraData | ZFormExtraData | null;diff --git a/web/src/zform.ts b/web/src/zform.tsindex 97635fccbbf..7fe68e95c1e 100644--- a/web/src/zform.ts+++ b/web/src/zform.ts@@ -1,16 +1,14 @@import $ from "jquery";-import type * as z from "zod/mini";import render_widgets_zform_choices from "../templates/widgets/zform_choices.hbs";import * as blueslip from "./blueslip.ts";import type {Message} from "./message_store.ts";-import {zform_widget_extra_data_schema} from "./submessage.ts";import * as transmit from "./transmit.ts";import type {Event} from "./widget_data.ts";import type {WidgetExtraData} from "./widgetize.ts";--export type ZFormExtraData = z.infer<typeof zform_widget_extra_data_schema>;+import {zform_widget_extra_data_schema} from "./zform_data.ts";+import type {ZFormExtraData} from "./zform_data.ts";export function activate(opts: {$elem: JQuery;diff --git a/web/src/zform_data.ts b/web/src/zform_data.tsnew file mode 100644index 00000000000..2e7d21ce707--- /dev/null+++ b/web/src/zform_data.ts@@ -0,0 +1,28 @@+import * as z from "zod/mini";++/*+ The zform widget is essentially support for creating+ a "choices" form that presents the user (in a message+ in the messages view) with a list of choices and+ buttons to push.++ The prime example of this is our trivia bot.++ See docs/subsystems/widgets.md and go to the+ zform-trivia-quiz-bot section for more details.+*/++export const zform_widget_extra_data_schema = z.object({+ choices: z.array(+ z.object({+ type: z.string(),+ long_name: z.string(),+ reply: z.string(),+ short_name: z.string(),+ }),+ ),+ heading: z.string(),+ type: z.literal("choices"),+});++export type ZFormExtraData = z.infer<typeof zform_widget_extra_data_schema>;