Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

inbox: Animate collapse / expand of channels and folders.

Aman Agrawal0e9fe75ba444
diff --git a/tools/test-js-with-node b/tools/test-js-with-node
index 8f39be74331..10e9a4494ac 100755
--- a/tools/test-js-with-node
+++ b/tools/test-js-with-node
@@ -52,6 +52,7 @@ EXEMPT_FILES = make_set(
"web/src/admin.ts",
"web/src/alert_popup.ts",
"web/src/alert_words_ui.ts",
+ "web/src/animate.ts",
"web/src/assets.d.ts",
"web/src/attachments.ts",
"web/src/attachments_ui.ts",
diff --git a/web/src/animate.ts b/web/src/animate.ts
new file mode 100644
index 00000000000..6f44594afe4
--- /dev/null
+++ b/web/src/animate.ts
@@ -0,0 +1,109 @@
+import $ from "jquery";
+
+export function collapse_or_expand({
+ toggle_class,
+ // Element which stores the toggle class and is being expanded/collapsed.
+ $toggle_container,
+ // Element which will be shown/hidden.
+ $content,
+ // List of all the elements including the toggle container and content.
+ // If rows other than toggle container and content could be grouped,
+ // provide the parent container instead of the individual rows.
+ $all_elements,
+ // Duration of the animation in milliseconds.
+ duration,
+}: {
+ toggle_class: string;
+ $toggle_container: JQuery;
+ $content: JQuery;
+ $all_elements: JQuery;
+ duration: number;
+}): void {
+ // We use a blocker to avoid any content from being
+ // visible below the last item. This function assumes
+ // that blocker is always the last element.
+ const $blocker = $all_elements.last();
+ // Expand the container.
+ if ($toggle_container.hasClass(toggle_class)) {
+ $toggle_container.removeClass(toggle_class);
+
+ const height = $content.outerHeight();
+ // Set height of the blocker to the height of the content,
+ // to avoid any content from showing below the last element.
+ $blocker.css("height", `${height}px`);
+ $content.addClass("content-expand-animation-start");
+
+ let found_container_wrapper = false;
+ // Move all the elements below the $toggle_container up
+ // by the height of the $content.
+ $all_elements.each((_index, elt) => {
+ if (found_container_wrapper) {
+ $(elt).addClass("mark-element-for-translation");
+ $(elt).css({
+ transform: `translateY(-${height}px)`,
+ });
+ }
+ if (elt === $content[0]) {
+ found_container_wrapper = true;
+ }
+ });
+
+ // Force the browser to reflow the page so that the transform is applied.
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
+ $content[0]!.offsetHeight;
+ found_container_wrapper = false;
+ $all_elements.each((_index, elt) => {
+ if (found_container_wrapper) {
+ $(elt).css({
+ transform: `translateY(0)`,
+ transition: "transform 0.2s ease-in-out",
+ });
+ }
+ if (elt === $content[0]) {
+ found_container_wrapper = true;
+ $content
+ .addClass("content-expand-animation-end")
+ .removeClass("content-expand-animation-start");
+ }
+ });
+ } else {
+ // Collapse the container.
+ const height = $content.outerHeight();
+ $blocker.css("height", `${height}px`);
+ $content.addClass("content-collapse-animation-start");
+ let found_container_wrapper = false;
+ $all_elements.each((_index, elt) => {
+ if (found_container_wrapper) {
+ $(elt).addClass("mark-element-for-translation");
+ $(elt).css({
+ transform: `translateY(-${height}px)`,
+ transition: "transform 0.2s ease-in-out",
+ });
+ }
+ if (elt === $content[0]) {
+ found_container_wrapper = true;
+ $content
+ .addClass("content-collapse-animation-end")
+ .removeClass("content-collapse-animation-start");
+ }
+ });
+ setTimeout(() => {
+ $toggle_container.addClass(toggle_class);
+ }, duration);
+ }
+
+ // Reset
+ setTimeout(() => {
+ $all_elements.each((_index, elt) => {
+ $(elt).css({
+ transform: "",
+ transition: "",
+ });
+ $(elt).removeClass("mark-element-for-translation");
+ });
+ $blocker.css("height", "");
+ $content.removeClass(
+ "content-expand-animation-start content-expand-animation-endcontent-collapse-animation-start content-collapse-animation-end",
+ );
+ }, duration);
+}
diff --git a/web/src/bundles/app.ts b/web/src/bundles/app.ts
index 26d9a58d1eb..844ef3c8f84 100644
--- a/web/src/bundles/app.ts
+++ b/web/src/bundles/app.ts
@@ -60,6 +60,7 @@ import "../../styles/widgets.css";
import "../../styles/print.css";
import "../../styles/inbox.css";
import "../../styles/color_picker.css";
+import "../../styles/animate.css";
import "@uppy/core/css/style.min.css";
import "@uppy/image-editor/css/style.min.css";
diff --git a/web/src/inbox_ui.ts b/web/src/inbox_ui.ts
index fc9bc6ada06..975a2705a60 100644
--- a/web/src/inbox_ui.ts
+++ b/web/src/inbox_ui.ts
@@ -12,6 +12,7 @@ import render_inbox_view from "../templates/inbox_view/inbox_view.hbs";
import render_introduce_zulip_view_modal from "../templates/introduce_zulip_view_modal.hbs";
import render_user_with_status_icon from "../templates/user_with_status_icon.hbs";
+import * as animate from "./animate.ts";
import * as buddy_data from "./buddy_data.ts";
import * as channel_folders from "./channel_folders.ts";
import * as compose_closed_ui from "./compose_closed_ui.ts";
@@ -1383,16 +1384,49 @@ function filter_should_hide_stream_row({
}
export function collapse_or_expand(container_id: string): void {
- $(`#${container_id}`).toggleClass("inbox-collapsed-state");
+ const animation_duration = 200; // ms
+ const $toggle_container = $(`#${container_id}`);
+ let $all_elements = $(".inbox-header.inbox-folder, .inbox-folder-components");
+ const $blocker = $("#inbox-animation-extra-content-blocker");
+ $all_elements = $all_elements.add($blocker);
+ // If a folder was expanded/collapsed.
+ if ($toggle_container.hasClass("inbox-folder")) {
+ const $content = $toggle_container.next(".inbox-folder-components");
+ animate.collapse_or_expand({
+ toggle_class: "inbox-collapsed-state",
+ $toggle_container,
+ $content,
+ $all_elements,
+ duration: animation_duration,
+ });
+ // If a channel was expanded/collapsed.
+ } else {
+ const $content = $toggle_container.next(".inbox-topic-container");
+ // Remove parent`.inbox-folder-components` and
+ // add it's contents to `$all_elements`.
+ const $parent_folder_components = $toggle_container.closest(".inbox-folder-components");
+ $all_elements = $all_elements.not($parent_folder_components);
+ const $parent_folder_components_children = $parent_folder_components.children().children();
+ $all_elements = $all_elements.add($parent_folder_components_children);
+ animate.collapse_or_expand({
+ toggle_class: "inbox-collapsed-state",
+ $toggle_container,
+ $content,
+ $all_elements,
+ duration: animation_duration,
+ });
+ }
if (collapsed_containers.has(container_id)) {
collapsed_containers.delete(container_id);
+ update_collapsed_note_visibility();
} else {
collapsed_containers.add(container_id);
+ // Show after the animation is complete.
+ setTimeout(update_collapsed_note_visibility, animation_duration);
}
save_data_to_ls();
- update_collapsed_note_visibility();
}
// We show the note "All of your unread conversations are hidden.
diff --git a/web/styles/animate.css b/web/styles/animate.css
new file mode 100644
index 00000000000..008c53c51f8
--- /dev/null
+++ b/web/styles/animate.css
@@ -0,0 +1,27 @@
+.content-expand-animation-start {
+ opacity: 0;
+}
+
+.content-expand-animation-end {
+ opacity: 1;
+ transition: opacity 0.2s ease-in-out;
+}
+
+.content-collapse-animation-start {
+ opacity: 1;
+}
+
+.content-collapse-animation-end {
+ opacity: 0;
+ transition: opacity 0.2s ease-in-out;
+}
+
+.collapse-expand-animation-extra-content-blocker {
+ z-index: 10000;
+ position: relative;
+}
+
+.mark-element-for-translation {
+ position: relative;
+ z-index: 1;
+}
diff --git a/web/styles/inbox.css b/web/styles/inbox.css
index 8e375dd12c6..004f3694b25 100644
--- a/web/styles/inbox.css
+++ b/web/styles/inbox.css
@@ -796,3 +796,7 @@
}
}
}
+
+#inbox-animation-extra-content-blocker {
+ background: var(--color-background-inbox);
+}
diff --git a/web/templates/inbox_view/inbox_view.hbs b/web/templates/inbox_view/inbox_view.hbs
index aa07bde4525..8a57cd8dbc7 100644
--- a/web/templates/inbox_view/inbox_view.hbs
+++ b/web/templates/inbox_view/inbox_view.hbs
@@ -40,6 +40,7 @@
</button>
</div>
</div>
+ <div id="inbox-animation-extra-content-blocker" class="collapse-expand-animation-extra-content-blocker"></div>
<div id="inbox-loading-indicator">
{{#unless normal_view}}
{{> ../view_bottom_loading_indicator}}