From b8f32963202879ad4709e60f32ab4e549605e16b Mon Sep 17 00:00:00 2001 From: Liam Fitzgerald Date: Fri, 10 Sep 2021 10:10:39 +1000 Subject: [PATCH] interface: update settings callsites --- pkg/interface/src/logic/state/settings.ts | 4 ++-- pkg/interface/src/views/apps/launch/App.tsx | 7 ++++--- .../views/apps/settings/components/lib/LeapSettings.tsx | 5 ++--- .../apps/settings/components/lib/ShortcutSettings.tsx | 7 +++---- pkg/interface/src/views/landscape/components/JoinGroup.tsx | 6 ++++-- .../src/views/landscape/components/TutorialModal.tsx | 6 ++++-- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pkg/interface/src/logic/state/settings.ts b/pkg/interface/src/logic/state/settings.ts index cbd2fc146..9762a8bfd 100644 --- a/pkg/interface/src/logic/state/settings.ts +++ b/pkg/interface/src/logic/state/settings.ts @@ -45,7 +45,7 @@ export interface SettingsState { keyboard: ShortcutMapping; remoteContentPolicy: RemoteContentPolicy; getAll: () => Promise; - putEntry: (bucket: string, key: string, value: Value) => void; + putEntry: (bucket: string, key: string, value: Value) => Promise; leap: { categories: LeapCategories[]; }; @@ -108,7 +108,7 @@ const useSettingsState = createState( } }); }, - putEntry: (bucket: string, entry: string, value: Value) => { + putEntry: async (bucket: string, entry: string, value: Value) => { const poke = putEntry((window as any).desk, bucket, entry, value); pokeOptimisticallyN(useSettingsState, poke, reduceUpdate); } diff --git a/pkg/interface/src/views/apps/launch/App.tsx b/pkg/interface/src/views/apps/launch/App.tsx index fe0eb7b6a..55238e02c 100644 --- a/pkg/interface/src/views/apps/launch/App.tsx +++ b/pkg/interface/src/views/apps/launch/App.tsx @@ -32,7 +32,6 @@ import Tiles from './components/tiles'; import Tile from './components/tiles/tile'; import './css/custom.css'; import { join } from '@urbit/api/groups'; -import { putEntry } from '@urbit/api/settings'; import { joinGraph } from '@urbit/api/graph'; import airlock from '~/logic/api'; @@ -103,15 +102,17 @@ export const LaunchApp = (props: LaunchAppProps): ReactElement | null => { maxWidth: '350px', modal: function modal(dismiss) { const onDismiss = (e) => { + const { putEntry } = useSettingsState.getState(); e.stopPropagation(); - airlock.poke(putEntry('tutorial', 'seen', true)); + putEntry('tutorial', 'seen', true); dismiss(); }; const onContinue = async (e) => { + const { putEntry } = useSettingsState.getState(); e.stopPropagation(); if (!hasTutorialGroup({ associations })) { await airlock.poke(join(TUTORIAL_HOST, TUTORIAL_GROUP)); - await airlock.poke(putEntry('tutorial', 'joined', Date.now())); + await putEntry('tutorial', 'joined', Date.now()); await waiter(hasTutorialGroup); await Promise.all( [TUTORIAL_BOOK, TUTORIAL_CHAT, TUTORIAL_LINKS].map(graph => airlock.thread(joinGraph(TUTORIAL_HOST, graph)))); diff --git a/pkg/interface/src/views/apps/settings/components/lib/LeapSettings.tsx b/pkg/interface/src/views/apps/settings/components/lib/LeapSettings.tsx index 9b0d28a85..1d6961fc2 100644 --- a/pkg/interface/src/views/apps/settings/components/lib/LeapSettings.tsx +++ b/pkg/interface/src/views/apps/settings/components/lib/LeapSettings.tsx @@ -4,7 +4,6 @@ import { ManagedCheckboxField, Text } from '@tlon/indigo-react'; import { Form, useFormikContext } from 'formik'; -import { putEntry } from '@urbit/api/settings'; import _ from 'lodash'; import React from 'react'; import useSettingsState, { selectSettingsState } from '~/logic/state/settings'; @@ -15,7 +14,6 @@ import { import { FormikOnBlur } from '~/views/components/FormikOnBlur'; import { ShuffleFields } from '~/views/components/ShuffleFields'; import { BackButton } from './BackButton'; -import airlock from '~/logic/api'; const labels: Record = { mychannel: 'My Channels', @@ -60,11 +58,12 @@ export function LeapSettings() { }; const onSubmit = async (values: FormSchema) => { + const { putEntry } = useSettingsState.getState(); const result = values.categories.reduce( (acc, { display, category }) => (display ? [...acc, category] : acc), [] as LeapCategories[] ); - await airlock.poke(putEntry('leap', 'categories', result)); + await putEntry('leap', 'categories', result); }; return ( diff --git a/pkg/interface/src/views/apps/settings/components/lib/ShortcutSettings.tsx b/pkg/interface/src/views/apps/settings/components/lib/ShortcutSettings.tsx index 1ffa0471b..4d951b229 100644 --- a/pkg/interface/src/views/apps/settings/components/lib/ShortcutSettings.tsx +++ b/pkg/interface/src/views/apps/settings/components/lib/ShortcutSettings.tsx @@ -3,7 +3,6 @@ import _ from 'lodash'; import { Box, Col, Text } from '@tlon/indigo-react'; import { Formik, Form, useField } from 'formik'; -import { putEntry } from '@urbit/api/settings'; import { getChord } from '~/logic/lib/util'; import useSettingsState, { @@ -12,7 +11,6 @@ import useSettingsState, { } from '~/logic/state/settings'; import { AsyncButton } from '~/views/components/AsyncButton'; import { BackButton } from './BackButton'; -import airlock from '~/logic/api'; const settingsSel = selectSettingsState(['keyboard']); @@ -69,9 +67,10 @@ export default function ShortcutSettings() { initialValues={keyboard} onSubmit={async (values: ShortcutMapping, actions) => { const promises = _.map(values, (value, key) => { + const { putEntry } = useSettingsState.getState(); return keyboard[key] !== value - ? airlock.poke(putEntry('keyboard', key, value)) - : Promise.resolve(0); + ? putEntry('keyboard', key, value) + : Promise.resolve(); }); await Promise.all(promises); actions.setStatus({ success: null }); diff --git a/pkg/interface/src/views/landscape/components/JoinGroup.tsx b/pkg/interface/src/views/landscape/components/JoinGroup.tsx index 4383a06c4..27396fd36 100644 --- a/pkg/interface/src/views/landscape/components/JoinGroup.tsx +++ b/pkg/interface/src/views/landscape/components/JoinGroup.tsx @@ -4,7 +4,7 @@ import { ManagedTextInputField as Input, Row, Text } from '@tlon/indigo-react'; -import { join, MetadataUpdatePreview, putEntry } from '@urbit/api'; +import { join, MetadataUpdatePreview } from '@urbit/api'; import { Form, Formik, FormikHelpers, useFormikContext } from 'formik'; import _ from 'lodash'; import React, { ReactElement, useCallback, useEffect, useState } from 'react'; @@ -22,6 +22,7 @@ import { FormError } from '~/views/components/FormError'; import { StatelessAsyncButton } from '~/views/components/StatelessAsyncButton'; import { GroupSummary } from './GroupSummary'; import airlock from '~/logic/api'; +import useSettingsState from '~/logic/state/settings'; const formSchema = Yup.object({ group: Yup.string() @@ -73,8 +74,9 @@ export function JoinGroup(props: JoinGroupProps): ReactElement { const onConfirm = useCallback(async (group: string) => { const [,,ship,name] = group.split('/'); + const { putEntry } = useSettingsState.getState(); if(group === TUTORIAL_GROUP_RESOURCE) { - await airlock.poke(putEntry('tutorial', 'joined', Date.now())); + await putEntry('tutorial', 'joined', Date.now()); } if (group in groups) { return history.push(`/~landscape${group}`); diff --git a/pkg/interface/src/views/landscape/components/TutorialModal.tsx b/pkg/interface/src/views/landscape/components/TutorialModal.tsx index 57e67c1bf..c8f3802f3 100644 --- a/pkg/interface/src/views/landscape/components/TutorialModal.tsx +++ b/pkg/interface/src/views/landscape/components/TutorialModal.tsx @@ -1,5 +1,5 @@ import { Box, Button, Col, Icon, Row, Text } from '@tlon/indigo-react'; -import { leaveGroup, putEntry } from '@urbit/api'; +import { leaveGroup } from '@urbit/api'; import _ from 'lodash'; import React, { useCallback, useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; @@ -16,6 +16,7 @@ import { Portal } from '~/views/components/Portal'; import { StatelessAsyncButton } from '~/views/components/StatelessAsyncButton'; import { Triangle } from '~/views/components/Triangle'; import airlock from '~/logic/api'; +import useSettingsState from '~/logic/state/settings'; const localSelector = selectLocalState([ 'tutorialProgress', @@ -94,7 +95,8 @@ export function TutorialModal() { const dismiss = useCallback(async () => { setPaused(false); hideTutorial(); - await airlock.poke(putEntry('tutorial', 'seen', true)); + const { putEntry } = useSettingsState.getState(); + await putEntry('tutorial', 'seen', true); }, [hideTutorial]); const bailExit = useCallback(() => {