Skip to content

Commit

Permalink
ww: improve list picker
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Jul 14, 2024
1 parent 316de60 commit 1016115
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 110 deletions.
2 changes: 1 addition & 1 deletion apps/gnocchi/hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"typecheck": "tsc --build tsconfig.json"
},
"dependencies": {
"@a-type/ui": "^0.8.28",
"@a-type/ui": "^0.8.31",
"@a-type/utils": "^1.0.8",
"@tiptap/core": "^2.2.4",
"@tiptap/extension-document": "^2.2.4",
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 @@ -14,7 +14,7 @@
"typecheck": "tsc --build tsconfig.json"
},
"dependencies": {
"@a-type/ui": "^0.8.28",
"@a-type/ui": "^0.8.31",
"@a-type/utils": "^1.0.8",
"@biscuits/client": "workspace:*",
"@biscuits/error": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion apps/humding/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@a-type/ui": "0.8.28",
"@a-type/ui": "0.8.31",
"@a-type/utils": "1.1.3",
"@biscuits/client": "workspace:*",
"@humding.biscuits/verdant": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion apps/marginalia/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@a-type/ui": "0.8.28",
"@a-type/ui": "0.8.31",
"@a-type/utils": "1.1.0",
"@biscuits/client": "workspace:*",
"@marginalia.biscuits/verdant": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion apps/star-chart/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@a-type/ui": "0.8.28",
"@a-type/ui": "0.8.31",
"@a-type/utils": "1.1.2",
"@biscuits/client": "workspace:*",
"@react-spring/web": "^9.7.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/trip-tick/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@a-type/ui": "^0.8.28",
"@a-type/ui": "^0.8.31",
"@a-type/utils": "^1.0.6",
"@biscuits/client": "workspace:*",
"@radix-ui/react-progress": "^1.0.3",
Expand Down
2 changes: 1 addition & 1 deletion apps/wish-wash/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"@a-type/ui": "0.8.28",
"@a-type/ui": "0.8.31",
"@a-type/utils": "1.1.3",
"@biscuits/client": "workspace:*",
"@react-spring/web": "^9.7.3",
Expand Down
6 changes: 4 additions & 2 deletions apps/wish-wash/web/src/components/lists/CreateListButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ export function CreateListButton({

const canSync = useCanSync();

const [open, setOpen] = useState(false);

const createPublic = async () => {
const list = await client.lists.put({});
navigate(`/${list.get('id')}?listId=${list.get('id')}`);
setOpen(false);
};
const createPrivate = async () => {
const list = await client.lists.put(
Expand All @@ -37,10 +40,9 @@ export function CreateListButton({
},
);
navigate(`/${list.get('id')}?listId=${list.get('id')}`);
setOpen(false);
};

const [open, setOpen] = useState(false);

return (
<Dialog
open={open}
Expand Down
90 changes: 50 additions & 40 deletions apps/wish-wash/web/src/components/lists/ListPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { hooks } from '@/store.js';
import { Icon } from '@a-type/ui/components/icon';
import { HorizontalList } from '@a-type/ui/components/horizontalList';
import { assert } from '@a-type/utils';
import { useCanSync } from '@biscuits/client';
import { authorization } from '@wish-wash.biscuits/verdant';
import { useCanSync, useLocalStorage } from '@biscuits/client';
import { authorization, List } from '@wish-wash.biscuits/verdant';
import { Button } from '@a-type/ui/components/button';
import { Link } from '@verdant-web/react-router';
import { CreateListButton } from './CreateListButton.jsx';
import { useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { clsx } from '@a-type/ui';

export interface ListPickerProps {
Expand All @@ -16,32 +16,23 @@ export interface ListPickerProps {
}

export function ListPicker({ className, value, ...props }: ListPickerProps) {
const [open, setOpen] = useState(false);

const [open, setOpen] = useLocalStorage('list-picker-open', false);
return (
<div {...props} className={clsx('relative w-full mb-4', className)}>
<HorizontalList open={open} className="w-full min-w-0">
<HorizontalList
className="w-full min-w-0 rounded-lg"
open={open}
onOpenChange={setOpen}
>
<ListsPickerLists value={value} />
<CreateListButton
size="icon"
color="primary"
// className="sticky right-2 bottom-2"
color="default"
// className="sticky right-2 bottom-2 ml-auto"
>
<Icon name="plus" />
</CreateListButton>
</HorizontalList>
<Button
size="icon"
className="absolute top-100% -translate-y-1/4 right-2"
toggled={open}
toggleMode="state-only"
onClick={() => setOpen((o) => !o)}
>
<Icon
name="chevron"
className={clsx('transition-transform', open && 'rotate-180')}
/>
</Button>
</div>
);
}
Expand All @@ -50,32 +41,51 @@ function ListsPickerLists({ value }: { value: string }) {
const lists = hooks.useAllLists();

// sort by recently created, with current value first
const sorted = lists.sort((a, b) =>
a.get('id') === value
? -1
: b.get('id') === value
? 1
: a.get('createdAt') - b.get('createdAt'),
);
const sorted = lists.sort((a, b) => a.get('createdAt') - b.get('createdAt'));

return (
<>
{sorted.map((list) => (
<Button
size="small"
<ListPickerListButton
selected={value === list.get('id')}
list={list}
key={list.uid}
color={value === list.get('id') ? 'default' : 'ghost'}
asChild
className={clsx(
value === list.get('id') && 'sticky left-2 right-12 z-1',
)}
>
<Link to={`/${list.get('id')}`}>
<Icon name={list.isAuthorized ? 'lock' : 'add_person'} />{' '}
{list.get('name')}
</Link>
</Button>
/>
))}
</>
);
}

function ListPickerListButton({
list,
selected,
}: {
list: List;
selected: boolean;
}) {
const ref = useRef<HTMLButtonElement>(null);
useEffect(() => {
if (selected) {
ref.current?.scrollIntoView({
behavior: 'smooth',
inline: 'center',
block: 'center',
});
}
}, [selected]);

return (
<Button
size="small"
color={selected ? 'accent' : 'ghost'}
asChild
// className={clsx(selected && 'sticky left-2 right-12 z-1')}
ref={ref}
>
<Link to={`/${list.get('id')}`}>
<Icon name={list.isAuthorized ? 'lock' : 'add_person'} />{' '}
{list.get('name')}
</Link>
</Button>
);
}
2 changes: 1 addition & 1 deletion blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"astro": "astro"
},
"dependencies": {
"@a-type/ui": "^0.8.28",
"@a-type/ui": "^0.8.31",
"@astrojs/check": "^0.5.10",
"@astrojs/mdx": "^2.3.1",
"@astrojs/rss": "^4.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"vite-plugin-pwa": "0.19.2"
},
"devDependencies": {
"@a-type/ui": "^0.8.28",
"@a-type/ui": "^0.8.31",
"@types/react": "18.3.3",
"@unocss/transformer-variant-group": "^0.58.0",
"@verdant-web/react-router": "0.6.3",
Expand Down
Loading

0 comments on commit 1016115

Please sign in to comment.