collections: clear toplevel unreads on visit

Fixes urbit/landscape#995
This commit is contained in:
Liam Fitzgerald 2021-06-25 08:38:29 +10:00
parent ed4fa6a7ae
commit 6df2d349d3
No known key found for this signature in database
GPG Key ID: D390E12C61D1CFFB

View File

@ -1,6 +1,6 @@
import { Col, Row, Text } from '@tlon/indigo-react'; import { Col, Row, Text } from '@tlon/indigo-react';
import { Association, Graph, GraphNode } from '@urbit/api'; import { Association, Graph, GraphNode, markEachAsRead } from '@urbit/api';
import React, { useCallback, useState, useMemo } from 'react'; import React, { useCallback, useState, useMemo, useEffect } from 'react';
import _ from 'lodash'; import _ from 'lodash';
import { useResize } from '~/logic/lib/useResize'; import { useResize } from '~/logic/lib/useResize';
import { LinkBlockItem } from './LinkBlockItem'; import { LinkBlockItem } from './LinkBlockItem';
@ -9,6 +9,8 @@ import useLocalState from '~/logic/state/local';
import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap'; import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap';
import bigInt from 'big-integer'; import bigInt from 'big-integer';
import VirtualScroller from '~/views/components/VirtualScroller'; import VirtualScroller from '~/views/components/VirtualScroller';
import airlock from '~/logic/api';
import useHarkState from '~/logic/state/hark';
export interface LinkBlocksProps { export interface LinkBlocksProps {
graph: Graph; 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 orm = useMemo(() => {
const nodes = [null, ...Array.from(props.graph)]; const nodes = [null, ...Array.from(props.graph)];