mirror of
https://github.com/urbit/shrub.git
synced 2024-12-24 03:14:30 +03:00
notifications: key notifications correctly
This commit is contained in:
parent
a9d7584d64
commit
c01a00bd6a
@ -1,6 +1,6 @@
|
||||
import bigInt, { BigInteger } from 'big-integer';
|
||||
import f from 'lodash/fp';
|
||||
import { Unreads, NotificationGraphConfig } from '@urbit/api';
|
||||
import { Unreads, NotificationGraphConfig, IndexedNotification } from '@urbit/api';
|
||||
|
||||
export function getLastSeen(
|
||||
unreads: Unreads,
|
||||
@ -44,3 +44,16 @@ export function isWatching(
|
||||
watch => watch.graph === graph && watch.index === index
|
||||
);
|
||||
}
|
||||
|
||||
export function getNotificationKey(time: BigInteger, notification: IndexedNotification): string {
|
||||
const base = time.toString();
|
||||
if('graph' in notification.index) {
|
||||
const { graph, index } = notification.index.graph;
|
||||
return `${base}-${graph}-${index}`;
|
||||
} else if('group' in notification.index) {
|
||||
const { group } = notification.index.group;
|
||||
return `${base}-${group}`;
|
||||
}
|
||||
return `${base}-unknown`;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import { useLazyScroll } from '~/logic/lib/useLazyScroll';
|
||||
import useHarkState from '~/logic/state/hark';
|
||||
import useInviteState from '~/logic/state/invite';
|
||||
import useMetadataState from '~/logic/state/metadata';
|
||||
import {getNotificationKey} from '~/logic/lib/hark';
|
||||
|
||||
type DatedTimebox = [BigInteger, Timebox];
|
||||
|
||||
@ -121,13 +122,14 @@ export default function Inbox(props: {
|
||||
);
|
||||
|
||||
return (
|
||||
<Col p="1" ref={scrollRef} position="relative" height="100%" overflowY="auto">
|
||||
<Col p="1" ref={scrollRef} position="relative" height="100%" overflowY="auto" overflowX="hidden">
|
||||
<Invites pendingJoin={props.pendingJoin} api={api} />
|
||||
{[...notificationsByDayMap.keys()].sort().reverse().map((day, index) => {
|
||||
const timeboxes = notificationsByDayMap.get(day)!;
|
||||
return timeboxes.length > 0 && (
|
||||
<DaySection
|
||||
key={day}
|
||||
time={day}
|
||||
label={day === 'latest' ? 'Today' : moment(day).calendar(null, calendar)}
|
||||
timeboxes={timeboxes}
|
||||
archive={Boolean(props.showArchive)}
|
||||
@ -166,6 +168,7 @@ function DaySection({
|
||||
label,
|
||||
archive,
|
||||
timeboxes,
|
||||
time,
|
||||
api,
|
||||
}) {
|
||||
const lent = timeboxes.map(([,nots]) => nots.length).reduce(f.add, 0);
|
||||
@ -178,7 +181,7 @@ function DaySection({
|
||||
{_.map(timeboxes.sort(sortTimeboxes), ([date, nots], i: number) =>
|
||||
_.map(nots.sort(sortIndexedNotification), (not, j: number) => (
|
||||
<Notification
|
||||
key={j}
|
||||
key={getNotificationKey(time, not)}
|
||||
api={api}
|
||||
notification={not}
|
||||
archived={archive}
|
||||
|
Loading…
Reference in New Issue
Block a user