({
context,
onNavigate,
}: {
context: PatchyContext;
onNavigate?: () => void;
})
| 91 | // search each get a few things that make sense there; anywhere else he |
| 92 | // offers something to read, what's trending and search. |
| 93 | export const PatchyMenu = ({ |
| 94 | context, |
| 95 | onNavigate, |
| 96 | }: { |
| 97 | context: PatchyContext; |
| 98 | onNavigate?: () => void; |
| 99 | }): ReactElement => { |
| 100 | const client = useQueryClient(); |
| 101 | const { logEvent } = useLogContext(); |
| 102 | const spotlight = useContext(SpotlightContext); |
| 103 | const { feedSettings } = useFeedSettings(); |
| 104 | const { onFollowTags } = useTagAndSource({ origin: Origin.Patchy }); |
| 105 | const { toggleBookmark } = useBookmarkPost(); |
| 106 | const openTune = useOpenFeedTune(Origin.Patchy); |
| 107 | const setExplain = useSetFeedExplain(Origin.Patchy); |
| 108 | const [picks, setPicks] = useState<{ |
| 109 | kind: PicksKind; |
| 110 | posts: PatchyQuickRead[]; |
| 111 | } | null>(null); |
| 112 | const [done, setDone] = useState<string[]>([]); |
| 113 | |
| 114 | const followed = feedSettings?.includeTags ?? []; |
| 115 | const isFollowing = (tag: string) => |
| 116 | followed.some((value) => value.toLowerCase() === tag.toLowerCase()); |
| 117 | |
| 118 | const getItems = (): MenuItem[] => { |
| 119 | const read: MenuItem = { |
| 120 | id: 'read', |
| 121 | label: 'What to read?', |
| 122 | icon: icon.read, |
| 123 | picks: 'feed', |
| 124 | }; |
| 125 | const trending: MenuItem = { |
| 126 | id: 'trending', |
| 127 | label: 'What’s trending?', |
| 128 | icon: icon.trending, |
| 129 | href: `${webappUrl}highlights`, |
| 130 | }; |
| 131 | const search: MenuItem = { |
| 132 | id: 'search', |
| 133 | label: 'Search daily.dev', |
| 134 | icon: icon.search, |
| 135 | onClick: spotlight?.open, |
| 136 | }; |
| 137 | const followTag = (tag: string): MenuItem => ({ |
| 138 | id: 'follow', |
| 139 | label: done.includes('follow') ? `Following #${tag}` : `Follow #${tag}`, |
| 140 | icon: icon.tag, |
| 141 | isDone: done.includes('follow'), |
| 142 | onClick: () => |
| 143 | onFollowTags({ tags: [tag] }).then(({ successful }) => { |
| 144 | if (successful) { |
| 145 | setDone((current) => [...current, 'follow']); |
| 146 | } |
| 147 | }), |
| 148 | }); |
| 149 | const bestOfTag = (tag: string): MenuItem => ({ |
| 150 | id: 'best_of', |
nothing calls this directly
no test coverage detected