@hanzo/app 0.2.45 → 0.2.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/SettingsPane.js +5 -28
- package/dist/Setup.js +46 -8
- package/dist/pref.d.ts +15 -0
- package/dist/pref.js +96 -0
- package/package.json +1 -1
package/dist/SettingsPane.js
CHANGED
|
@@ -26,6 +26,7 @@ import { showSettings } from './open.js';
|
|
|
26
26
|
import { Look } from './look.js';
|
|
27
27
|
import { ProviderMark } from './ProviderMark.js';
|
|
28
28
|
import { bearer, org, pick } from './lib/session.js';
|
|
29
|
+
import { usePref } from './pref.js';
|
|
29
30
|
import { Experimental } from './experimental.js';
|
|
30
31
|
import { site } from './where.js';
|
|
31
32
|
import { named, ROWS } from './Settings.js';
|
|
@@ -142,40 +143,16 @@ function Account() {
|
|
|
142
143
|
/** Real Web3 Wallet Connect & Payout Address for collecting referral & compute rewards. */
|
|
143
144
|
function WalletPayouts() {
|
|
144
145
|
const { t } = useI18n();
|
|
145
|
-
const [address, setAddress] =
|
|
146
|
-
|
|
147
|
-
return typeof window !== 'undefined' ? (window.localStorage.getItem('hanzo.wallet.address') ?? '') : '';
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
return '';
|
|
151
|
-
}
|
|
152
|
-
});
|
|
146
|
+
const [address, setAddress] = usePref('rewards_payout_wallet', '');
|
|
147
|
+
const [, setProvider] = usePref('rewards_payout_provider', '');
|
|
153
148
|
const [busy, setBusy] = useState(false);
|
|
154
149
|
const [saved, setSaved] = useState(false);
|
|
155
150
|
const [error, setError] = useState('');
|
|
156
151
|
const persist = async (addr, provider) => {
|
|
157
152
|
const clean = addr.trim();
|
|
153
|
+
// The account holds the address (PATCH /v1/pref), so it is the same on every machine.
|
|
158
154
|
setAddress(clean);
|
|
159
|
-
|
|
160
|
-
if (clean)
|
|
161
|
-
window.localStorage.setItem('hanzo.wallet.address', clean);
|
|
162
|
-
else
|
|
163
|
-
window.localStorage.removeItem('hanzo.wallet.address');
|
|
164
|
-
}
|
|
165
|
-
catch { }
|
|
166
|
-
const tok = bearer();
|
|
167
|
-
if (tok && clean) {
|
|
168
|
-
await fetch(`${api()}/v1/preferences`, {
|
|
169
|
-
method: 'PUT',
|
|
170
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${tok}` },
|
|
171
|
-
body: JSON.stringify({
|
|
172
|
-
preferences: {
|
|
173
|
-
rewards_payout_wallet: clean,
|
|
174
|
-
rewards_payout_provider: provider,
|
|
175
|
-
},
|
|
176
|
-
}),
|
|
177
|
-
}).catch(() => { });
|
|
178
|
-
}
|
|
155
|
+
setProvider(clean ? provider : '');
|
|
179
156
|
setSaved(true);
|
|
180
157
|
setTimeout(() => setSaved(false), 2400);
|
|
181
158
|
};
|
package/dist/Setup.js
CHANGED
|
@@ -24,6 +24,7 @@ import { ProviderMark } from './ProviderMark.js';
|
|
|
24
24
|
import { useBetas } from './Betas.js';
|
|
25
25
|
import { useRooms } from './host.js';
|
|
26
26
|
import { useKept } from './kept.js';
|
|
27
|
+
import { usePref } from './pref.js';
|
|
27
28
|
import { api } from './lib/api.js';
|
|
28
29
|
import { app } from './lib/host.js';
|
|
29
30
|
import { scope } from './lib/session.js';
|
|
@@ -48,16 +49,18 @@ export function Setup({ go } = {}) {
|
|
|
48
49
|
const { isAuthenticated, accessToken } = useIam();
|
|
49
50
|
const { open: opens } = useBetas();
|
|
50
51
|
const pathed = useRooms().path !== null;
|
|
51
|
-
const [later, setLater] =
|
|
52
|
-
const [step, setStep] =
|
|
53
|
-
const [githubDone, setGithubDone] =
|
|
54
|
-
const [slackDone, setSlackDone] =
|
|
55
|
-
const [pluginDone, setPluginDone] =
|
|
52
|
+
const [later, setLater, known] = usePref(LATER_KEY, false);
|
|
53
|
+
const [step, setStep] = usePref(STEP_KEY, 1);
|
|
54
|
+
const [githubDone, setGithubDone] = usePref(GITHUB_KEY, false);
|
|
55
|
+
const [slackDone, setSlackDone] = usePref(SLACK_KEY, false);
|
|
56
|
+
const [pluginDone, setPluginDone] = usePref(PLUGIN_KEY, false);
|
|
56
57
|
const [googleDone, setGoogleDone] = useKept(GOOGLE_KEY, false);
|
|
57
58
|
const [googleAccounts, setGoogleAccounts] = useKept(GOOGLE_ACCOUNTS_KEY, []);
|
|
58
59
|
const [busy, setBusy] = useState(null);
|
|
59
60
|
const [modalOpen, setModalOpen] = useState(false);
|
|
60
61
|
const [errorMsg, setErrorMsg] = useState(null);
|
|
62
|
+
// A first press on Disconnect asks; the second lets go of GitHub.
|
|
63
|
+
const [dropping, setDropping] = useState(false);
|
|
61
64
|
const [syncTurn, setSyncTurn] = useState(0);
|
|
62
65
|
const signed = isAuthenticated && Boolean(accessToken);
|
|
63
66
|
const accountList = Array.isArray(googleAccounts) ? googleAccounts : [];
|
|
@@ -198,7 +201,8 @@ export function Setup({ go } = {}) {
|
|
|
198
201
|
const totalDone = (githubDone ? 1 : 0) + (slackDone ? 1 : 0) + (pluginDone ? 1 : 0);
|
|
199
202
|
const allDone = totalDone === 3;
|
|
200
203
|
const activeStep = step === 1 || step === 2 || step === 3 ? step : 1;
|
|
201
|
-
|
|
204
|
+
// Dismissed on another machine is dismissed here: the account answers before the card draws.
|
|
205
|
+
if (!known || (later && !modalOpen))
|
|
202
206
|
return null;
|
|
203
207
|
const openOAuthPopup = (authorizeUrl, provider, label, onDone) => {
|
|
204
208
|
const popup = window.open(authorizeUrl, `hanzo-oauth-${provider}`, 'width=600,height=700');
|
|
@@ -279,6 +283,40 @@ export function Setup({ go } = {}) {
|
|
|
279
283
|
setGithubDone(true);
|
|
280
284
|
setStep(slackDone ? 3 : 2);
|
|
281
285
|
});
|
|
286
|
+
// Let go of the org's GitHub accounts, so another can be connected. The platform
|
|
287
|
+
// also removes its App from an account no other organization uses, so the next
|
|
288
|
+
// connect is a fresh install. An org admin's act: anyone else is told so.
|
|
289
|
+
const handleDisconnectGithub = async () => {
|
|
290
|
+
if (!dropping) {
|
|
291
|
+
setDropping(true);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
setBusy('github');
|
|
295
|
+
setErrorMsg(null);
|
|
296
|
+
try {
|
|
297
|
+
const res = await fetch(`${api()}/v1/provider/github/disconnect`, {
|
|
298
|
+
method: 'POST',
|
|
299
|
+
headers: { ...scope(), 'Content-Type': 'application/json' },
|
|
300
|
+
body: '{}',
|
|
301
|
+
});
|
|
302
|
+
if (!res.ok) {
|
|
303
|
+
setErrorMsg(res.status === 403
|
|
304
|
+
? t('Only an organization admin can disconnect GitHub.')
|
|
305
|
+
: t('Could not disconnect {provider} right now. Please try again.', { provider: 'GitHub' }));
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
setGithubDone(false);
|
|
309
|
+
setStep(1);
|
|
310
|
+
setSyncTurn((n) => n + 1);
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
setErrorMsg(t('Could not disconnect {provider} right now. Please try again.', { provider: 'GitHub' }));
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
setDropping(false);
|
|
317
|
+
setBusy(null);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
282
320
|
// 2. Connect Slack
|
|
283
321
|
const handleConnectSlack = () => connectOAuthProvider('slack', 'Slack', () => {
|
|
284
322
|
setSlackDone(true);
|
|
@@ -288,13 +326,13 @@ export function Setup({ go } = {}) {
|
|
|
288
326
|
const handleConnectGoogle = () => connectOAuthProvider('google', 'Google', () => {
|
|
289
327
|
setGoogleDone(true);
|
|
290
328
|
});
|
|
291
|
-
return (_jsxs(_Fragment, { children: [_jsxs(YStack, { "data-slot": "setup", role: "region", "aria-label": t('Onboarding (1-2-3)'), gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "$raised", width: "100%", overflow: "hidden", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$1.5", minW: 0, flex: 1, children: [_jsx(Sparkles, { size: 15, color: "var(--primary)", "aria-hidden": true }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: allDone ? t('Onboarding complete') : t('Quick setup ({n}/3)', { n: totalDone }) })] }), _jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Box, { render: "button", "aria-label": t('Expand onboarding popup'), onClick: () => setModalOpen(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Maximize2, { size: 13, "aria-hidden": true, color: "$soft" }) }), _jsx(Box, { render: "button", "aria-label": t('Dismiss'), onClick: () => setLater(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(X, { size: 13, "aria-hidden": true, color: "$soft" }) })] })] }), _jsxs(XStack, { gap: "$1", width: "100%", children: [_jsx(Box, { render: "button", "aria-label": t('Step 1: Connect GitHub'), onClick: () => setStep(1), flex: 1, height: 6, rounded: 3, bg: githubDone ? GOOD : activeStep === 1 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 2: Connect Slack'), onClick: () => setStep(2), flex: 1, height: 6, rounded: 3, bg: slackDone ? GOOD : activeStep === 2 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 3: Connect a plugin'), onClick: () => setStep(3), flex: 1, height: 6, rounded: 3, bg: pluginDone ? GOOD : activeStep === 3 ? '$ink' : '$edge', cursor: "pointer" })] }), allDone ? (_jsxs(YStack, { gap: "$2", pt: "$1", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Check, { size: 16, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$2", color: "$ink", fontWeight: "500", children: t('GitHub, Slack & a plugin connected') })] }), workspace && accountList.length > 0 ? (_jsx(XStack, { gap: "$1", flexWrap: "wrap", children: accountList.map((acct) => (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$0.5", rounded: "$2", bg: "$edge", children: [_jsx(Text, { fontSize: "$1", color: "$ink", numberOfLines: 1, children: acct }), _jsx(Box, { render: "button", "aria-label": t('Remove {account}', { account: acct }), onClick: () => removeGoogleAccount(acct), cursor: "pointer", children: _jsx(X, { size: 11, color: "$soft", "aria-hidden": true }) })] }, acct))) })) : null, _jsxs(XStack, { gap: "$1.5", items: "center", flexWrap: "wrap", children: [workspace ? (_jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(Plus, { size: 12, color: "$ink", "aria-hidden": true }), _jsx(Text, { fontSize: "$1", fontWeight: "500", color: "$ink", children: t('Add Google account') })] }) })) : null, _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, items: "center", justify: "center", cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "500", children: t('Done') }) })] })] })) : activeStep === 1 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('1. Connect GitHub') })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and team repository context.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectGithub, "aria-disabled": busy === 'github', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'github' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : githubDone ? t('Reconnect') : t('Connect GitHub') }) }), _jsx(Box, { render: "button", onClick: () => setStep(2), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : activeStep === 2 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(SlackMark, { size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('2. Connect Slack') })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Route agent notifications and chat in team channels.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectSlack, "aria-disabled": busy === 'slack', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'slack' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : slackDone ? t('Reconnect') : t('Connect Slack') }) }), _jsx(Box, { render: "button", onClick: () => setStep(3), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(Plug, { size: 18, color: "var(--foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('3. Connect a plugin') })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Give your agents tools: build a plugin or add an MCP server in Customize.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: openPlugins, px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: pluginDone ? t('Open plugins') : t('Connect a plugin') }) }), _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: pluginDone ? t('Done') : t('Skip') }) })] }), workspace ? (_jsxs(YStack, { gap: "$2", minW: 0, pt: "$2", borderTopWidth: 1, borderColor: "$borderColor", "data-slot": "setup-workspace", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('Google Workspace') })] }), hasGoogle ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: accountList.length > 1
|
|
329
|
+
return (_jsxs(_Fragment, { children: [_jsxs(YStack, { "data-slot": "setup", role: "region", "aria-label": t('Onboarding (1-2-3)'), gap: "$2.5", p: "$3", rounded: "$4", borderWidth: 1, borderColor: "$borderColor", bg: "$raised", width: "100%", overflow: "hidden", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$1.5", minW: 0, flex: 1, children: [_jsx(Sparkles, { size: 15, color: "var(--primary)", "aria-hidden": true }), _jsx(SizableText, { size: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: allDone ? t('Onboarding complete') : t('Quick setup ({n}/3)', { n: totalDone }) })] }), _jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Box, { render: "button", "aria-label": t('Expand onboarding popup'), onClick: () => setModalOpen(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Maximize2, { size: 13, "aria-hidden": true, color: "$soft" }) }), _jsx(Box, { render: "button", "aria-label": t('Dismiss'), onClick: () => setLater(true), p: "$1", rounded: 999, hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(X, { size: 13, "aria-hidden": true, color: "$soft" }) })] })] }), _jsxs(XStack, { gap: "$1", width: "100%", children: [_jsx(Box, { render: "button", "aria-label": t('Step 1: Connect GitHub'), onClick: () => setStep(1), flex: 1, height: 6, rounded: 3, bg: githubDone ? GOOD : activeStep === 1 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 2: Connect Slack'), onClick: () => setStep(2), flex: 1, height: 6, rounded: 3, bg: slackDone ? GOOD : activeStep === 2 ? '$ink' : '$edge', cursor: "pointer" }), _jsx(Box, { render: "button", "aria-label": t('Step 3: Connect a plugin'), onClick: () => setStep(3), flex: 1, height: 6, rounded: 3, bg: pluginDone ? GOOD : activeStep === 3 ? '$ink' : '$edge', cursor: "pointer" })] }), allDone ? (_jsxs(YStack, { gap: "$2", pt: "$1", children: [_jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Check, { size: 16, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$2", color: "$ink", fontWeight: "500", children: t('GitHub, Slack & a plugin connected') })] }), workspace && accountList.length > 0 ? (_jsx(XStack, { gap: "$1", flexWrap: "wrap", children: accountList.map((acct) => (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$0.5", rounded: "$2", bg: "$edge", children: [_jsx(Text, { fontSize: "$1", color: "$ink", numberOfLines: 1, children: acct }), _jsx(Box, { render: "button", "aria-label": t('Remove {account}', { account: acct }), onClick: () => removeGoogleAccount(acct), cursor: "pointer", children: _jsx(X, { size: 11, color: "$soft", "aria-hidden": true }) })] }, acct))) })) : null, _jsxs(XStack, { gap: "$1.5", items: "center", flexWrap: "wrap", children: [workspace ? (_jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsxs(XStack, { items: "center", gap: "$1", children: [_jsx(Plus, { size: 12, color: "$ink", "aria-hidden": true }), _jsx(Text, { fontSize: "$1", fontWeight: "500", color: "$ink", children: t('Add Google account') })] }) })) : null, _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2.5", py: "$1", rounded: "$3", bg: "$edge", hoverStyle: { bg: '$hover' }, items: "center", justify: "center", cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "500", children: t('Done') }) })] })] })) : activeStep === 1 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('1. Connect GitHub') })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and team repository context.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectGithub, "aria-disabled": busy === 'github', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'github' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : githubDone ? t('Reconnect') : t('Connect GitHub') }) }), githubDone ? (_jsx(Box, { render: "button", onClick: () => void handleDisconnectGithub(), "aria-disabled": busy === 'github', px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: dropping ? '$ink' : '$soft', children: dropping ? t('Confirm disconnect') : t('Disconnect') }) })) : null, _jsx(Box, { render: "button", onClick: () => setStep(2), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : activeStep === 2 ? (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(SlackMark, { size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('2. Connect Slack') })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Route agent notifications and chat in team channels.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: handleConnectSlack, "aria-disabled": busy === 'slack', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'slack' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : slackDone ? t('Reconnect') : t('Connect Slack') }) }), _jsx(Box, { render: "button", onClick: () => setStep(3), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Skip') }) })] })] })) : (_jsxs(YStack, { gap: "$2", minW: 0, children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(Plug, { size: 18, color: "var(--foreground)", "aria-hidden": true }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('3. Connect a plugin') })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Give your agents tools: build a plugin or add an MCP server in Customize.') }), _jsxs(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: [_jsx(Box, { render: "button", onClick: openPlugins, px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: pluginDone ? t('Open plugins') : t('Connect a plugin') }) }), _jsx(Box, { render: "button", onClick: () => setLater(true), px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: "$soft", children: pluginDone ? t('Done') : t('Skip') }) })] }), workspace ? (_jsxs(YStack, { gap: "$2", minW: 0, pt: "$2", borderTopWidth: 1, borderColor: "$borderColor", "data-slot": "setup-workspace", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$1.5", flexWrap: "wrap", minW: 0, children: [_jsxs(XStack, { items: "center", gap: "$2", minW: 0, flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 18 }), _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "$ink", numberOfLines: 1, children: t('Google Workspace') })] }), hasGoogle ? (_jsxs(XStack, { items: "center", gap: "$1", shrink: 0, children: [_jsx(Check, { size: 12, color: GOOD, "aria-hidden": true }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: accountList.length > 1
|
|
292
330
|
? t('{n} connected', { n: accountList.length })
|
|
293
331
|
: t('Connected') })] })) : null] }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Grant Drive, Docs, Sheets, Gmail & Calendar permissions. Add personal, work, or multiple org accounts.') }), accountList.length > 0 ? (_jsx(XStack, { gap: "$1", flexWrap: "wrap", children: accountList.map((acct) => (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$0.5", rounded: "$2", bg: "$edge", children: [_jsx(Text, { fontSize: "$1", color: "$ink", numberOfLines: 1, children: acct }), _jsx(Box, { render: "button", "aria-label": t('Remove {account}', { account: acct }), onClick: () => removeGoogleAccount(acct), cursor: "pointer", children: _jsx(X, { size: 11, color: "$soft", "aria-hidden": true }) })] }, acct))) })) : null, _jsx(XStack, { gap: "$1.5", items: "center", pt: "$1", flexWrap: "wrap", children: _jsx(Box, { render: "button", onClick: handleConnectGoogle, "aria-disabled": busy === 'google', px: "$2.5", py: "$1", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", opacity: busy === 'google' ? 0.6 : 1, children: _jsx(Text, { fontSize: "$1", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'google'
|
|
294
332
|
? t('Connecting…')
|
|
295
333
|
: hasGoogle
|
|
296
334
|
? t('+ Add Google account')
|
|
297
|
-
: t('Connect Google') }) }) })] })) : null] })), errorMsg ? (_jsx(Text, { fontSize: "$1", color: "$red10", children: errorMsg })) : null] }), _jsx(Dialog, { open: modalOpen, onOpenChange: setModalOpen, children: _jsxs(DialogContent, { maxW: 520, rounded: "$6", gap: "$4", p: "$5", children: [_jsx(DialogTitle, { children: _jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Sparkles, { size: 20, color: "var(--primary)", "aria-hidden": true }), _jsx(Text, { fontSize: "$5", fontWeight: "600", color: "$ink", children: t('Set up {brand} in 3 steps', { brand: brand() }) })] }) }), _jsx(Text, { fontSize: "$2", color: "$soft", children: t('Connect your code, your team chat, and the tools your agents use.', { brand: brand() }) }), _jsxs(YStack, { gap: "$3", children: [_jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: githubDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('1. GitHub') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and code context') })] })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: handleConnectGithub, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: slackDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(SlackMark, { size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('2. Slack') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Notifications and agent bot chat in channels') })] })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: handleConnectSlack, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: pluginDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(Plug, { size: 24, color: "var(--foreground)", "aria-hidden": true }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('3. Plugins') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Plugins and MCP servers your agents can call') })] })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: openPlugins, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: t('Open') }) }))] }), workspace ? (_jsxs(YStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: hasGoogle ? GOOD : '$borderColor', bg: "$raised", gap: "$2.5", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('Google Workspace · private beta') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Edit Drive files, Docs, Sheets, Gmail & Calendar across personal and business accounts') })] })] }), _jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'google'
|
|
335
|
+
: t('Connect Google') }) }) })] })) : null] })), errorMsg ? (_jsx(Text, { fontSize: "$1", color: "$red10", children: errorMsg })) : null] }), _jsx(Dialog, { open: modalOpen, onOpenChange: setModalOpen, children: _jsxs(DialogContent, { maxW: 520, rounded: "$6", gap: "$4", p: "$5", children: [_jsx(DialogTitle, { children: _jsxs(XStack, { items: "center", gap: "$2", children: [_jsx(Sparkles, { size: 20, color: "var(--primary)", "aria-hidden": true }), _jsx(Text, { fontSize: "$5", fontWeight: "600", color: "$ink", children: t('Set up {brand} in 3 steps', { brand: brand() }) })] }) }), _jsx(Text, { fontSize: "$2", color: "$soft", children: t('Connect your code, your team chat, and the tools your agents use.', { brand: brand() }) }), _jsxs(YStack, { gap: "$3", children: [_jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: githubDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "github", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('1. GitHub') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Sync repositories, PRs, and code context') })] })] }), githubDone ? (_jsxs(XStack, { items: "center", gap: "$2", children: [_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] }), _jsx(Box, { render: "button", onClick: () => void handleDisconnectGithub(), "aria-disabled": busy === 'github', px: "$2", py: "$1", rounded: "$3", bg: "transparent", hoverStyle: { bg: '$hover' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$1", color: dropping ? '$ink' : '$soft', children: dropping ? t('Confirm disconnect') : t('Disconnect') }) })] })) : (_jsx(Box, { render: "button", onClick: handleConnectGithub, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'github' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: slackDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(SlackMark, { size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('2. Slack') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Notifications and agent bot chat in channels') })] })] }), slackDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: handleConnectSlack, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'slack' ? t('Connecting…') : t('Connect') }) }))] }), _jsxs(XStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: pluginDone ? GOOD : '$borderColor', bg: "$raised", items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(Plug, { size: 24, color: "var(--foreground)", "aria-hidden": true }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('3. Plugins') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Plugins and MCP servers your agents can call') })] })] }), pluginDone ? (_jsxs(XStack, { items: "center", gap: "$1", px: "$2", py: "$1", rounded: "$2", bg: "$hover", children: [_jsx(Check, { size: 14, color: GOOD }), _jsx(Text, { fontSize: "$1", color: GOOD, fontWeight: "600", children: t('Connected') })] })) : (_jsx(Box, { render: "button", onClick: openPlugins, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: t('Open') }) }))] }), workspace ? (_jsxs(YStack, { p: "$3", rounded: "$4", borderWidth: 1, borderColor: hasGoogle ? GOOD : '$borderColor', bg: "$raised", gap: "$2.5", children: [_jsxs(XStack, { items: "center", justify: "space-between", gap: "$3", children: [_jsxs(XStack, { items: "center", gap: "$3", flex: 1, children: [_jsx(ProviderMark, { org: "google", size: 24 }), _jsxs(YStack, { flex: 1, minW: 0, children: [_jsx(Text, { fontSize: "$3", fontWeight: "600", color: "$ink", children: t('Google Workspace · private beta') }), _jsx(Text, { fontSize: "$1", color: "$soft", children: t('Edit Drive files, Docs, Sheets, Gmail & Calendar across personal and business accounts') })] })] }), _jsx(Box, { render: "button", onClick: handleConnectGoogle, px: "$3", py: "$1.5", rounded: "$3", bg: "var(--accent)", hoverStyle: { bg: 'var(--accent-hover)' }, cursor: "pointer", children: _jsx(Text, { fontSize: "$2", fontWeight: "600", color: "var(--accent-foreground)", children: busy === 'google'
|
|
298
336
|
? t('Connecting…')
|
|
299
337
|
: hasGoogle
|
|
300
338
|
? t('+ Add account')
|
package/dist/pref.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value kept on the signed-in person's account, so it follows them to every
|
|
3
|
+
* machine and every Hanzo surface: GET /v1/pref reads their preference document,
|
|
4
|
+
* PATCH /v1/pref merges one key into it (shallow: a key sent is replaced whole,
|
|
5
|
+
* the rest are left as they are).
|
|
6
|
+
*
|
|
7
|
+
* Signed in, the account is the truth: a key the document holds wins, and a key
|
|
8
|
+
* it does not hold is `initial`, never what this browser kept for whoever used
|
|
9
|
+
* it before. This browser's copy only paints the first frame and stands in while
|
|
10
|
+
* signed out. `ready` is false until the document has answered, so a surface that
|
|
11
|
+
* would flash (a card the person already dismissed) can wait for it.
|
|
12
|
+
*/
|
|
13
|
+
export declare function usePref<T>(key: string, initial: T): [T, (v: T) => void, boolean];
|
|
14
|
+
/** One key written to the account; a signed-out page keeps it in this browser only. */
|
|
15
|
+
export declare function send(patch: Record<string, unknown>): void;
|
package/dist/pref.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { api } from './lib/api.js';
|
|
4
|
+
import { scope } from './lib/session.js';
|
|
5
|
+
/**
|
|
6
|
+
* A value kept on the signed-in person's account, so it follows them to every
|
|
7
|
+
* machine and every Hanzo surface: GET /v1/pref reads their preference document,
|
|
8
|
+
* PATCH /v1/pref merges one key into it (shallow: a key sent is replaced whole,
|
|
9
|
+
* the rest are left as they are).
|
|
10
|
+
*
|
|
11
|
+
* Signed in, the account is the truth: a key the document holds wins, and a key
|
|
12
|
+
* it does not hold is `initial`, never what this browser kept for whoever used
|
|
13
|
+
* it before. This browser's copy only paints the first frame and stands in while
|
|
14
|
+
* signed out. `ready` is false until the document has answered, so a surface that
|
|
15
|
+
* would flash (a card the person already dismissed) can wait for it.
|
|
16
|
+
*/
|
|
17
|
+
export function usePref(key, initial) {
|
|
18
|
+
const signed = Boolean(scope().Authorization);
|
|
19
|
+
const [value, setValue] = useState(() => local(key, initial));
|
|
20
|
+
const [ready, setReady] = useState(!signed);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!signed)
|
|
23
|
+
return;
|
|
24
|
+
let live = true;
|
|
25
|
+
void held().then((doc) => {
|
|
26
|
+
if (!live)
|
|
27
|
+
return;
|
|
28
|
+
if (doc) {
|
|
29
|
+
const next = key in doc ? doc[key] : initial;
|
|
30
|
+
setValue(next);
|
|
31
|
+
keep(key, next);
|
|
32
|
+
}
|
|
33
|
+
setReady(true);
|
|
34
|
+
});
|
|
35
|
+
return () => {
|
|
36
|
+
live = false;
|
|
37
|
+
};
|
|
38
|
+
// `initial` is a literal at every call site.
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, [key, signed]);
|
|
41
|
+
const set = (v) => {
|
|
42
|
+
setValue(v);
|
|
43
|
+
keep(key, v);
|
|
44
|
+
send({ [key]: v });
|
|
45
|
+
};
|
|
46
|
+
return [value, set, ready];
|
|
47
|
+
}
|
|
48
|
+
/** The document, read once per page and per credential, and shared by every key. */
|
|
49
|
+
let read = null;
|
|
50
|
+
function held() {
|
|
51
|
+
const auth = scope();
|
|
52
|
+
if (!auth.Authorization)
|
|
53
|
+
return Promise.resolve(null);
|
|
54
|
+
if (read?.auth !== auth.Authorization) {
|
|
55
|
+
read = {
|
|
56
|
+
auth: auth.Authorization,
|
|
57
|
+
doc: fetch(`${api()}/v1/pref`, { headers: auth })
|
|
58
|
+
.then((r) => (r.ok ? r.json() : null))
|
|
59
|
+
.then((body) => (body && body.prefs && typeof body.prefs === 'object' ? body.prefs : body ? {} : null))
|
|
60
|
+
.catch(() => null),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return read.doc;
|
|
64
|
+
}
|
|
65
|
+
/** One key written to the account; a signed-out page keeps it in this browser only. */
|
|
66
|
+
export function send(patch) {
|
|
67
|
+
const auth = scope();
|
|
68
|
+
if (!auth.Authorization)
|
|
69
|
+
return;
|
|
70
|
+
if (read?.auth === auth.Authorization) {
|
|
71
|
+
const was = read.doc;
|
|
72
|
+
read = { auth: auth.Authorization, doc: was.then((doc) => ({ ...(doc ?? {}), ...patch })) };
|
|
73
|
+
}
|
|
74
|
+
void fetch(`${api()}/v1/pref`, {
|
|
75
|
+
method: 'PATCH',
|
|
76
|
+
headers: { ...auth, 'Content-Type': 'application/json' },
|
|
77
|
+
body: JSON.stringify(patch),
|
|
78
|
+
}).catch(() => { });
|
|
79
|
+
}
|
|
80
|
+
function local(key, initial) {
|
|
81
|
+
try {
|
|
82
|
+
const raw = localStorage.getItem(key);
|
|
83
|
+
return raw === null ? initial : JSON.parse(raw);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return initial;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function keep(key, v) {
|
|
90
|
+
try {
|
|
91
|
+
localStorage.setItem(key, JSON.stringify(v));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
/* the account still holds it */
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/app",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.47",
|
|
4
4
|
"description": "Hanzo's app: the shell and its apps (Home, Chat, Inbox, Contacts, Meet, Calendar, Drive, Board, Work, Bots), once, for every Hanzo surface.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|