From 1c421963d1de7ad9102070f5dc3a54773964b198 Mon Sep 17 00:00:00 2001 From: Hunter Miller Date: Mon, 23 Aug 2021 14:18:07 -0500 Subject: [PATCH] dialogs: updates to design and mobile tweaks --- pkg/grid/src/components/Button.tsx | 10 +++--- pkg/grid/src/nav/Nav.tsx | 4 +-- pkg/grid/src/nav/search/AppInfo.tsx | 49 +++++++++++++++++++++-------- pkg/grid/src/pages/Grid.tsx | 6 ++-- pkg/grid/src/state/docket.ts | 37 +++++++++++----------- pkg/grid/src/state/mock-data.ts | 9 +++--- pkg/grid/src/tiles/RemoveApp.tsx | 24 ++++++++------ pkg/grid/src/tiles/SuspendApp.tsx | 20 +++++++----- pkg/grid/src/tiles/Tile.tsx | 2 +- 9 files changed, 96 insertions(+), 65 deletions(-) diff --git a/pkg/grid/src/components/Button.tsx b/pkg/grid/src/components/Button.tsx index e8f6c88ebf..df1d00c38f 100644 --- a/pkg/grid/src/components/Button.tsx +++ b/pkg/grid/src/components/Button.tsx @@ -2,7 +2,7 @@ import React from 'react'; import type * as Polymorphic from '@radix-ui/react-polymorphic'; import classNames from 'classnames'; -type ButtonVariant = 'primary' | 'secondary' | 'destructive'; +type ButtonVariant = 'primary' | 'secondary' | 'destructive' | 'alt-primary' | 'alt-secondary'; type PolymorphicButton = Polymorphic.ForwardRefComponent< 'button', @@ -12,9 +12,11 @@ type PolymorphicButton = Polymorphic.ForwardRefComponent< >; const variants: Record = { - primary: 'text-white bg-blue-400', - secondary: 'text-blue-400 bg-blue-100', - destructive: 'text-white bg-red-400' + primary: 'text-white bg-black', + secondary: 'text-black bg-gray-100', + destructive: 'text-white bg-red-400', + 'alt-primary': 'text-white bg-blue-400', + 'alt-secondary': 'text-blue-400 bg-blue-100' }; export const Button = React.forwardRef( diff --git a/pkg/grid/src/nav/Nav.tsx b/pkg/grid/src/nav/Nav.tsx index 5a15d5d82b..798c433724 100644 --- a/pkg/grid/src/nav/Nav.tsx +++ b/pkg/grid/src/nav/Nav.tsx @@ -163,13 +163,13 @@ export const Nav: FunctionComponent = ({ menu }) => { -
+
{
{installed && ( - + Open App )} {!installed && ( - - {installing ? ( - <> - - Installing... - - ) : ( - 'Get App' - )} - + + + {installing ? ( + <> + + Installing... + + ) : ( + 'Get App' + )} + + +

Install “{treaty.title}”

+

+ This application will be able to view and interact with the contents of your + Urbit. Only install if you trust the developer. +

+
+ + Cancel + + + Get “{treaty.title}” + +
+
+
)} - + Copy App Link
diff --git a/pkg/grid/src/pages/Grid.tsx b/pkg/grid/src/pages/Grid.tsx index 4d33cfd1dc..3e56b20592 100644 --- a/pkg/grid/src/pages/Grid.tsx +++ b/pkg/grid/src/pages/Grid.tsx @@ -26,14 +26,14 @@ export const Grid: FunctionComponent = ({ match }) => { return (
-
+
-
+
{!chargesLoaded && Loading...} {chargesLoaded && ( -
+
{charges && map(omit(charges, 'grid'), (charge, desk) => ( diff --git a/pkg/grid/src/state/docket.ts b/pkg/grid/src/state/docket.ts index 9940c77587..f60ff5faf5 100644 --- a/pkg/grid/src/state/docket.ts +++ b/pkg/grid/src/state/docket.ts @@ -1,9 +1,7 @@ import create from 'zustand'; import produce from 'immer'; import { useCallback, useEffect } from 'react'; -import { omit } from 'lodash-es'; -import api from './api'; -import { mockAllies, mockCharges, mockTreaties } from './mock-data'; +import { mapValues, omit, pick } from 'lodash-es'; import { Allies, Charge, @@ -21,8 +19,9 @@ import { docketInstall, ChargeUpdate } from '@urbit/api/docket'; -import _ from 'lodash'; -import {kilnRevive, kilnSuspend} from '@urbit/api/hood'; +import { kilnRevive, kilnSuspend } from '@urbit/api/hood'; +import api from './api'; +import { mockAllies, mockCharges, mockTreaties } from './mock-data'; const useMockData = import.meta.env.MODE === 'mock'; @@ -67,8 +66,10 @@ const useDocketState = create((set, get) => ({ return allies; }, fetchAllyTreaties: async (ally: string) => { - let treaties = useMockData ? mockTreaties : (await api.scry(scryAllyTreaties(ally))).ini; - treaties = _.mapValues(treaties, normalizeDocket); + let treaties = useMockData + ? mockTreaties + : (await api.scry(scryAllyTreaties(ally))).ini; + treaties = mapValues(treaties, normalizeDocket); set((s) => ({ treaties: { ...s.treaties, ...treaties } })); return treaties; }, @@ -97,10 +98,9 @@ const useDocketState = create((set, get) => ({ throw new Error('Bad install'); } if (useMockData) { - - set((state) => addCharge(state, desk, {...treaty, chad: { install: null }})); + set((state) => addCharge(state, desk, { ...treaty, chad: { install: null } })); await new Promise((res) => setTimeout(() => res(), 5000)); - set((state) => addCharge(state, desk, {...treaty, chad: { glob: null }})); + set((state) => addCharge(state, desk, { ...treaty, chad: { glob: null } })); } return api.poke(docketInstall(ship, desk)); @@ -117,7 +117,7 @@ const useDocketState = create((set, get) => ({ }); }, toggleDocket: async (desk: string) => { - if(useMockData) { + if (useMockData) { set( produce((draft) => { const charge = draft.charges[desk]; @@ -127,11 +127,11 @@ const useDocketState = create((set, get) => ({ } const { charges } = get(); const charge = charges[desk]; - if(!charge) { + if (!charge) { return; } const suspended = 'suspend' in charge.chad; - if(suspended) { + if (suspended) { await api.poke(kilnRevive(desk)); } else { await api.poke(kilnSuspend(desk)); @@ -175,15 +175,14 @@ api.subscribe({ path: '/charges', event: (data: ChargeUpdate) => { useDocketState.setState((state) => { - if ('add-charge' in data) { - const { desk, charge } = data['add-charge'] - return addCharge(state, desk, charge) + const { desk, charge } = data['add-charge']; + return addCharge(state, desk, charge); } if ('del-charge' in data) { const desk = data['del-charge']; - return delCharge(state, desk) + return delCharge(state, desk); } return { charges: state.charges }; @@ -222,7 +221,7 @@ export function useAllyTreaties(ship: string) { useCallback( (s) => { const charter = s.allies[ship]; - return _.pick(s.treaties, ...(charter || [])); + return pick(s.treaties, ...(charter || [])); }, [ship] ) @@ -242,6 +241,6 @@ export function useTreaty(host: string, desk: string) { } // xx useful for debugging -//window.docket = useDocketState.getState; +// window.docket = useDocketState.getState; export default useDocketState; diff --git a/pkg/grid/src/state/mock-data.ts b/pkg/grid/src/state/mock-data.ts index c18cf69983..6f6728eaf2 100644 --- a/pkg/grid/src/state/mock-data.ts +++ b/pkg/grid/src/state/mock-data.ts @@ -1,6 +1,6 @@ -import systemUrl from '../assets/system.png'; -import _ from 'lodash'; +import _ from 'lodash-es'; import { Allies, Charges, DocketHrefGlob, Treaties, Treaty } from '@urbit/api/docket'; +import systemUrl from '../assets/system.png'; export const appMetaData: Pick = { cass: '~2021.8.11..05.11.10..b721', @@ -127,9 +127,8 @@ export const mockCharges: Charges = _.reduce( mockTreaties, (acc, val, key) => { const [, desk] = key.split('/'); - const chad = desk === 'uniswap' - ? { install: null } : { glob : null }; - if(desk === 'inbox') { + const chad = { glob: null }; + if (desk === 'inbox') { return acc; } diff --git a/pkg/grid/src/tiles/RemoveApp.tsx b/pkg/grid/src/tiles/RemoveApp.tsx index 4239c4644f..3325ce7cbe 100644 --- a/pkg/grid/src/tiles/RemoveApp.tsx +++ b/pkg/grid/src/tiles/RemoveApp.tsx @@ -1,7 +1,7 @@ import React, { useCallback } from 'react'; import { useHistory, useParams } from 'react-router-dom'; import { Button } from '../components/Button'; -import { Dialog, DialogContent } from '../components/Dialog'; +import { Dialog, DialogClose, DialogContent } from '../components/Dialog'; import useDocketState, { useCharges } from '../state/docket'; export const RemoveApp = () => { @@ -14,19 +14,23 @@ export const RemoveApp = () => { // TODO: add optimistic updates const handleRemoveApp = useCallback(() => { uninstallDocket(desk); - history.push('/'); - }, []); + }, [desk]); return ( !open && history.push('/')}> - -

Remove “{docket?.title || ''}”

-

- Explanatory writing about what data will be kept. + +

Remove “{docket?.title || ''}”?

+

+ This will remove the software's tile from your home screen.

- +
+ + Cancel + + + Remove “{docket?.title}” + +
); diff --git a/pkg/grid/src/tiles/SuspendApp.tsx b/pkg/grid/src/tiles/SuspendApp.tsx index 748a298623..c7cfcdf573 100644 --- a/pkg/grid/src/tiles/SuspendApp.tsx +++ b/pkg/grid/src/tiles/SuspendApp.tsx @@ -1,7 +1,7 @@ import React, { useCallback } from 'react'; import { Redirect, useHistory, useParams } from 'react-router-dom'; import { Button } from '../components/Button'; -import { Dialog, DialogContent } from '../components/Dialog'; +import { Dialog, DialogClose, DialogContent } from '../components/Dialog'; import useDocketState, { useCharges } from '../state/docket'; export const SuspendApp = () => { @@ -13,7 +13,6 @@ export const SuspendApp = () => { // TODO: add optimistic updates const handleSuspendApp = useCallback(() => { useDocketState.getState().toggleDocket(desk); - history.push('/'); }, [desk]); if ('suspend' in charge.chad) { @@ -22,14 +21,19 @@ export const SuspendApp = () => { return ( !open && history.push('/')}> - -

Suspend “{charge?.title || ''}”

-

+ +

Suspend “{charge?.title || ''}”

+

Suspending an app will freeze its current state, and render it unable

- +
+ + Cancel + + + Suspend “{charge?.title}” + +
); diff --git a/pkg/grid/src/tiles/Tile.tsx b/pkg/grid/src/tiles/Tile.tsx index 6b52f30d2a..3cbfa26538 100644 --- a/pkg/grid/src/tiles/Tile.tsx +++ b/pkg/grid/src/tiles/Tile.tsx @@ -38,7 +38,7 @@ export const Tile: FunctionComponent = ({ charge, desk }) => { href={active ? link : undefined} target={desk} className={classNames( - 'group relative font-semibold aspect-w-1 aspect-h-1 rounded-xl default-ring', + 'group relative font-semibold aspect-w-1 aspect-h-1 rounded-3xl default-ring', !active && 'cursor-default' )} style={{ backgroundColor: active ? color || 'purple' : suspendColor }}