From 6df2d349d33feeb74d255d400f9861aad7edf7c0 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Fri, 25 Jun 2021 08:38:29 +1000 Subject: [PATCH] collections: clear toplevel unreads on visit Fixes urbit/landscape#995 --- .../src/views/apps/links/components/LinkBlocks.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/interface/src/views/apps/links/components/LinkBlocks.tsx b/pkg/interface/src/views/apps/links/components/LinkBlocks.tsx index 106fd7a8c2..5c22904245 100644 --- a/pkg/interface/src/views/apps/links/components/LinkBlocks.tsx +++ b/pkg/interface/src/views/apps/links/components/LinkBlocks.tsx @@ -1,6 +1,6 @@ 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)).forEach((u) => { + airlock.poke(markEachAsRead(association.resource, '/', u)); + }); +}, [association.resource]); + const orm = useMemo(() => { const nodes = [null, ...Array.from(props.graph)];