From d593561b0fb5fedf5ef799a92a1bb9107b527257 Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Mon, 20 Sep 2021 14:34:55 +1000 Subject: [PATCH] interface: fix misc bugs --- pkg/interface/public/index.html | 4 +- .../src/logic/reducers/hark-update.ts | 3 +- pkg/interface/src/logic/state/hark.ts | 6 +- .../views/apps/launch/components/Invite.tsx | 62 +++++++++---------- .../src/views/components/StatusBar.tsx | 25 +------- .../src/views/components/leap/Omnibox.tsx | 2 +- .../views/components/leap/OmniboxResult.tsx | 51 --------------- .../views/landscape/components/Content.tsx | 2 +- .../components/Sidebar/SidebarItem.tsx | 3 +- 9 files changed, 43 insertions(+), 115 deletions(-) diff --git a/pkg/interface/public/index.html b/pkg/interface/public/index.html index e955f8f527..f55832cbe1 100644 --- a/pkg/interface/public/index.html +++ b/pkg/interface/public/index.html @@ -18,11 +18,11 @@ "display": "standalone", "background_color": "%23FFFFFF", "theme_color": "%23000000"}' /> + +
- - diff --git a/pkg/interface/src/logic/reducers/hark-update.ts b/pkg/interface/src/logic/reducers/hark-update.ts index 170c34f608..1aa7c8608d 100644 --- a/pkg/interface/src/logic/reducers/hark-update.ts +++ b/pkg/interface/src/logic/reducers/hark-update.ts @@ -107,7 +107,7 @@ function updateNotificationStats(state: HarkState, place: HarkPlace, f: (s: Hark } function seenIndex(json: any, state: HarkState): HarkState { - const data = _.get(json, 'seen-index'); + const data = _.get(json, 'saw-place'); if(data) { updateNotificationStats(state, data, s => ({ last: Date.now() })); } @@ -154,6 +154,7 @@ function unreadEach(json: any, state: HarkState): HarkState { function allStats(json: any, state: HarkState): HarkState { if('all-stats' in json) { const data = json['all-stats']; + console.log(data); data.forEach(({ place, stats }) => { state.unreads[place.path] = stats; }); diff --git a/pkg/interface/src/logic/state/hark.ts b/pkg/interface/src/logic/state/hark.ts index 7e571cbbf1..2321f9efff 100644 --- a/pkg/interface/src/logic/state/hark.ts +++ b/pkg/interface/src/logic/state/hark.ts @@ -4,7 +4,6 @@ import { markCountAsRead, Notification, NotificationGraphConfig, - readNote, Unreads } from '@urbit/api'; import { Poke } from '@urbit/http-api'; @@ -132,9 +131,8 @@ export function useHarkDm(ship: string) { return useHarkState( useCallback( (s) => { - return s.unreads[`/graph/~${window.ship}/dm-inbox`]?.[ - `/${patp2dec(ship)}` - ] || emptyStats(); + const key = `/graph/~${window.ship}/dm-inbox/${patp2dec(ship)}`; + return s.unreads[key] || emptyStats(); }, [ship] ) diff --git a/pkg/interface/src/views/apps/launch/components/Invite.tsx b/pkg/interface/src/views/apps/launch/components/Invite.tsx index 0b1742d8dd..7cb4165fcb 100644 --- a/pkg/interface/src/views/apps/launch/components/Invite.tsx +++ b/pkg/interface/src/views/apps/launch/components/Invite.tsx @@ -1,19 +1,18 @@ -import React, { useState, useEffect, useCallback } from "react"; -import { useHistory, useParams } from "react-router-dom"; +import React, { useState, useEffect, useCallback } from 'react'; +import { useHistory, useParams } from 'react-router-dom'; import { Box, Col, Row, Text, - Button, Action, - LoadingSpinner, -} from "@tlon/indigo-react"; -import * as Dialog from "@radix-ui/react-dialog"; -import { PropFunc } from "~/types"; -import { useRunIO } from "~/logic/lib/useRunIO"; -import useMetadataState from "~/logic/state/metadata"; -import { GroupSummary } from "~/views/landscape/components/GroupSummary"; + LoadingSpinner +} from '@tlon/indigo-react'; +import * as Dialog from '@radix-ui/react-dialog'; +import { PropFunc } from '~/types'; +import { useRunIO } from '~/logic/lib/useRunIO'; +import useMetadataState from '~/logic/state/metadata'; +import { GroupSummary } from '~/views/landscape/components/GroupSummary'; import { accept, decline, @@ -22,13 +21,13 @@ import { join, Metadata, MetadataUpdatePreview, - resourceFromPath, -} from "@urbit/api"; -import useInviteState from "~/logic/state/invite"; -import useGroupState from "~/logic/state/group"; -import useGraphState from "~/logic/state/graph"; -import { useWaitForProps } from "~/logic/lib/useWaitForProps"; -import airlock from "~/logic/api"; + resourceFromPath +} from '@urbit/api'; +import useInviteState from '~/logic/state/invite'; +import useGroupState from '~/logic/state/group'; +import useGraphState from '~/logic/state/graph'; +import { useWaitForProps } from '~/logic/lib/useWaitForProps'; +import airlock from '~/logic/api'; function InviteDialog({ children, ...rest }: PropFunc) { return ( @@ -84,7 +83,7 @@ function inviteUrl( return `/~landscape${resource}`; } - if (metadata.config?.graph === "chat") { + if (metadata.config?.graph === 'chat') { return `/~landscape/messages/resource/${metadata.config.graph}${resource}`; } else { return `/~landscape/home/resource/${metadata.config?.graph}${resource}`; @@ -94,9 +93,9 @@ function inviteUrl( function useInviteAccept(resource: string, app?: string, uid?: string) { const { ship, name } = resourceFromPath(resource); const history = useHistory(); - const associations = useMetadataState((s) => s.associations); - const groups = useGroupState((s) => s.groups); - const graphKeys = useGraphState((s) => s.graphKeys); + const associations = useMetadataState(s => s.associations); + const groups = useGroupState(s => s.groups); + const graphKeys = useGraphState(s => s.graphKeys); const waiter = useWaitForProps({ associations, graphKeys, groups }); return useRunIO( @@ -110,7 +109,6 @@ function useInviteAccept(resource: string, app?: string, uid?: string) { } await airlock.poke(join(ship, name)); - await airlock.poke(accept(app, uid)); await waiter((p) => { return ( (resource in p.groups && @@ -119,10 +117,12 @@ function useInviteAccept(resource: string, app?: string, uid?: string) { resource in (p.associations?.groups ?? {}) ); }); + airlock.poke(accept(app, uid)); return true; }, (success: boolean) => { if (!success) { + history.push('/'); return; } const redir = inviteUrl( @@ -147,11 +147,11 @@ export function Invite() { uid: string; }>(); - const invite = useInviteState((s) => s.invites?.[app]?.[uid]); + const invite = useInviteState(s => s.invites?.[app]?.[uid]); return ( - {!!invite ? ( + {invite ? ( <> {renderInviteContent(app, uid, invite)} @@ -166,7 +166,7 @@ export function Invite() { function InviteActions({ app, uid, - invite, + invite }: { app: string; uid: string; @@ -201,9 +201,9 @@ function InviteActions({ function GroupInvite({ uid, invite }: { uid: string; invite: IInvite }) { const { - resource: { ship, name }, + resource: { ship, name } } = invite; - const { associations, getPreview } = useMetadataState(); + const { getPreview } = useMetadataState(); const [preview, setPreview] = useState(null); useEffect(() => { (async () => { @@ -218,8 +218,8 @@ function GroupInvite({ uid, invite }: { uid: string; invite: IInvite }) { return preview ? ( ) : ( @@ -232,9 +232,9 @@ function GraphInvite({ uid, invite }: { uid: string; invite: IInvite }) { function renderInviteContent(app: string, uid: string, invite: IInvite) { switch (app) { - case "groups": + case 'groups': return ; - case "graph": + case 'graph': return ; default: return null; diff --git a/pkg/interface/src/views/components/StatusBar.tsx b/pkg/interface/src/views/components/StatusBar.tsx index 2a8e316121..381bba831f 100644 --- a/pkg/interface/src/views/components/StatusBar.tsx +++ b/pkg/interface/src/views/components/StatusBar.tsx @@ -8,13 +8,10 @@ import { Text } from '@tlon/indigo-react'; import React, { useRef } from 'react'; -import { Link, useHistory } from 'react-router-dom'; +import { Link } from 'react-router-dom'; import { Sigil } from '~/logic/lib/sigil'; import { uxToHex } from '~/logic/lib/util'; import useContactState from '~/logic/state/contact'; -import useHarkState from '~/logic/state/hark'; -import useLaunchState from '~/logic/state/launch'; -import useInviteState from '~/logic/state/invite'; import useLocalState, { selectLocalState } from '~/logic/state/local'; import useSettingsState, { selectCalmState } from '~/logic/state/settings'; import { Dropdown } from './Dropdown'; @@ -22,21 +19,13 @@ import { ProfileStatus } from './ProfileStatus'; import ReconnectButton from './ReconnectButton'; import { StatusBarItem } from './StatusBarItem'; import { useTutorialModal } from './useTutorialModal'; -import {StatusBarJoins} from './StatusBarJoins'; +import { StatusBarJoins } from './StatusBarJoins'; const localSel = selectLocalState(['toggleOmnibox']); const StatusBar = (props) => { const { ship } = props; - const history = useHistory(); - const runtimeLag = useLaunchState(state => state.runtimeLag); const ourContact = useContactState(state => state.contacts[`~${ship}`]); - const notificationsCount = useHarkState(state => state.notificationsCount); - const doNotDisturb = useHarkState(state => state.doNotDisturb); - const inviteState = useInviteState(state => state.invites); - const invites = [].concat( - ...Object.values(inviteState).map(obj => Object.values(obj)) - ); const metaKey = window.navigator.platform.includes('Mac') ? '⌘' : 'Ctrl+'; const { toggleOmnibox } = useLocalState(localSel); const { hideAvatars } = useSettingsState(selectCalmState); @@ -87,16 +76,6 @@ const StatusBar = (props) => { toggleOmnibox()}> - {!doNotDisturb && runtimeLag && ( - - - - )} - {!doNotDisturb && (notificationsCount > 0 || invites.length > 0) && ( - - - - )} Leap diff --git a/pkg/interface/src/views/components/leap/Omnibox.tsx b/pkg/interface/src/views/components/leap/Omnibox.tsx index 363abcf48b..3b00d04825 100644 --- a/pkg/interface/src/views/components/leap/Omnibox.tsx +++ b/pkg/interface/src/views/components/leap/Omnibox.tsx @@ -119,7 +119,7 @@ export function Omnibox(props: OmniboxProps): ReactElement { if (category === 'other') { return [ 'other', - index.get('other').filter(({ app }) => app !== 'tutorial') + index.get('other').filter(({ app }) => app !== 'tutorial' && app !== 'inbox') ]; } return [category, []]; diff --git a/pkg/interface/src/views/components/leap/OmniboxResult.tsx b/pkg/interface/src/views/components/leap/OmniboxResult.tsx index 9b4095cf15..5a4f3eac43 100644 --- a/pkg/interface/src/views/components/leap/OmniboxResult.tsx +++ b/pkg/interface/src/views/components/leap/OmniboxResult.tsx @@ -7,8 +7,6 @@ import { cite, uxToHex } from '~/logic/lib/util'; import { IconRef } from '~/types/util'; import withState from '~/logic/lib/withState'; import useContactState from '~/logic/state/contact'; -import useHarkState from '~/logic/state/hark'; -import useLaunchState from '~/logic/state/launch'; import useInviteState from '~/logic/state/invite'; function OmniboxResultChord(props: { @@ -34,8 +32,6 @@ interface OmniboxResultProps { invites: Invites; link: string; navigate: () => void; - notificationsCount: number; - runtimeLag: any; selected: string; setSelection: () => void; subtext: string; @@ -80,21 +76,11 @@ export class OmniboxResult extends Component Object.values(obj)) - ); let graphic: ReactElement =
; if ( @@ -120,35 +106,6 @@ export class OmniboxResult extends Component ); - } else if (icon === 'inbox') { - graphic = ( - - - {lag && ( - - )} - {(notificationsCount > 0 || inviteCount.length > 0) && ( - - )} - - ); } else if (icon === 'logout') { graphic = ( { if(Object.keys(associations).length > 0 && query.has('grid-note')) { history.push(getNotificationRedirect(query.get('grid-note'))); } - }, [location.search]); + }, [location.search, associations]); useShortcut('navForward', useCallback((e) => { e.preventDefault(); diff --git a/pkg/interface/src/views/landscape/components/Sidebar/SidebarItem.tsx b/pkg/interface/src/views/landscape/components/Sidebar/SidebarItem.tsx index 9a2b87c3c0..87675e754d 100644 --- a/pkg/interface/src/views/landscape/components/Sidebar/SidebarItem.tsx +++ b/pkg/interface/src/views/landscape/components/Sidebar/SidebarItem.tsx @@ -128,7 +128,8 @@ export const SidebarDmItem = React.memo((props: { !hideNicknames && contact?.nickname ? contact?.nickname : cite(ship) ?? ship; - const { unreads } = useHarkDm(ship) || { unreads: 0 }; + const { count, each } = useHarkDm(ship); + const unreads = count + each.length; const img = contact?.avatar && !hideAvatars ? (