mirror of
https://github.com/urbit/shrub.git
synced 2025-01-03 01:54:43 +03:00
grid: update mock
This commit is contained in:
parent
2064b976c2
commit
c1dff9e3f0
@ -1,4 +1,4 @@
|
||||
import { chadIsRunning, Treaty } from '@urbit/api/docket';
|
||||
import { chadIsRunning, Treaty } from '@urbit/api';
|
||||
import clipboardCopy from 'clipboard-copy';
|
||||
import React, { FC } from 'react';
|
||||
import cn from 'classnames';
|
||||
|
@ -36,7 +36,7 @@ const Empty = () => (
|
||||
|
||||
export const Notifications = () => {
|
||||
const select = useLeapStore((s) => s.select);
|
||||
const { unreads, reads, systemNotifications, hasAnyNotifications } = useNotifications();
|
||||
const { unreads, reads, hasAnyNotifications } = useNotifications();
|
||||
const markAllAsRead = () => {
|
||||
const { readAll } = useHarkStore.getState();
|
||||
readAll();
|
||||
@ -48,6 +48,8 @@ export const Notifications = () => {
|
||||
getMore();
|
||||
}, []);
|
||||
|
||||
console.log(unreads);
|
||||
|
||||
return (
|
||||
<div className="grid grid-rows-[auto,1fr] h-full p-4 md:p-8 overflow-hidden">
|
||||
<header className="space-x-2 mb-8">
|
||||
@ -67,12 +69,7 @@ export const Notifications = () => {
|
||||
{!hasAnyNotifications && <Empty />}
|
||||
{hasAnyNotifications && (
|
||||
<section className="text-gray-400 space-y-2 overflow-y-auto">
|
||||
{systemNotifications.map((n, index) =>
|
||||
renderNotification(n, (unreads.length + index).toString())
|
||||
)}
|
||||
{unreads.map((n, index) =>
|
||||
renderNotification(n, (systemNotifications.length + index).toString(), true)
|
||||
)}
|
||||
{unreads.map((n, index) => renderNotification(n, index.toString(), true))}
|
||||
{Array.from(reads)
|
||||
.map(([, nots]) => nots)
|
||||
.flat()
|
||||
|
@ -7,11 +7,8 @@ import { useNotifications } from '../state/notifications';
|
||||
|
||||
type NotificationsState = 'empty' | 'unread' | 'attention-needed';
|
||||
|
||||
function getNotificationsState(
|
||||
notifications: Notification[],
|
||||
systemNotifications: Notification[]
|
||||
): NotificationsState {
|
||||
if (systemNotifications.length > 0) {
|
||||
function getNotificationsState(notifications: Notification[]): NotificationsState {
|
||||
if (notifications.filter(({ bin }) => bin.place.desk === window.desk).length > 0) {
|
||||
return 'attention-needed';
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,10 @@ import {
|
||||
AllyUpdateIni,
|
||||
TreatyUpdateIni,
|
||||
docketInstall,
|
||||
ChargeUpdate
|
||||
} from '@urbit/api/docket';
|
||||
import { kilnRevive, kilnSuspend } from '@urbit/api/hood';
|
||||
ChargeUpdate,
|
||||
kilnRevive,
|
||||
kilnSuspend
|
||||
} from '@urbit/api';
|
||||
import api from './api';
|
||||
import { mockAllies, mockCharges, mockTreaties } from './mock-data';
|
||||
import { fakeRequest, useMockData } from './util';
|
||||
|
@ -6,7 +6,6 @@ import BigIntOrderedMap from '@urbit/api/lib/BigIntOrderedMap';
|
||||
import { unstable_batchedUpdates } from 'react-dom';
|
||||
import produce from 'immer';
|
||||
import { map } from 'lodash';
|
||||
import bigInt from 'big-integer';
|
||||
import api from './api';
|
||||
import { useMockData } from './util';
|
||||
import { mockNotifications } from './mock-data';
|
||||
@ -21,9 +20,7 @@ interface HarkStore {
|
||||
|
||||
export const useHarkStore = create<HarkStore>((set, get) => ({
|
||||
unreads: useMockData ? mockNotifications : [],
|
||||
reads: useMockData
|
||||
? new BigIntOrderedMap<Notification[]>().gas([[bigInt.zero, mockNotifications]])
|
||||
: new BigIntOrderedMap<Notification[]>(),
|
||||
reads: new BigIntOrderedMap<Notification[]>(),
|
||||
set: (f) => {
|
||||
const newState = produce(get(), f);
|
||||
set(newState);
|
||||
@ -53,6 +50,9 @@ export const useHarkStore = create<HarkStore>((set, get) => ({
|
||||
|
||||
function reduceHark(u: any) {
|
||||
const { set } = useHarkStore.getState();
|
||||
if (!u) {
|
||||
return;
|
||||
}
|
||||
if ('more' in u) {
|
||||
u.more.forEach((upd) => {
|
||||
reduceHark(upd);
|
||||
|
@ -8,7 +8,9 @@ import {
|
||||
Treaties,
|
||||
Treaty,
|
||||
Notification,
|
||||
HarkContent
|
||||
HarkContent,
|
||||
HarkBody,
|
||||
unixToDa
|
||||
} from '@urbit/api';
|
||||
import systemUrl from '../assets/system.png';
|
||||
|
||||
@ -163,37 +165,63 @@ export const mockAllies: Allies = [
|
||||
'~nalrys'
|
||||
].reduce((acc, val) => ({ ...acc, [val]: charter }), {});
|
||||
|
||||
function createDmNotification(content: string): HarkContent {
|
||||
function ship(s: string) {
|
||||
return { ship: s };
|
||||
}
|
||||
|
||||
function text(t: string) {
|
||||
return { text: t };
|
||||
}
|
||||
|
||||
function createDmNotification(...content: HarkContent[]): HarkBody {
|
||||
return {
|
||||
title: ' messaged you',
|
||||
author: '~hastuc-dibtux',
|
||||
time: Date.now() - 3_600,
|
||||
title: [ship('~hastuc-dibtux'), text(' messaged you')],
|
||||
time: unixToDa(Date.now() - 3_600).toString(),
|
||||
content,
|
||||
links: []
|
||||
link: '/'
|
||||
};
|
||||
}
|
||||
|
||||
function createBitcoinNotif(amount: string) {
|
||||
return {
|
||||
title: ` sent you ${amount}`,
|
||||
author: '~silnem',
|
||||
time: Date.now() - 3_600,
|
||||
content: '',
|
||||
links: []
|
||||
title: [ship('~silnem'), text(` sent you ${amount}`)],
|
||||
time: unixToDa(Date.now() - 3_600).toString(),
|
||||
content: [],
|
||||
binned: '/',
|
||||
link: '/'
|
||||
};
|
||||
}
|
||||
|
||||
function createGroupNotif(to: string): HarkContent {
|
||||
function createGroupNotif(to: string): HarkBody {
|
||||
return {
|
||||
title: ` invited you to ${to}`,
|
||||
author: '~ridlur-figbud',
|
||||
content: '',
|
||||
time: Date.now() - 3_600,
|
||||
links: []
|
||||
title: [ship('~ridlur-figbud'), text(` invited you to ${to}`)],
|
||||
content: [],
|
||||
time: unixToDa(Date.now() - 3_600).toString(),
|
||||
link: '/'
|
||||
};
|
||||
}
|
||||
|
||||
export function createMockNotification(desk: string, contents: HarkContent[]) {
|
||||
window.desk = window.desk || 'garden';
|
||||
|
||||
function createMockSysNotification(path: string) {
|
||||
return {
|
||||
bin: {
|
||||
place: {
|
||||
desk: window.desk,
|
||||
path
|
||||
},
|
||||
path: '/'
|
||||
},
|
||||
time: Date.now() - 3_600,
|
||||
body: []
|
||||
};
|
||||
}
|
||||
|
||||
const lag = createMockSysNotification('/lag');
|
||||
const blocked = createMockSysNotification('/blocked');
|
||||
const onboard = createMockSysNotification('/onboard');
|
||||
|
||||
export function createMockNotification(desk: string, body: HarkBody[]): Notification {
|
||||
return {
|
||||
bin: {
|
||||
place: {
|
||||
@ -203,14 +231,17 @@ export function createMockNotification(desk: string, contents: HarkContent[]) {
|
||||
path: '/'
|
||||
},
|
||||
time: Date.now() - 3_600,
|
||||
contents
|
||||
body
|
||||
};
|
||||
}
|
||||
|
||||
export const mockNotifications: Notification[] = [
|
||||
lag,
|
||||
blocked,
|
||||
onboard,
|
||||
createMockNotification('groups', [
|
||||
createDmNotification('ie the hook agent responsible for marking the notifications'),
|
||||
createDmNotification('~hastuc-dibtux sent a link')
|
||||
createDmNotification(text('ie the hook agent responsible for marking the notifications')),
|
||||
createDmNotification(ship('~hastuc-dibtux'), text(' sent a link'))
|
||||
]),
|
||||
createMockNotification('bitcoin-wallet', [createBitcoinNotif('0.025 BTC')]),
|
||||
createMockNotification('groups', [createGroupNotif('a Group: Tlon Corporation')])
|
||||
|
@ -13,6 +13,7 @@
|
||||
.note-grid-no-content {
|
||||
display: grid;
|
||||
width: 100%;
|
||||
padding: 1rem;
|
||||
grid-template-rows: 1.75rem 1.75rem;
|
||||
grid-template-columns: 3.5rem 1fr;
|
||||
grid-column-gap: 0.75rem;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import classNames from 'classnames';
|
||||
import React, { FunctionComponent } from 'react';
|
||||
import { darken, hsla, lighten, parseToHsla, readableColorIsBlack } from 'color2k';
|
||||
import { chadIsRunning } from '@urbit/api/docket';
|
||||
import { chadIsRunning } from '@urbit/api';
|
||||
import { TileMenu } from './TileMenu';
|
||||
import { Spinner } from '../components/Spinner';
|
||||
import { getAppHref } from '../state/util';
|
||||
|
@ -4,8 +4,7 @@ import { Poke } from '../lib/types';
|
||||
import {
|
||||
HarkBin,
|
||||
HarkBinId,
|
||||
HarkPlace,
|
||||
NotifIndex
|
||||
HarkPlace
|
||||
} from './types';
|
||||
import { decToUd } from '../lib';
|
||||
|
||||
@ -34,12 +33,12 @@ export { groupHookAction as harkGroupHookAction };
|
||||
export const actOnNotification = (
|
||||
frond: string,
|
||||
intTime: BigInteger,
|
||||
index: NotifIndex
|
||||
bin: HarkBin
|
||||
): Poke<unknown> =>
|
||||
harkAction({
|
||||
[frond]: {
|
||||
time: decToUd(intTime.toString()),
|
||||
index
|
||||
bin
|
||||
}
|
||||
});
|
||||
|
||||
@ -69,13 +68,8 @@ export const archive = (bin: HarkBin, time?: BigInteger): Poke<unknown> =>
|
||||
export const readNote = (bin: HarkBin): Poke<unknown> =>
|
||||
harkAction({ 'read-note': bin });
|
||||
|
||||
export const readIndex = (index: NotifIndex): Poke<unknown> =>
|
||||
harkAction({
|
||||
'read-index': index
|
||||
});
|
||||
|
||||
export const unread = (time: BigInteger, index: NotifIndex): Poke<unknown> =>
|
||||
actOnNotification('unread-note', time, index);
|
||||
export const unread = (time: BigInteger, bin: HarkBin): Poke<unknown> =>
|
||||
actOnNotification('unread-note', time, bin);
|
||||
|
||||
export const markCountAsRead = (place: HarkPlace): Poke<unknown> =>
|
||||
harkAction({
|
||||
@ -93,14 +87,6 @@ export const markEachAsRead = (
|
||||
}
|
||||
});
|
||||
|
||||
export const dec = (index: NotifIndex, ref: string): Poke<unknown> =>
|
||||
harkAction({
|
||||
dec: {
|
||||
index,
|
||||
ref
|
||||
}
|
||||
});
|
||||
|
||||
export const seen = () => harkAction({ seen: null });
|
||||
|
||||
export const readAll = harkAction({ 'read-all': null });
|
||||
|
Loading…
Reference in New Issue
Block a user