collections: clear toplevel unreads on visit
Fixes urbit/landscape#995
import { Col, Row, Text } from '@tlon/indigo-react';
-import { Association, Graph, GraphNode } from '@urbit/api';
-import React, { useCallback, useState, useMemo } from 'react';
+import { Association, Graph, GraphNode, markEachAsRead } from '@urbit/api';
+import React, { useCallback, useState, useMemo, useEffect } from 'react';
import _ from 'lodash';
import { useResize } from '~/logic/lib/useResize';
import { LinkBlockItem } from './LinkBlockItem';
@@ -9,6 +9,8 @@ import useLocalState from '~/logic/state/local';
import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap';
import bigInt from 'big-integer';
import VirtualScroller from '~/views/components/VirtualScroller';
+import airlock from '~/logic/api';
+import useHarkState from '~/logic/state/hark';
export interface LinkBlocksProps {
graph: Graph;
@@ -40,6 +42,14 @@ export function LinkBlocks(props: LinkBlocksProps) {
)
);
+ useEffect(() => {
+ const { unreads } = useHarkState
+ .getState().unreads.graph?.[association.resource]?.['/'];
+ Array.from((unreads as Set<string>)).forEach((u) => {
+ airlock.poke(markEachAsRead(association.resource, '/', u));
+ });
+}, [association.resource]);
+
const orm = useMemo(() => {
const nodes = [null, ...Array.from(props.graph)];
