From 678278508370e529b11ee461893644a53dd1d471 Mon Sep 17 00:00:00 2001 From: Matilde Park Date: Wed, 11 Nov 2020 15:42:06 -0500 Subject: [PATCH] landscape: surface invites in notifications --- pkg/interface/src/views/App.js | 3 +- pkg/interface/src/views/apps/launch/app.js | 6 +- .../views/apps/launch/components/Groups.tsx | 58 +------------------ .../src/views/apps/notifications/inbox.tsx | 50 +++++++++++++++- .../src/views/components/StatusBar.js | 5 +- .../src/views/components/leap/Omnibox.js | 4 +- .../views/components/leap/OmniboxResult.js | 25 +++++--- 7 files changed, 76 insertions(+), 75 deletions(-) diff --git a/pkg/interface/src/views/App.js b/pkg/interface/src/views/App.js index c857e1b188..f3315809ce 100644 --- a/pkg/interface/src/views/App.js +++ b/pkg/interface/src/views/App.js @@ -155,7 +155,8 @@ class App extends React.Component { associations={state.associations} apps={state.launch} api={this.api} - dark={state.dark} + notifications={state.notificationsCount} + invites={state.invites} groups={state.groups} show={state.omniboxShown} /> diff --git a/pkg/interface/src/views/apps/launch/app.js b/pkg/interface/src/views/apps/launch/app.js index 895f64a5be..aa6baba226 100644 --- a/pkg/interface/src/views/apps/launch/app.js +++ b/pkg/interface/src/views/apps/launch/app.js @@ -2,12 +2,10 @@ import React from 'react'; import Helmet from 'react-helmet'; import styled from 'styled-components'; -import { Box, Row, Icon, Text, Center } from '@tlon/indigo-react'; -import { uxToHex, adjustHex } from '~/logic/lib/util'; +import { Box, Row, Icon, Text } from '@tlon/indigo-react'; import './css/custom.css'; -import { Sigil } from '~/logic/lib/sigil'; import Tiles from './components/tiles'; import Tile from './components/tiles/tile'; import Welcome from './components/welcome'; @@ -65,7 +63,7 @@ export default class LaunchApp extends React.Component { weather={props.weather} /> - + alphabeticalOrder(a.metadata.title, b.metadata.title); export default function Groups(props: GroupsProps & Parameters[0]) { - const { associations, invites, api, ...boxProps } = props; - - const incomingGroups = Object.values(invites?.['contacts'] || {}); - const getKeyByValue = (object, value) => { - return Object.keys(object).find(key => object[key] === value); - } + const { associations, ...boxProps } = props; const groups = Object.values(associations?.contacts || {}) .filter(e => e['group-path'] in props.groups) .sort(sortGroupsAlph); - const acceptInvite = (invite) => { - const resource = { - ship: `~${invite.resource.ship}`, - name: invite.resource.name - }; - return api.contacts.join(resource).then(() => { - api.invite.accept('contacts', getKeyByValue(invites['contacts'], invite)); - }); - }; - return ( <> - {incomingGroups.map((invite) => ( - - You have been invited to: - - {`~${invite.resource.ship}/${invite.resource.name}`} - - - acceptInvite(invite)} - color='blue' - mr='2' - cursor='pointer'> - Accept - - - api.invite.decline( - 'contacts', - getKeyByValue(invites['contacts'], invite) - ) - } - cursor='pointer'> - Reject - - - - ))} {groups.map((group) => ( {group.metadata.title} diff --git a/pkg/interface/src/views/apps/notifications/inbox.tsx b/pkg/interface/src/views/apps/notifications/inbox.tsx index f1e25094f9..f41ebeb37a 100644 --- a/pkg/interface/src/views/apps/notifications/inbox.tsx +++ b/pkg/interface/src/views/apps/notifications/inbox.tsx @@ -9,6 +9,7 @@ import { BigInteger } from "big-integer"; import GlobalApi from "~/logic/api/global"; import { Notification } from "./notification"; import { Associations } from "~/types"; +import { cite } from '~/logic/lib/util'; type DatedTimebox = [BigInteger, Timebox]; @@ -39,8 +40,9 @@ export default function Inbox(props: { associations: Associations; contacts: Rolodex; filter: string[]; + invites: any; }) { - const { api, associations } = props; + const { api, associations, invites } = props; useEffect(() => { let seen = false; setTimeout(() => { @@ -67,8 +69,54 @@ export default function Inbox(props: { f.values )(notifications); + const incomingGroups = Object.values(invites?.['contacts'] || {}); + + const getKeyByValue = (object, value) => { + return Object.keys(object).find(key => object[key] === value); + }; + +const acceptInvite = (invite) => { + const resource = { + ship: `~${invite.resource.ship}`, + name: invite.resource.name + }; + return api.contacts.join(resource).then(() => { + api.invite.accept('contacts', getKeyByValue(invites['contacts'], invite)); + }); + }; + return ( + {incomingGroups.map((invite) => ( + + {cite(invite.resource.ship)} invited you to {invite.resource.name} + + acceptInvite(invite)} + color='blue' + mr='2' + cursor='pointer'> + Accept + + + api.invite.decline( + 'contacts', + getKeyByValue(invites['contacts'], invite) + ) + } + cursor='pointer'> + Reject + + + + ))} {newNotifications && ( { - + const invites = Object.keys(props.invites?.['contacts'] || {}); const metaKey = (window.navigator.platform.includes('Mac')) ? '⌘' : 'Ctrl+'; return ( @@ -26,7 +25,7 @@ const StatusBar = (props) => { props.api.local.setOmnibox()}> - { !props.doNotDisturb && props.notificationsCount > 0 && + { !props.doNotDisturb && (props.notificationsCount > 0 || invites.length > 0) && ( diff --git a/pkg/interface/src/views/components/leap/Omnibox.js b/pkg/interface/src/views/components/leap/Omnibox.js index 23199ff645..82bd5eeb36 100644 --- a/pkg/interface/src/views/components/leap/Omnibox.js +++ b/pkg/interface/src/views/components/leap/Omnibox.js @@ -241,7 +241,9 @@ export class Omnibox extends Component { link={result.link} navigate={() => this.navigate(result.app, result.link)} selected={selected} - dark={props.dark} /> + invites={props.invites} + notifications={props.notifications} + /> ))} ); diff --git a/pkg/interface/src/views/components/leap/OmniboxResult.js b/pkg/interface/src/views/components/leap/OmniboxResult.js index 5c8e419f6a..77dc938720 100644 --- a/pkg/interface/src/views/components/leap/OmniboxResult.js +++ b/pkg/interface/src/views/components/leap/OmniboxResult.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Row, Icon, Text } from '@tlon/indigo-react'; +import { Box, Row, Icon, Text } from '@tlon/indigo-react'; import defaultApps from '~/logic/lib/default-apps'; import Sigil from '~/logic/lib/sigil'; @@ -25,21 +25,30 @@ export class OmniboxResult extends Component { } } - getIcon(icon, dark, selected, link) { + getIcon(icon, selected, link, invites, notifications) { const iconFill = (this.state.hovered || (selected === link)) ? 'white' : 'black'; const sigilFill = (this.state.hovered || (selected === link)) ? '#3a8ff7' : '#ffffff'; + const bulletFill = (this.state.hovered || (selected === link)) ? 'white' : 'blue'; + + const inviteCount = Object.keys(invites?.['contacts'] || {}); let graphic =
; - if (defaultApps.includes(icon.toLowerCase()) || icon.toLowerCase() === 'links' || icon === 'inbox') { - icon = (icon === 'inbox') ? 'Inbox' : icon; + if (defaultApps.includes(icon.toLowerCase()) || icon.toLowerCase() === 'links') { icon = (icon === 'Link') ? 'Links' : icon; graphic = ; + } else if (icon === 'inbox') { + graphic = + + {(notifications > 0 || inviteCount.length > 0) && ( + + )} + ; } else if (icon === 'logout') { - graphic = ; + graphic = ; } else if (icon === 'profile') { graphic = ; } else if (icon === 'home') { - graphic = ; + graphic = ; } else if (icon === 'notifications') { graphic = ; } else { @@ -54,9 +63,9 @@ export class OmniboxResult extends Component { } render() { - const { icon, text, subtext, link, navigate, selected, dark } = this.props; + const { icon, text, subtext, link, navigate, selected, invites, notifications } = this.props; - const graphic = this.getIcon(icon, dark, selected, link); + const graphic = this.getIcon(icon, selected, link, invites, notifications); return (