Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve admin listeners list transition performance on large number of nodes #180

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions front/admin/src/routes/(online)/(app)/listeners/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import PageTop from "$lib/components/PageMenu/PageTop.svelte";
import { mdiConnection } from "@mdi/js";
import { now } from "$share/now";
import { slide } from "svelte/transition";
import { fly, slide, type TransitionConfig } from "svelte/transition";
import { onMount } from "svelte";
import { default_logger } from "$share/logger";
import { sleep } from "$share/util";
Expand Down Expand Up @@ -89,34 +89,41 @@
}))}`
}

const toggle_station = (item: Item) => {
const target = station_toggle_link(item);
history.replaceState(history.state, "", target);
searchParams = new URLSearchParams(location.search)
}

const deployment_toggle_link = (item: Item): string => {
return `/listeners${qs(make_params({
deployment: q_deployment_id === item.deployment_id ? null : item.deployment_id
}))}`
}

const referer_toggle_link = (ref: string | null): string => {
return `/listeners${qs(make_params({
referer: q_referer === ref ? null : String(ref)
}))}`
}

let navigating = true;

const toggle_deployment = (item: Item) => {
const target = deployment_toggle_link(item);
history.replaceState(history.state, "", target);
navigating = true;
searchParams = new URLSearchParams(location.search)
}

const referer_toggle_link = (ref: string | null): string => {
return `/listeners${qs(make_params({
referer: q_referer === ref ? null : String(ref)
}))}`
const toggle_station = (item: Item) => {
const target = station_toggle_link(item);
history.replaceState(history.state, "", target);
navigating = true;
searchParams = new URLSearchParams(location.search)
sleep(5).then(() => navigating = false)
}

const toggle_referer = (ref: string | null) => {
const target = referer_toggle_link(ref);
history.replaceState(history.state, "", target);
navigating = true;
searchParams = new URLSearchParams(location.search)
sleep(5).then(() => navigating = false)
}

const SEC = 1_000;
Expand Down Expand Up @@ -209,6 +216,23 @@
mounted = false;
}
})

const transition_item = (node: HTMLElement, dir: boolean) => {
if(navigating) {
node.style.opacity = dir ? "0" : "";
return () => {
sleep(3).then(() => node.style.opacity = dir ? "" : "0");
return {
duration: 500,
}
}
} else {
return slide(node, { duration: 400 })
}
}

const enter_item = ((node: HTMLElement) => transition_item(node, true)) as (node: HTMLElement, args: any) => TransitionConfig;
const leave_item = ((node: HTMLElement) => transition_item(node, false)) as (node: HTMLElement, args: any) => TransitionConfig;
</script>

<style>
Expand All @@ -231,6 +255,7 @@
padding: 1rem 1rem;
border-radius: 0.5rem;
font-size: 0.9rem;
transition: opacity 500ms ease;
}

.pic {
Expand Down Expand Up @@ -304,7 +329,7 @@
{#each show_items as item (item._id)}
{@const station = item_station(item)}
{@const referer = website(item)}
<div class="item" class:open={item.is_open} class:closed={!item.is_open} transition:slide|local={{ duration: 400 }}>
<div class="item" class:open={item.is_open} class:closed={!item.is_open} in:enter_item|local out:leave_item|local>
<div class="pic" class:empty={station == null} style:background-image={
station != null ?
`url(${data.config.storage_public_url}/station-pictures/webp/128/${station?.picture_id}.webp?v=${STATION_PICTURES_VERSION})` :
Expand Down