Generalized frontend model store (#193)

This commit is contained in:
Gregory Schier
2025-03-31 11:56:17 -07:00
committed by GitHub
parent ce885c3551
commit f1757ae427
201 changed files with 2185 additions and 2865 deletions

View File

@@ -1,6 +1,6 @@
import { patchModel, settingsAtom } from '@yaakapp-internal/models';
import { useAtomValue } from 'jotai';
import React from 'react';
import { useSettings } from '../../hooks/useSettings';
import { useUpdateSettings } from '../../hooks/useUpdateSettings';
import { Checkbox } from '../core/Checkbox';
import { PlainInput } from '../core/PlainInput';
import { Select } from '../core/Select';
@@ -8,8 +8,7 @@ import { Separator } from '../core/Separator';
import { HStack, VStack } from '../core/Stacks';
export function SettingsProxy() {
const settings = useSettings();
const updateSettings = useUpdateSettings();
const settings = useAtomValue(settingsAtom);
return (
<VStack space={1.5} className="mb-4">
@@ -19,11 +18,11 @@ export function SettingsProxy() {
hideLabel
size="sm"
value={settings.proxy?.type ?? 'automatic'}
onChange={(v) => {
onChange={async (v) => {
if (v === 'automatic') {
updateSettings.mutate({ proxy: undefined });
await patchModel(settings, { proxy: undefined });
} else if (v === 'enabled') {
updateSettings.mutate({
await patchModel(settings, {
proxy: {
type: 'enabled',
http: '',
@@ -32,7 +31,7 @@ export function SettingsProxy() {
},
});
} else {
updateSettings.mutate({ proxy: { type: 'disabled' } });
await patchModel(settings, { proxy: { type: 'disabled' } });
}
}}
options={[
@@ -49,10 +48,10 @@ export function SettingsProxy() {
label="HTTP"
placeholder="localhost:9090"
defaultValue={settings.proxy?.http}
onChange={(http) => {
onChange={async (http) => {
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
const auth = settings.proxy?.type === 'enabled' ? settings.proxy.auth : null;
updateSettings.mutate({ proxy: { type: 'enabled', http, https, auth } });
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
}}
/>
<PlainInput
@@ -60,10 +59,10 @@ export function SettingsProxy() {
label="HTTPS"
placeholder="localhost:9090"
defaultValue={settings.proxy?.https}
onChange={(https) => {
onChange={async (https) => {
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
const auth = settings.proxy?.type === 'enabled' ? settings.proxy.auth : null;
updateSettings.mutate({ proxy: { type: 'enabled', http, https, auth } });
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
}}
/>
</HStack>
@@ -71,11 +70,11 @@ export function SettingsProxy() {
<Checkbox
checked={settings.proxy.auth != null}
title="Enable authentication"
onChange={(enabled) => {
onChange={async (enabled) => {
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
const auth = enabled ? { user: '', password: '' } : null;
updateSettings.mutate({ proxy: { type: 'enabled', http, https, auth } });
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
}}
/>
@@ -87,13 +86,13 @@ export function SettingsProxy() {
label="User"
placeholder="myUser"
defaultValue={settings.proxy.auth.user}
onChange={(user) => {
onChange={async (user) => {
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
const password =
settings.proxy?.type === 'enabled' ? (settings.proxy.auth?.password ?? '') : '';
const auth = { user, password };
updateSettings.mutate({ proxy: { type: 'enabled', http, https, auth } });
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
}}
/>
<PlainInput
@@ -102,13 +101,13 @@ export function SettingsProxy() {
type="password"
placeholder="s3cretPassw0rd"
defaultValue={settings.proxy.auth.password}
onChange={(password) => {
onChange={async (password) => {
const https = settings.proxy?.type === 'enabled' ? settings.proxy.https : '';
const http = settings.proxy?.type === 'enabled' ? settings.proxy.http : '';
const user =
settings.proxy?.type === 'enabled' ? (settings.proxy.auth?.user ?? '') : '';
const auth = { user, password };
updateSettings.mutate({ proxy: { type: 'enabled', http, https, auth } });
await patchModel(settings, { proxy: { type: 'enabled', http, https, auth } });
}}
/>
</HStack>