feat(handleTitleStatusChanged): create reusable handler for sections title status management

This commit is contained in:
Ilia Mashkov
2026-02-27 12:49:13 +03:00
parent 9f84769fba
commit 8fa376ef94

View File

@@ -0,0 +1,29 @@
import type { TitleStatusChangeHandler } from '$shared/ui';
import type { Snippet } from 'svelte';
import { scrollBreadcrumbsStore } from '../../store/scrollBreadcrumbsStore.svelte';
/**
* Updates the breadcrumb store when the title visibility status changes.
*
* @param index - Index of the section
* @param isPast - Whether the section is past the current scroll position
* @param title - Snippet for a title itself
* @param id - ID of the section
* @returns Cleanup callback
*/
export const handleTitleStatusChanged: TitleStatusChangeHandler = (
index: number,
isPast: boolean,
title?: Snippet<[{ className?: string }]>,
id?: string,
) => {
if (isPast && title) {
scrollBreadcrumbsStore.add({ index, title, id });
} else {
scrollBreadcrumbsStore.remove(index);
}
return () => {
scrollBreadcrumbsStore.remove(index);
};
};