onboarding_steps: Convert module to TypeScript.

This commit is contained in:
afeefuddin 2024-02-25 00:39:41 +05:30 committed by Tim Abbott
parent 3a03e14938
commit 28e4fe1820
3 changed files with 35 additions and 7 deletions

View File

@ -157,7 +157,7 @@ EXEMPT_FILES = make_set(
"web/src/navbar_help_menu.ts", "web/src/navbar_help_menu.ts",
"web/src/navbar_menus.js", "web/src/navbar_menus.js",
"web/src/navigate.js", "web/src/navigate.js",
"web/src/onboarding_steps.js", "web/src/onboarding_steps.ts",
"web/src/overlay_util.ts", "web/src/overlay_util.ts",
"web/src/overlays.ts", "web/src/overlays.ts",
"web/src/padded_widget.ts", "web/src/padded_widget.ts",

View File

@ -1,11 +1,12 @@
import * as blueslip from "./blueslip"; import * as blueslip from "./blueslip";
import * as channel from "./channel"; import * as channel from "./channel";
import {current_user} from "./state_data"; 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<string>();
export function post_onboarding_step_as_read(onboarding_step_name) { export function post_onboarding_step_as_read(onboarding_step_name: string): void {
channel.post({ void channel.post({
url: "/json/users/me/onboarding_steps", url: "/json/users/me/onboarding_steps",
data: {onboarding_step: onboarding_step_name}, data: {onboarding_step: onboarding_step_name},
error(err) { 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"); 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(); ONE_TIME_NOTICES_TO_DISPLAY.clear();
for (const onboarding_step of onboarding_steps) { 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); update_notice_to_display(current_user.onboarding_steps);
} }

View File

@ -21,6 +21,32 @@ export const narrow_term_schema = z.object({
export type NarrowTerm = z.output<typeof narrow_term_schema>; export type NarrowTerm = z.output<typeof narrow_term_schema>;
// Sync this with zerver.lib.events.do_events_register. // 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<typeof onboarding_steps_schema>;
export const current_user_schema = z.object({ export const current_user_schema = z.object({
avatar_source: z.string(), avatar_source: z.string(),
delivery_email: z.string(), delivery_email: z.string(),
@ -29,6 +55,7 @@ export const current_user_schema = z.object({
is_guest: z.boolean(), is_guest: z.boolean(),
is_moderator: z.boolean(), is_moderator: z.boolean(),
is_owner: z.boolean(), is_owner: z.boolean(),
onboarding_steps: z.array(onboarding_steps_schema),
user_id: z.number(), user_id: z.number(),
}); });
// Sync this with zerver.lib.events.do_events_register. // Sync this with zerver.lib.events.do_events_register.