Merge remote-tracking branch 'origin/next/groups' into lf/fix-sidebar-priority

This commit is contained in:
Liam Fitzgerald 2021-11-04 11:05:56 -05:00
commit 678e92a331
6 changed files with 48 additions and 7 deletions

View File

@ -15,11 +15,12 @@ export function useResize<T extends HTMLElement>(
callback(entry, observer);
}
}
let el = ref.current;
const resizeObs = new ResizeObserver(observer);
resizeObs.observe(ref.current, { box: 'border-box' });
resizeObs.observe(el, { box: 'border-box' });
return () => {
resizeObs.unobserve(ref.current);
resizeObs.unobserve(el);
};
}, [callback]);

View File

@ -9,7 +9,8 @@ import {
harkBinToId,
decToUd,
unixToDa,
opened
opened,
markEachAsRead
} from '@urbit/api';
import { Poke } from '@urbit/http-api';
import { patp2dec } from 'urbit-ob';
@ -25,6 +26,7 @@ import {
reduceStateN
} from './base';
import { reduce, reduceGraph, reduceGroup } from '../reducers/hark-update';
import useMetadataState from './metadata';
export const HARK_FETCH_MORE_COUNT = 3;
@ -43,6 +45,8 @@ export interface HarkState {
unreads: Unreads;
archiveNote: (bin: HarkBin, lid: HarkLid) => Promise<void>;
readCount: (path: string) => Promise<void>;
readGraph: (graph: string) => Promise<void>;
readGroup: (group: string) => Promise<void>;
}
const useHarkState = createState<HarkState>(
@ -54,6 +58,38 @@ const useHarkState = createState<HarkState>(
poke: async (poke: Poke<any>) => {
await pokeOptimisticallyN(useHarkState, poke, [reduce]);
},
readGraph: async (graph: string) => {
const prefix = `/graph/${graph.slice(6)}`;
let counts = [] as string[];
let eaches = [] as [string, string][];
Object.entries(get().unreads).forEach(([path, unreads]) => {
if (path.startsWith(prefix)) {
if(unreads.count > 0) {
counts.push(path);
}
unreads.each.forEach(unread => {
eaches.push([path, unread]);
});
}
});
get().set(draft => {
counts.forEach(path => {
draft.unreads[path].count = 0;
});
eaches.forEach(([path, each]) => {
draft.unreads[path].each = [];
});
});
await Promise.all([
...counts.map(path => markCountAsRead({ desk: window.desk, path })),
...eaches.map(([path, each]) => markEachAsRead({ desk: window.desk, path }, each))
].map(pok => api.poke(pok)));
},
readGroup: async (group: string) => {
const graphs =
_.pickBy(useMetadataState.getState().associations.graph, a => a.group === group);
await Promise.all(Object.keys(graphs).map(get().readGraph));
},
readCount: async (path) => {
const poke = markCountAsRead({ desk: (window as any).desk, path });
await pokeOptimisticallyN(useHarkState, poke, [reduce]);

View File

@ -61,6 +61,9 @@ export function Note(props: NoteProps & RouteComponentProps) {
const noteId = bigInt(index[1]);
useEffect(() => {
airlock.poke(markEachAsRead(toHarkPlace(association.resource), `/${index[1]}`));
// Unread may be malformed, dismiss anyway
// TODO: remove when %read-graph is implemented
airlock.poke(markEachAsRead(toHarkPlace(association.resource), `/1`));
}, [association, props.note]);
const adminLinks: JSX.Element[] = [];

View File

@ -7,6 +7,7 @@ import useContactState from '~/logic/state/contact';
import useGroupState from '~/logic/state/group';
import airlock from '~/logic/api';
import { NotebookPosts } from './NotebookPosts';
import useHarkState from '~/logic/state/hark';
interface NotebookProps {
ship: string;
@ -35,7 +36,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps): ReactEleme
const showNickname = useShowNickname(contact);
const readBook = useCallback(() => {
airlock.poke(readGraph(association.resource));
useHarkState.getState().readGraph(association.resource, 'graph-validator-publish');
}, [association.resource]);
if (!group) {

View File

@ -43,7 +43,7 @@ export function GroupsPane(props: GroupsPaneProps) {
useShortcut('readGroup', useCallback(() => {
if(groupPath) {
airlock.poke(readGroup(groupPath));
useHarkState.getState().readGroup(groupPath);
}
}, [groupPath]));

View File

@ -486,7 +486,7 @@
update-core
?- mode.kind
%count (hark %unread-count place %.y 1)
%each (hark %unread-each place /(rsh 4 (scot %ui (rear index.post))))
%each (hark %unread-each place /(rsh 4 (scot %ui (rear self-idx))))
%none update-core
==
==
@ -497,7 +497,7 @@
update-core
?- mode.kind
%count (hark %unread-count place %.n 1)
%each (hark %read-each place /(rsh 4 (scot %ui (rear index.post))))
%each (hark %read-each place /(rsh 4 (scot %ui (rear self-idx))))
%none update-core
==
==