refactor(chronik): replace inline filter switch with filterFeed()
Wire the extracted filterFeed function into the displayFeed derived, removing 20 lines of inline switch logic from +page.svelte. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@ import ChronikEmptyState from '$lib/components/chronik/ChronikEmptyState.svelte'
|
|||||||
import ChronikErrorCard from '$lib/components/chronik/ChronikErrorCard.svelte';
|
import ChronikErrorCard from '$lib/components/chronik/ChronikErrorCard.svelte';
|
||||||
import type { components } from '$lib/generated/api';
|
import type { components } from '$lib/generated/api';
|
||||||
import type { FilterValue } from './+page.server';
|
import type { FilterValue } from './+page.server';
|
||||||
|
import { filterFeed } from './feedFilters';
|
||||||
|
|
||||||
type ActivityFeedItemDTO = components['schemas']['ActivityFeedItemDTO'];
|
type ActivityFeedItemDTO = components['schemas']['ActivityFeedItemDTO'];
|
||||||
|
|
||||||
@@ -92,28 +93,7 @@ async function onMarkAllRead() {
|
|||||||
await notificationStore.markAllRead();
|
await notificationStore.markAllRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
const displayFeed = $derived<ActivityFeedItemDTO[]>(
|
const displayFeed = $derived(filterFeed(data.activityFeed, activeFilter));
|
||||||
(() => {
|
|
||||||
const merged = data.activityFeed;
|
|
||||||
switch (activeFilter) {
|
|
||||||
case 'alle':
|
|
||||||
return merged;
|
|
||||||
case 'fuer-dich':
|
|
||||||
return merged.filter((i) => i.kind === 'MENTION_CREATED' || i.youMentioned);
|
|
||||||
case 'hochgeladen':
|
|
||||||
return merged.filter((i) => i.kind === 'FILE_UPLOADED');
|
|
||||||
case 'transkription':
|
|
||||||
return merged.filter(
|
|
||||||
(i) =>
|
|
||||||
i.kind === 'TEXT_SAVED' ||
|
|
||||||
i.kind === 'BLOCK_REVIEWED' ||
|
|
||||||
i.kind === 'ANNOTATION_CREATED'
|
|
||||||
);
|
|
||||||
case 'kommentare':
|
|
||||||
return merged.filter((i) => i.kind === 'COMMENT_ADDED' || i.kind === 'MENTION_CREATED');
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
);
|
|
||||||
|
|
||||||
const isEmpty = $derived(displayFeed.length === 0);
|
const isEmpty = $derived(displayFeed.length === 0);
|
||||||
const emptyVariant = $derived<'first-run' | 'filter-empty' | 'inbox-zero'>(
|
const emptyVariant = $derived<'first-run' | 'filter-empty' | 'inbox-zero'>(
|
||||||
|
|||||||
Reference in New Issue
Block a user