1
1
import { A } from '@solidjs/router' ;
2
+ import { createQuery } from '@tanstack/solid-query' ;
2
3
import { cx } from 'class-variance-authority' ;
3
4
import dayjs from 'dayjs' ;
4
5
import { type Component } from 'solid-js' ;
6
+ import { getEntry } from '~/api/entries' ;
7
+ import { QUERY_KEYS } from '~/constants/query' ;
5
8
import { useFilterParams } from '~/hooks/use-filter-params' ;
6
9
import { Entry } from '~/types/bindings/entry' ;
7
10
import { Feed } from '~/types/bindings/feed' ;
@@ -14,20 +17,34 @@ type EntryItemProps = {
14
17
export const EntryItem : Component < EntryItemProps > = props => {
15
18
const filter = useFilterParams ( ) ;
16
19
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
+
17
29
return (
18
30
< A
19
31
href = { filter . getEntryUrl ( props . entry . uuid ) }
20
32
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
+ ) }
22
37
class = { cx (
23
38
'-mx-2 flex flex-col gap-1 rounded-lg p-2 ring-gray-300 transition dark:ring-gray-700' ,
24
39
'focus:bg-gray-100 focus:outline-none focus:ring focus:dark:bg-gray-950' ,
25
40
) }
26
41
>
27
42
< h4 class = "text-base/5 md:text-sm xl:text-base/5" > { props . entry . title } </ h4 >
43
+
28
44
< 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" /> }
29
46
< span class = "font-medium" > { props . feed . title } </ span >
30
- < span class = "text-gray-300 dark:text-gray-600" > –</ span >
47
+ < span class = "text-gray-400 dark:text-gray-600" > –</ span >
31
48
< span > { dayjs ( props . entry . published_at ) . format ( 'MMM D, YYYY' ) } </ span >
32
49
</ small >
33
50
</ A >
0 commit comments