Skip to content

Commit

Permalink
upgrade verdant for private docs
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Jul 10, 2024
1 parent 8ef7829 commit 941cf66
Show file tree
Hide file tree
Showing 23 changed files with 398 additions and 426 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,5 @@ backups/
.DS_Store

*.bak

vite.config.ts.*
8 changes: 4 additions & 4 deletions apps/gnocchi/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"dependencies": {
"@0no-co/graphqlsp": "1.12.8",
"@biscuits/client": "workspace:*",
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "3.8.4",
"@verdant-web/cli": "^4.5.0",
"@verdant-web/common": "2.4.0",
"@verdant-web/react": "35.0.0",
"@verdant-web/store": "3.9.0",
"cuid": "^2.1.8",
"stopword": "^2.0.8"
},
Expand Down
2 changes: 1 addition & 1 deletion apps/gnocchi/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@use-gesture/react": "^10.2.24",
"@vercel/analytics": "^0.1.6",
"@verdant-web/react-router": "^0.6.3",
"@verdant-web/store": "^3.8.4",
"@verdant-web/store": "^3.9.0",
"@zip.js/zip.js": "^2.7.6",
"classnames": "^2.3.2",
"convert-units": "^3.0.0-beta.4",
Expand Down
14 changes: 13 additions & 1 deletion apps/gnocchi/web/src/stores/groceries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,19 @@ export function createClientDescriptor(options: { namespace: string }) {
namespace: options.namespace,
log:
import.meta.env.DEV || DEBUG
? (...args: any[]) => console.debug('🌿', ...args)
? (level, ...args: any[]) => {
if (level === 'debug') {
if (DEBUG) {
console.debug('🌿', ...args);
}
} else if (level === 'error' || level === 'critical') {
console.error('🌿', ...args);
} else if (level === 'warn') {
console.warn('🌿', ...args);
} else {
console.log('🌿', ...args);
}
}
: undefined,
EXPERIMENTAL_weakRefs: true,
});
Expand Down
8 changes: 4 additions & 4 deletions apps/humding/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"react": "18.3.1"
},
"dependencies": {
"@verdant-web/cli": "4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "^3.8.4"
"@verdant-web/cli": "4.5.0",
"@verdant-web/common": "2.4.0",
"@verdant-web/react": "35.0.0",
"@verdant-web/store": "^3.9.0"
}
}
8 changes: 4 additions & 4 deletions apps/marginalia/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"react": "18.3.1"
},
"dependencies": {
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "^2.3.4",
"@verdant-web/react": "^34.0.1",
"@verdant-web/store": "^3.8.4",
"@verdant-web/cli": "^4.5.0",
"@verdant-web/common": "^2.4.0",
"@verdant-web/react": "^35.0.0",
"@verdant-web/store": "^3.9.0",
"cuid": "^2.1.8"
}
}
8 changes: 4 additions & 4 deletions apps/star-chart/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"react": "18.3.1"
},
"dependencies": {
"@verdant-web/cli": "4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "3.8.4"
"@verdant-web/cli": "4.5.0",
"@verdant-web/common": "2.4.0",
"@verdant-web/react": "35.0.0",
"@verdant-web/store": "3.9.0"
}
}
8 changes: 4 additions & 4 deletions apps/trip-tick/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"react": "18.3.1"
},
"dependencies": {
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "2.3.4",
"@verdant-web/react": "34.0.1",
"@verdant-web/store": "3.8.4",
"@verdant-web/cli": "^4.5.0",
"@verdant-web/common": "2.4.0",
"@verdant-web/react": "35.0.0",
"@verdant-web/store": "3.9.0",
"cuid": "^2.1.8"
}
}
4 changes: 2 additions & 2 deletions apps/trip-tick/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@tanstack/react-query": "^4.24.10",
"@trip-tick.biscuits/verdant": "workspace:*",
"@unocss/transformer-variant-group": "^0.54.1",
"@verdant-web/react": "^34.0.1",
"@verdant-web/react": "^35.0.0",
"@verdant-web/react-router": "^0.6.3",
"@verdant-web/store": "^3.8.4",
"@verdant-web/store": "^3.9.0",
"classnames": "^2.3.2",
"date-fns": "^2.30.0",
"downshift": "^7.0.1",
Expand Down
8 changes: 4 additions & 4 deletions apps/wish-wash/verdant/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"react": "18.3.1"
},
"dependencies": {
"@verdant-web/cli": "^4.4.1",
"@verdant-web/common": "^2.3.4",
"@verdant-web/react": "^34.0.1",
"@verdant-web/store": "^3.8.4"
"@verdant-web/cli": "4.5.0",
"@verdant-web/common": "2.4.0",
"@verdant-web/react": "35.0.0",
"@verdant-web/store": "3.9.0"
}
}
21 changes: 8 additions & 13 deletions apps/wish-wash/web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { clientDescriptor, hooks } from '@/store.js';
import { ErrorBoundary } from '@a-type/ui/components/errorBoundary';
import { Provider as UIProvider } from '@a-type/ui/components/provider';
import { H1, P } from '@a-type/ui/components/typography';
import { Provider, ReloadButton } from '@biscuits/client';
import { Provider, ReloadButton, useCanSync } from '@biscuits/client';
import { ReactNode, Suspense } from 'react';
import { privateClientDescriptor, privateHooks } from './privateStore.js';

