Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
poll: Move types to poll_data.
Steve Howell2503de2cdd9e
diff --git a/web/src/poll_data.ts b/web/src/poll_data.tsindex fd240ce5a81..f796d7b0b0b 100644--- a/web/src/poll_data.ts+++ b/web/src/poll_data.ts@@ -66,6 +66,18 @@ const inbound_vote_schema = z.object({vote: z.number(),});+export const poll_widget_extra_data_schema = z.object({+ question: z.optional(z.string()),+ options: z.optional(z.array(z.string())),+});++export type PollWidgetExtraData = z.infer<typeof poll_widget_extra_data_schema>;++export type PollWidgetOutboundData =+ | NewOptionOutboundData+ | QuestionOutboundData+ | VoteOutboundData;+// Any single user should send add a finite number of options// to a poll. We arbitrarily pick this value.const MAX_IDX = 1000;diff --git a/web/src/poll_widget.ts b/web/src/poll_widget.tsindex 32951d887ec..137c1393b1f 100644--- a/web/src/poll_widget.ts+++ b/web/src/poll_widget.ts@@ -1,5 +1,4 @@import $ from "jquery";-import * as z from "zod/mini";import render_message_hidden_dialog from "../templates/message_hidden_dialog.hbs";import render_widgets_poll_widget from "../templates/widgets/poll_widget.hbs";@@ -11,29 +10,12 @@ import * as keydown_util from "./keydown_util.ts";import * as message_lists from "./message_lists.ts";import type {Message} from "./message_store.ts";import * as people from "./people.ts";-import type {- InboundData,- NewOptionOutboundData,- QuestionOutboundData,- VoteOutboundData,-} from "./poll_data.ts";-import {PollData} from "./poll_data.ts";+import type {InboundData, PollWidgetOutboundData} from "./poll_data.ts";+import {PollData, poll_widget_extra_data_schema} from "./poll_data.ts";import type {WidgetExtraData} from "./widgetize.ts";export type Event = {sender_id: number; data: InboundData};-export const poll_widget_extra_data_schema = z.object({- question: z.optional(z.string()),- options: z.optional(z.array(z.string())),-});--export type PollWidgetExtraData = z.infer<typeof poll_widget_extra_data_schema>;--export type PollWidgetOutboundData =- | NewOptionOutboundData- | QuestionOutboundData- | VoteOutboundData;-export function activate({$elem,callback,diff --git a/web/src/submessage.ts b/web/src/submessage.tsindex e1dde8b540d..c7a2dfb5ca4 100644--- a/web/src/submessage.ts+++ b/web/src/submessage.ts@@ -5,7 +5,8 @@ import * as channel from "./channel.ts";import type {MessageList} from "./message_list.ts";import * as message_store from "./message_store.ts";import type {Message} from "./message_store.ts";-import type {PollWidgetOutboundData} from "./poll_widget.ts";+import {poll_widget_extra_data_schema} from "./poll_data.ts";+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";@@ -27,13 +28,6 @@ export const zform_widget_extra_data_schema = z.object({type: z.literal("choices"),});-const poll_widget_extra_data_schema = z.nullable(- z.object({- question: z.optional(z.string()),- options: z.optional(z.array(z.string())),- }),-);-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 bd244c02eb6..2a3bfcf7c2d 100644--- a/web/src/widgetize.ts+++ b/web/src/widgetize.ts@@ -3,7 +3,8 @@ import $ from "jquery";import * as blueslip from "./blueslip.ts";import * as message_lists from "./message_lists.ts";import type {Message} from "./message_store.ts";-import type {Event, PollWidgetExtraData, PollWidgetOutboundData} from "./poll_widget.ts";+import type {PollWidgetExtraData, PollWidgetOutboundData} from "./poll_data.ts";+import type {Event} from "./poll_widget.ts";import type {TodoWidgetExtraData, TodoWidgetOutboundData} from "./todo_widget.ts";import type {ZFormExtraData} from "./zform.ts";