()
| 310 | ); |
| 311 | |
| 312 | export const CoverTopics = (): ReactElement => { |
| 313 | const { logEvent } = useLogContext(); |
| 314 | const [isSettingsOpen, setIsSettingsOpen] = useState(false); |
| 315 | const { isOnboardingComplete } = useOnboardingActions(); |
| 316 | const { data, isPending } = useQuery({ |
| 317 | ...dailyHeadlinesQueryOptions(), |
| 318 | enabled: isOnboardingComplete, |
| 319 | }); |
| 320 | const { data: channelData } = useQuery(channelConfigurationsQueryOptions()); |
| 321 | const [getHeadlines, setHeadlines] = useUpdateQuery( |
| 322 | dailyHeadlinesQueryOptions(), |
| 323 | ); |
| 324 | |
| 325 | const updatePost = useCallback<UpdateDailyPost>( |
| 326 | (postId, manipulate) => { |
| 327 | const current = getHeadlines(); |
| 328 | |
| 329 | if (!current) { |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | current.dailyHeadlines.edges.forEach((edge) => { |
| 334 | if (edge.node.id === postId) { |
| 335 | Object.assign(edge.node, manipulate(edge.node)); |
| 336 | } |
| 337 | }); |
| 338 | |
| 339 | setHeadlines(current); |
| 340 | }, |
| 341 | [getHeadlines, setHeadlines], |
| 342 | ); |
| 343 | |
| 344 | const onVoteMutate = useMemo( |
| 345 | () => createVoteOnMutate(updatePost), |
| 346 | [updatePost], |
| 347 | ); |
| 348 | const onBookmarkMutate = useMemo( |
| 349 | () => createBookmarkOnMutate(updatePost), |
| 350 | [updatePost], |
| 351 | ); |
| 352 | const { toggleBookmark } = useBookmarkPost({ onMutate: onBookmarkMutate }); |
| 353 | |
| 354 | const channelBySourceId = useMemo( |
| 355 | () => |
| 356 | new Map( |
| 357 | (channelData?.channelConfigurations ?? []).flatMap((channel) => { |
| 358 | const sourceId = channel.digest?.source?.id; |
| 359 | return sourceId ? [[sourceId, channel] as const] : []; |
| 360 | }), |
| 361 | ), |
| 362 | [channelData], |
| 363 | ); |
| 364 | |
| 365 | const highlights = useMemo( |
| 366 | () => data?.dailyHeadlines.edges.map((edge) => edge.node) ?? [], |
| 367 | [data], |
| 368 | ); |
| 369 |
nothing calls this directly
no test coverage detected