export interface AppProps {}

Expand All @@ -14,26 +13,22 @@ export function App({}: AppProps) {
<ErrorBoundary fallback={<ErrorFallback />}>
<UIProvider toastContainerClassName="mb-10 sm:mb-0">
<Suspense>
<VerdantProvider>
<Provider
appId="wish-wash"
storeDescriptor={clientDescriptor as any}
>
<Provider appId="wish-wash" storeDescriptor={clientDescriptor as any}>
<VerdantProvider>
<Pages />
</Provider>
</VerdantProvider>
</VerdantProvider>
</Provider>
</Suspense>
</UIProvider>
</ErrorBoundary>
);
}

function VerdantProvider({ children }: { children: ReactNode }) {
const canSync = useCanSync();
return (
<hooks.Provider value={clientDescriptor}>
<privateHooks.Provider value={privateClientDescriptor}>
{children}
</privateHooks.Provider>
<hooks.Provider value={clientDescriptor} sync={canSync}>
{children}
</hooks.Provider>
);
}
Expand Down
27 changes: 21 additions & 6 deletions apps/wish-wash/web/src/components/lists/CreateItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,43 @@ import {
} from '@a-type/ui/components/forms';
import { useListContext } from './ListContext.jsx';
import { createdItemState } from './state.js';
import { hooks } from '@/store.js';
import { authorization } from '@wish-wash.biscuits/verdant';

export interface CreateItemProps {}

export function CreateItem({}: CreateItemProps) {
const { listId, client } = useListContext();
const { listId, list } = useListContext();
const client = hooks.useClient();

return (
<FormikForm
initialValues={{ description: '' }}
onSubmit={async (values, form) => {
const item = await client.items.put({
listId,
description: values.description,
});
const item = await client.items.put(
{
listId,
description: values.description,
},
{
access: list.isAuthorized
? authorization.private
: authorization.public,
},
);
// actually don't need to focus edit on this since we just
// named it...
// createdItemState.justCreatedId = item.get('id');
form.resetForm();
}}
className="!row items-center gap-2"
>
<TextField name="description" required className="flex-1" />
<TextField
name="description"
required
className="flex-1"
variant="primary"
/>
<SubmitButton>Add</SubmitButton>
</FormikForm>
);
Expand Down
4 changes: 2 additions & 2 deletions apps/wish-wash/web/src/components/lists/ListContext.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Client } from '@wish-wash.biscuits/verdant';
import { Client, List } from '@wish-wash.biscuits/verdant';
import { createContext, useContext } from 'react';

export interface ListContextProps {
listId: string;
client: Client;
list: List;
}

const listContext = createContext<ListContextProps | undefined>(undefined);
Expand Down
28 changes: 12 additions & 16 deletions apps/wish-wash/web/src/components/lists/ListMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { privateHooks } from '@/privateStore.js';
import { hooks } from '@/store.js';
import { ButtonProps, Button } from '@a-type/ui/components/button';
import { Icon } from '@a-type/ui/components/icon';
import { useCanSync } from '@biscuits/client';
import { useNavigate } from '@verdant-web/react-router';
import { MouseEvent } from 'react';
import {
DropdownMenu,
DropdownMenuContent,
Expand All @@ -13,24 +11,22 @@ import {
DropdownMenuItem,
DropdownMenuItemRightSlot,
} from '@a-type/ui/components/dropdownMenu';
import { authorization } from '@wish-wash.biscuits/verdant';

export interface ListMenuProps extends ButtonProps {}

export function ListMenu({ children, onClick, ...props }: ListMenuProps) {
export function ListMenu(props: ListMenuProps) {
const client = hooks.useClient();
const privateClient = privateHooks.useClient();

const navigate = useNavigate();
const createPublicList = async (ev: MouseEvent<any>) => {
const list = await client.lists.put({ name: 'New list' });
navigate(`/shared/${list.get('id')}?listId=${list.get('id')}`);
onClick?.(ev);
};

const createPrivateList = async (ev: MouseEvent<any>) => {
const list = await privateClient.lists.put({ name: 'New list' });
navigate(`/private/${list.get('id')}?listId=${list.get('id')}`);
onClick?.(ev);
const createList = async (isPrivate?: boolean) => {
const list = await client.lists.put(
{ name: 'New list' },
{
access: isPrivate ? authorization.private : authorization.public,
},
);
navigate(`/${list.get('id')}?listId=${list.get('id')}`);
};

const canSync = useCanSync();
Expand All @@ -45,14 +41,14 @@ export function ListMenu({ children, onClick, ...props }: ListMenuProps) {
<DropdownMenuContent>
<DropdownMenuArrow />
{canSync && (
<DropdownMenuItem onClick={createPublicList}>
<DropdownMenuItem onClick={() => createList(false)}>
New public list
<DropdownMenuItemRightSlot>
<Icon name="add_person" />
</DropdownMenuItemRightSlot>
</DropdownMenuItem>
)}
<DropdownMenuItem onClick={createPrivateList}>
<DropdownMenuItem onClick={() => createList(true)}>
New private list
<DropdownMenuItemRightSlot>
<Icon name="plus" />
Expand Down
Loading

0 comments on commit 941cf66

Please sign in to comment.