From 28e4fe182040bea188a4f4d302aa4a7aa212e59b Mon Sep 17 00:00:00 2001 From: afeefuddin Date: Sun, 25 Feb 2024 00:39:41 +0530 Subject: [PATCH] onboarding_steps: Convert module to TypeScript. --- tools/test-js-with-node | 2 +- ...nboarding_steps.js => onboarding_steps.ts} | 13 ++++----- web/src/state_data.ts | 27 +++++++++++++++++++ 3 files changed, 35 insertions(+), 7 deletions(-) rename web/src/{onboarding_steps.js => onboarding_steps.ts} (72%) diff --git a/tools/test-js-with-node b/tools/test-js-with-node index 605235c3ae..2bf219c833 100755 --- a/tools/test-js-with-node +++ b/tools/test-js-with-node @@ -157,7 +157,7 @@ EXEMPT_FILES = make_set( "web/src/navbar_help_menu.ts", "web/src/navbar_menus.js", "web/src/navigate.js", - "web/src/onboarding_steps.js", + "web/src/onboarding_steps.ts", "web/src/overlay_util.ts", "web/src/overlays.ts", "web/src/padded_widget.ts", diff --git a/web/src/onboarding_steps.js b/web/src/onboarding_steps.ts similarity index 72% rename from web/src/onboarding_steps.js rename to web/src/onboarding_steps.ts index 2ffd3e53ca..522e869f9c 100644 --- a/web/src/onboarding_steps.js +++ b/web/src/onboarding_steps.ts @@ -1,11 +1,12 @@ import * as blueslip from "./blueslip"; import * as channel from "./channel"; import {current_user} from "./state_data"; +import type {OnboardingSteps} from "./state_data"; -export const ONE_TIME_NOTICES_TO_DISPLAY = new Set(); +export const ONE_TIME_NOTICES_TO_DISPLAY = new Set(); -export function post_onboarding_step_as_read(onboarding_step_name) { - channel.post({ +export function post_onboarding_step_as_read(onboarding_step_name: string): void { + void channel.post({ url: "/json/users/me/onboarding_steps", data: {onboarding_step: onboarding_step_name}, error(err) { @@ -20,11 +21,11 @@ export function post_onboarding_step_as_read(onboarding_step_name) { }); } -export function filter_new_hotspots(onboarding_steps) { +export function filter_new_hotspots(onboarding_steps: OnboardingSteps[]): OnboardingSteps[] { return onboarding_steps.filter((onboarding_step) => onboarding_step.type === "hotspot"); } -export function update_notice_to_display(onboarding_steps) { +export function update_notice_to_display(onboarding_steps: OnboardingSteps[]): void { ONE_TIME_NOTICES_TO_DISPLAY.clear(); for (const onboarding_step of onboarding_steps) { @@ -34,6 +35,6 @@ export function update_notice_to_display(onboarding_steps) { } } -export function initialize() { +export function initialize(): void { update_notice_to_display(current_user.onboarding_steps); } diff --git a/web/src/state_data.ts b/web/src/state_data.ts index 48343af30f..a6aca38ec3 100644 --- a/web/src/state_data.ts +++ b/web/src/state_data.ts @@ -21,6 +21,32 @@ export const narrow_term_schema = z.object({ export type NarrowTerm = z.output; // Sync this with zerver.lib.events.do_events_register. +const hotspot_location_schema = z.object({ + element: z.string(), + offset_x: z.number(), + offset_y: z.number(), + popover: z.optional(z.string()), +}); + +const hotspot_schema = z.object({ + delay: z.number(), + description: z.string(), + has_trigger: z.boolean(), + location: z.optional(hotspot_location_schema), + name: z.string(), + title: z.string(), + type: z.literal("hotspot"), +}); + +const one_time_notice_schema = z.object({ + name: z.string(), + type: z.literal("one_time_notice"), +}); + +const onboarding_steps_schema = z.union([one_time_notice_schema, hotspot_schema]); + +export type OnboardingSteps = z.output; + export const current_user_schema = z.object({ avatar_source: z.string(), delivery_email: z.string(), @@ -29,6 +55,7 @@ export const current_user_schema = z.object({ is_guest: z.boolean(), is_moderator: z.boolean(), is_owner: z.boolean(), + onboarding_steps: z.array(onboarding_steps_schema), user_id: z.number(), }); // Sync this with zerver.lib.events.do_events_register.