From 1ea839da8c61e8d7b96ea404cad466e83449e23d Mon Sep 17 00:00:00 2001 From: Zak Nesler Date: Thu, 23 May 2024 13:44:52 -0400 Subject: [PATCH] improve styles and rm local entry store --- ui/src/components/entry/entry-item.tsx | 28 ++++++++++++++---- ui/src/components/entry/entry-list.tsx | 8 ++--- ui/src/components/feed/feed-item.tsx | 2 +- ui/src/hooks/queries/use-infinite-entries.ts | 31 -------------------- ui/src/hooks/use-filter-params.ts | 7 +++-- 5 files changed, 31 insertions(+), 45 deletions(-) diff --git a/ui/src/components/entry/entry-item.tsx b/ui/src/components/entry/entry-item.tsx index 0b194859..9f55b59e 100644 --- a/ui/src/components/entry/entry-item.tsx +++ b/ui/src/components/entry/entry-item.tsx @@ -1,4 +1,4 @@ -import { A, AnchorProps } from '@solidjs/router'; +import { A, AnchorProps, useMatch } from '@solidjs/router'; import { createQuery } from '@tanstack/solid-query'; import { cx } from 'class-variance-authority'; import { splitProps, type Component } from 'solid-js'; @@ -34,31 +34,47 @@ export const EntryItem: Component = props => { const getDate = () => local.entry.published_at || local.entry.updated_at; + const entryRouteMatch = useMatch(() => filter.getEntryUrl(local.entry.uuid, false)); + const isActive = () => Boolean(entryRouteMatch()); + return (

{local.entry.title}

- - {!isRead() && } + + {!isRead() && ( + + )} {!filter.params.feed_uuid && ( <> {feed()?.title} - {!!getDate() && } + {!!getDate() && } )} diff --git a/ui/src/components/entry/entry-list.tsx b/ui/src/components/entry/entry-list.tsx index cb81020f..3b012c4c 100644 --- a/ui/src/components/entry/entry-list.tsx +++ b/ui/src/components/entry/entry-list.tsx @@ -20,7 +20,7 @@ export const EntryList: Component = props => { const entries = useInfiniteEntries(); // Handle arrow navigation - useListNav(() => ({ enabled: !!props.containsActiveElement, entries: entries.localEntries() })); + useListNav(() => ({ enabled: !!props.containsActiveElement, entries: entries.getAllEntries() })); createEffect(() => { if (!listBounds.bottom || !props.containerBounds?.bottom) return; @@ -46,9 +46,9 @@ export const EntryList: Component = props => { - {entries.localEntries().length ? ( -
- + {entries.getAllEntries().length ? ( +
+ {(entry, index) => ( = props => ( {props.title} - + {props.unread_count} diff --git a/ui/src/hooks/queries/use-infinite-entries.ts b/ui/src/hooks/queries/use-infinite-entries.ts index de53fcf6..2e20945c 100644 --- a/ui/src/hooks/queries/use-infinite-entries.ts +++ b/ui/src/hooks/queries/use-infinite-entries.ts @@ -5,8 +5,6 @@ import { QUERY_KEYS } from '~/constants/query'; import { type Entry } from '~/types/bindings'; import { useFilterParams } from '../use-filter-params'; import { debounce, leading } from '@solid-primitives/scheduled'; -import { createEffect, createSignal } from 'solid-js'; -import { getEntryComparator } from '~/utils/entries'; export const useInfiniteEntries = () => { const filter = useFilterParams(); @@ -28,34 +26,6 @@ export const useInfiniteEntries = () => { const getAllEntries = () => query.data?.pages.flatMap(page => page.data) || []; - // Maintain local state of entries to prevent entries just marked as read from being removed - const [localEntries, setLocalEntries] = createSignal(getAllEntries()); - - // Associate the local entries with the feed we're viewing, so we know when to reset the data - const [localFeedKey, setLocalFeedKey] = createSignal(filter.getFeedUrl()); - - createEffect(() => { - const currentIds = localEntries().map(entry => entry.id); - const newEntries = getAllEntries().filter(entry => !currentIds.includes(entry.id)); - - // Don't bother updating local state if we've got nothing to add - if (!newEntries.length) return; - - // Add new entries and sort to maintain order - setLocalEntries([...localEntries(), ...newEntries].sort(getEntryComparator(filter.getSort()))); - }); - - createEffect(() => { - const feedKey = filter.getFeedUrl(); - - // Only reset the local cache if we look at a new feed - if (localFeedKey() === feedKey) return; - - // Reset the local cache - setLocalFeedKey(feedKey); - setLocalEntries(getAllEntries()); - }); - const fetchMore = leading( debounce, () => { @@ -69,7 +39,6 @@ export const useInfiniteEntries = () => { return { query, - localEntries, getAllEntries, fetchMore, }; diff --git a/ui/src/hooks/use-filter-params.ts b/ui/src/hooks/use-filter-params.ts index d46f2280..9e7004f9 100644 --- a/ui/src/hooks/use-filter-params.ts +++ b/ui/src/hooks/use-filter-params.ts @@ -41,13 +41,14 @@ export const useFilterParams = () => { return `?${builder.toString()}`; }; - const getFeedUrl = (append?: string) => { + const getFeedUrl = (append?: string, withQuery = true) => { const path = params.feed_uuid ? `/feeds/${params.feed_uuid}` : `/`; const withAppended = append ? path.concat(append) : path; - return withAppended.replace(/\/\//g, '/').concat(getQueryString()); + const trimmed = withAppended.replace(/\/\//g, '/'); + return withQuery ? trimmed.concat(getQueryString()) : trimmed; }; - const getEntryUrl = (entry_uuid: string) => getFeedUrl(`/entries/${entry_uuid}`); + const getEntryUrl = (entry_uuid: string, withQuery = true) => getFeedUrl(`/entries/${entry_uuid}`, withQuery); return { params,