feat(handleTitleStatusChanged): create reusable handler for sections title status management
This commit is contained in:
@@ -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);
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user