Skip to content

Commit 7ea1d14

Browse files
committed
better unread display
1 parent c31cede commit 7ea1d14

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

ui/src/components/entry/entry-item.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { A } from '@solidjs/router';
2+
import { createQuery } from '@tanstack/solid-query';
23
import { cx } from 'class-variance-authority';
34
import dayjs from 'dayjs';
45
import { type Component } from 'solid-js';
6+
import { getEntry } from '~/api/entries';
7+
import { QUERY_KEYS } from '~/constants/query';
58
import { useFilterParams } from '~/hooks/use-filter-params';
69
import { Entry } from '~/types/bindings/entry';
710
import { Feed } from '~/types/bindings/feed';
@@ -14,20 +17,34 @@ type EntryItemProps = {
1417
export const EntryItem: Component<EntryItemProps> = props => {
1518
const filter = useFilterParams();
1619

20+
// Get the data for an entry to check if user marked it as read
21+
const entryData = createQuery(() => ({
22+
enabled: filter.params.entry_uuid === props.entry.uuid,
23+
queryKey: [QUERY_KEYS.ENTRIES_VIEW, props.entry.uuid],
24+
queryFn: () => getEntry(props.entry.uuid),
25+
}));
26+
27+
const isRead = () => !!props.entry.read_at || !!entryData.data?.read_at;
28+
1729
return (
1830
<A
1931
href={filter.getEntryUrl(props.entry.uuid)}
2032
activeClass="bg-gray-100 dark:bg-gray-950"
21-
inactiveClass={cx('hover:bg-gray-100 dark:hover:bg-gray-950', props.entry.read_at && 'opacity-50')}
33+
inactiveClass={cx(
34+
'hover:bg-gray-100 dark:hover:bg-gray-950',
35+
filter.getView() === 'unread' && isRead() && 'opacity-50',
36+
)}
2237
class={cx(
2338
'-mx-2 flex flex-col gap-1 rounded-lg p-2 ring-gray-300 transition dark:ring-gray-700',
2439
'focus:bg-gray-100 focus:outline-none focus:ring focus:dark:bg-gray-950',
2540
)}
2641
>
2742
<h4 class="text-base/5 md:text-sm xl:text-base/5">{props.entry.title}</h4>
43+
2844
<small class="flex w-full gap-1 text-xs text-gray-500 dark:text-gray-400">
45+
{!isRead() && <span class="h-2 w-2 self-center rounded-full bg-gray-500 dark:bg-gray-300" />}
2946
<span class="font-medium">{props.feed.title}</span>
30-
<span class="text-gray-300 dark:text-gray-600">&ndash;</span>
47+
<span class="text-gray-400 dark:text-gray-600">&ndash;</span>
3148
<span>{dayjs(props.entry.published_at).format('MMM D, YYYY')}</span>
3249
</small>
3350
</A>

ui/src/components/entry/entry-panel.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const EntryPanel = () => {
2828

2929
markAsRead.mutateAsync(entry.data.uuid).then(() => {
3030
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.FEEDS_STATS] });
31-
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.ENTRIES_INDEX, filter.params.feed_uuid] });
3231
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.ENTRIES_VIEW, entry.data.uuid] });
3332
});
3433
});

ui/src/hooks/use-ws.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { WebSocket } from 'partysocket';
33
import { Notification } from '~/types/bindings/notification';
44
import { useQueryClient } from '@tanstack/solid-query';
55
import { QUERY_KEYS } from '~/constants/query';
6+
import { useFilterParams } from './use-filter-params';
67

78
export const useWs = () => {
9+
const filter = useFilterParams();
810
const queryClient = useQueryClient();
911

1012
const socket = new WebSocket(wsUrl('/notifs'), undefined, {
@@ -24,7 +26,7 @@ export const useWs = () => {
2426
case 'EntriesFetched':
2527
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.FEEDS] });
2628
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.FEEDS_VIEW, notif.feed_uuid] });
27-
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.ENTRIES_INDEX, notif.feed_uuid] });
29+
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.ENTRIES_INDEX, notif.feed_uuid, filter.getView()] });
2830
}
2931
});
3032
};

0 commit comments

Comments
 (0)