Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
folders: Update folders data on successful request.
Sahil Batra7b4840da4128
diff --git a/web/src/channel_folders.ts b/web/src/channel_folders.tsindex f42083d0aa4..8631f8ae06d 100644--- a/web/src/channel_folders.ts+++ b/web/src/channel_folders.ts@@ -85,29 +85,51 @@ export function user_has_folders(): boolean {return false;}+export function update_channel_folder(+ folder_id: number,+ property: "name" | "description" | "rendered_description" | "is_archived",+ value: string | boolean,+): void {+ const channel_folder = get_channel_folder_by_id(folder_id);++ if (property === "is_archived") {+ assert(typeof value === "boolean");+ channel_folder.is_archived = value;+ if (channel_folder.is_archived) {+ active_channel_folder_ids.delete(channel_folder.id);+ }+ return;+ }++ assert(typeof value === "string");+ const old_value = channel_folder[property];++ channel_folder[property] = value;++ if (property === "name") {+ channel_folder_name_dict.delete(old_value);+ channel_folder_name_dict.set(channel_folder.name, channel_folder);+ }++ if (property === "rendered_description") {+ clean_up_description(channel_folder);+ }+}+export function update(event: ChannelFolderUpdateEvent): void {const folder_id = event.channel_folder_id;- const channel_folder = get_channel_folder_by_id(folder_id);if (event.data.name !== undefined) {- channel_folder_name_dict.delete(channel_folder.name);- channel_folder.name = event.data.name;- channel_folder_name_dict.set(channel_folder.name, channel_folder);+ update_channel_folder(folder_id, "name", event.data.name);}if (event.data.description !== undefined) {- channel_folder.description = event.data.description;+ update_channel_folder(folder_id, "description", event.data.description);assert(event.data.rendered_description !== undefined);- channel_folder.rendered_description = event.data.rendered_description;- clean_up_description(channel_folder);+ update_channel_folder(folder_id, "rendered_description", event.data.rendered_description);}if (event.data.is_archived !== undefined) {- channel_folder.is_archived = event.data.is_archived;- channel_folder_name_dict.delete(channel_folder.name);- channel_folder_name_dict.set(channel_folder.name, channel_folder);- if (channel_folder.is_archived) {- active_channel_folder_ids.delete(channel_folder.id);- }+ update_channel_folder(folder_id, "is_archived", event.data.is_archived);}}diff --git a/web/src/channel_folders_ui.ts b/web/src/channel_folders_ui.tsindex e466b60fb1c..7a70d7daaf3 100644--- a/web/src/channel_folders_ui.ts+++ b/web/src/channel_folders_ui.ts@@ -79,7 +79,16 @@ function archive_folder(folder_id: number): void {const data = {is_archived: JSON.stringify(true),};- dialog_widget.submit_api_request(channel.patch, url, data);+ const opts = {+ success_continuation() {+ // Update the channel folders data so that+ // the folder dropdown shows only non-archived+ // folders immediately even if client receives+ // the update event after some delay.+ channel_folders.update_channel_folder(folder_id, "is_archived", true);+ },+ };+ dialog_widget.submit_api_request(channel.patch, url, data, opts);}if (stream_ids.length === 0) {@@ -150,13 +159,31 @@ export function handle_editing_channel_folder(folder_id: number): void {id: "edit_channel_folder",on_click() {const url = "/json/channel_folders/" + folder_id.toString();+ const new_name = $<HTMLInputElement>("input#edit_channel_folder_name").val()!.trim();+ const new_description = $<HTMLTextAreaElement>(+ "textarea#edit_channel_folder_description",+ )+ .val()!+ .trim();const data = {- name: $<HTMLInputElement>("input#edit_channel_folder_name").val()!.trim(),- description: $<HTMLTextAreaElement>("textarea#edit_channel_folder_description")- .val()!- .trim(),+ name: new_name,+ description: new_description,+ };+ const opts = {+ success_continuation() {+ // Update the channel folders data so that+ // the folder dropdown shows updated folder+ // names immediately even if client receives+ // the update event after some delay.+ channel_folders.update_channel_folder(folder_id, "name", new_name);+ channel_folders.update_channel_folder(+ folder_id,+ "description",+ new_description,+ );+ },};- dialog_widget.submit_api_request(channel.patch, url, data);+ dialog_widget.submit_api_request(channel.patch, url, data, opts);},loading_spinner: true,on_shown: () => $("#edit_channel_folder_name").trigger("focus"),