-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tos and privacy policy. more session refresh work
- Loading branch information
Showing
43 changed files
with
1,392 additions
and
1,214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
168 changes: 85 additions & 83 deletions
168
apps/gnocchi/web/src/components/sync/meetup/MeetupSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,102 @@ | ||
import { Icon } from '@/components/icons/Icon.jsx'; | ||
import { hooks } from '@/stores/groceries/index.js'; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectIcon, | ||
SelectItem, | ||
SelectLabel, | ||
SelectTrigger, | ||
SelectValue, | ||
UnstyledSelectTrigger, | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectIcon, | ||
SelectItem, | ||
SelectLabel, | ||
SelectTrigger, | ||
SelectValue, | ||
UnstyledSelectTrigger, | ||
} from '@a-type/ui/components/select'; | ||
import classNames from 'classnames'; | ||
import { ReactNode, useCallback, useEffect } from 'react'; | ||
|
||
export interface MeetupSelectProps { | ||
children?: (value: string | undefined) => ReactNode; | ||
id?: string; | ||
emptyLabel?: string; | ||
children?: (value: string | undefined) => ReactNode; | ||
id?: string; | ||
emptyLabel?: string; | ||
} | ||
|
||
export function MeetupSelect({ children, id, emptyLabel }: MeetupSelectProps) { | ||
const client = hooks.useClient(); | ||
const info = hooks.useCollaborationInfo('default'); | ||
hooks.useWatch(info); | ||
const meetup = info?.get('meetup') ?? null; | ||
hooks.useWatch(meetup); | ||
const client = hooks.useClient(); | ||
const info = hooks.useCollaborationInfo('default'); | ||
hooks.useWatch(info); | ||
const meetup = info?.get('meetup') ?? null; | ||
hooks.useWatch(meetup); | ||
|
||
useEffect(() => { | ||
if (!info) { | ||
client.collaborationInfo.put({}); | ||
} | ||
}, [info]); | ||
useEffect(() => { | ||
if (!info) { | ||
client.collaborationInfo.put({}); | ||
} | ||
}, [info, client]); | ||
|
||
let location = meetup?.get('location'); | ||
const createdAt = meetup?.get('createdAt') || 0; | ||
if (createdAt < Date.now() - 1000 * 60 * 60) { | ||
location = undefined; | ||
} | ||
let location = meetup?.get('location'); | ||
const createdAt = meetup?.get('createdAt') || 0; | ||
if (createdAt < Date.now() - 1000 * 60 * 60) { | ||
location = undefined; | ||
} | ||
|
||
const categories = hooks.useAllCategories(); | ||
const options = categories.map((cat) => cat.get('name')); | ||
const categories = hooks.useAllCategories(); | ||
const options = categories.map((cat) => cat.get('name')); | ||
|
||
const setMeetup = useCallback( | ||
(value: string) => { | ||
client | ||
.batch({ undoable: false }) | ||
.run(() => { | ||
info?.set('meetup', { | ||
location: value, | ||
}); | ||
}) | ||
.flush(); | ||
}, | ||
[info, client], | ||
); | ||
const clearMeetup = useCallback(() => { | ||
info?.set('meetup', undefined); | ||
}, [info]); | ||
const Trigger = children ? UnstyledSelectTrigger : SelectTrigger; | ||
const setMeetup = useCallback( | ||
(value: string) => { | ||
if (value === 'clear') { | ||
info?.set('meetup', undefined); | ||
} else { | ||
client | ||
.batch({ undoable: false }) | ||
.run(() => { | ||
info?.set('meetup', { | ||
location: value, | ||
}); | ||
}) | ||
.commit(); | ||
} | ||
}, | ||
[info, client], | ||
); | ||
|
||
return ( | ||
<Select value={location || ''} onValueChange={setMeetup}> | ||
<Trigger | ||
asChild={!!children} | ||
className={classNames( | ||
!children && 'py-3 px-6', | ||
!!location && 'bg-accent-wash color-accent-dark', | ||
)} | ||
id={id} | ||
> | ||
{children ? ( | ||
children(location) | ||
) : ( | ||
<> | ||
<Icon name="locate" /> | ||
<SelectValue /> | ||
<SelectIcon /> | ||
</> | ||
)} | ||
</Trigger> | ||
<SelectContent> | ||
<SelectItem value=""> | ||
{location ? 'Clear' : emptyLabel || 'Regroup'} | ||
</SelectItem> | ||
<SelectGroup> | ||
<SelectLabel>Choose a location</SelectLabel> | ||
<SelectItem value="Checkout Lanes">Checkout Lanes</SelectItem> | ||
<SelectItem value="Self Checkout">Self Checkout</SelectItem> | ||
{options.map((option) => ( | ||
<SelectItem value={option} key={option}> | ||
{option} | ||
</SelectItem> | ||
))} | ||
</SelectGroup> | ||
</SelectContent> | ||
</Select> | ||
); | ||
const Trigger = children ? UnstyledSelectTrigger : SelectTrigger; | ||
|
||
return ( | ||
<Select value={location || ''} onValueChange={setMeetup}> | ||
<Trigger | ||
asChild={!!children} | ||
className={classNames( | ||
!children && 'py-3 px-6', | ||
!!location && 'bg-accent-wash color-accent-dark', | ||
)} | ||
id={id} | ||
> | ||
{children ? ( | ||
children(location) | ||
) : ( | ||
<> | ||
<Icon name="locate" /> | ||
<SelectValue /> | ||
<SelectIcon /> | ||
</> | ||
)} | ||
</Trigger> | ||
<SelectContent> | ||
<SelectItem value="clear"> | ||
{location ? 'Clear' : emptyLabel || 'Regroup'} | ||
</SelectItem> | ||
<SelectGroup> | ||
<SelectLabel>Choose a location</SelectLabel> | ||
<SelectItem value="Checkout Lanes">Checkout Lanes</SelectItem> | ||
<SelectItem value="Self Checkout">Self Checkout</SelectItem> | ||
{options.map((option) => ( | ||
<SelectItem value={option} key={option}> | ||
{option} | ||
</SelectItem> | ||
))} | ||
</SelectGroup> | ||
</SelectContent> | ||
</Select> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.