-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
180 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use server' | ||
|
||
import { getGroup } from '@/lib/api' | ||
|
||
export async function getGroupInfoAction(groupId: string) { | ||
'use server' | ||
return getGroup(groupId) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { getGroupInfoAction } from '@/app/groups/add-group-by-url-button-actions' | ||
import { saveRecentGroup } from '@/app/groups/recent-groups-helpers' | ||
import { Button } from '@/components/ui/button' | ||
import { Input } from '@/components/ui/input' | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
} from '@/components/ui/popover' | ||
import { useMediaQuery } from '@/lib/hooks' | ||
import { Loader2, Plus } from 'lucide-react' | ||
import { useState } from 'react' | ||
|
||
type Props = { | ||
reload: () => void | ||
} | ||
|
||
export function AddGroupByUrlButton({ reload }: Props) { | ||
const isDesktop = useMediaQuery('(min-width: 640px)') | ||
const [url, setUrl] = useState('') | ||
const [error, setError] = useState(false) | ||
const [open, setOpen] = useState(false) | ||
const [pending, setPending] = useState(false) | ||
|
||
return ( | ||
<Popover open={open} onOpenChange={setOpen}> | ||
<PopoverTrigger asChild> | ||
<Button variant="secondary"> | ||
{/* <Plus className="w-4 h-4 mr-2" /> */} | ||
<>Add by URL</> | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent | ||
align={isDesktop ? 'end' : 'start'} | ||
className="[&_p]:text-sm flex flex-col gap-3" | ||
> | ||
<h3 className="font-bold">Add a group by URL</h3> | ||
<p> | ||
If a group was shared with you, you can paste its URL here to add it | ||
to your list. | ||
</p> | ||
<form | ||
className="flex gap-2" | ||
onSubmit={async (event) => { | ||
event.preventDefault() | ||
const [, groupId] = | ||
url.match( | ||
new RegExp(`${window.location.origin}/groups/([^/]+)`), | ||
) ?? [] | ||
setPending(true) | ||
const group = groupId ? await getGroupInfoAction(groupId) : null | ||
setPending(false) | ||
if (!group) { | ||
setError(true) | ||
} else { | ||
saveRecentGroup({ id: group.id, name: group.name }) | ||
reload() | ||
setUrl('') | ||
setOpen(false) | ||
} | ||
}} | ||
> | ||
<Input | ||
type="url" | ||
required | ||
placeholder="https://spliit.app/..." | ||
className="flex-1 text-base" | ||
value={url} | ||
disabled={pending} | ||
onChange={(event) => { | ||
setUrl(event.target.value) | ||
setError(false) | ||
}} | ||
/> | ||
<Button size="icon" type="submit" disabled={pending}> | ||
{pending ? ( | ||
<Loader2 className="w-4 h-4 animate-spin" /> | ||
) : ( | ||
<Plus className="w-4 h-4" /> | ||
)} | ||
</Button> | ||
</form> | ||
{error && ( | ||
<p className="text-destructive"> | ||
Oops, we are not able to find the group from the URL you provided… | ||
</p> | ||
)} | ||
</PopoverContent> | ||
</Popover> | ||
) | ||
} |
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,29 +1,10 @@ | ||
import { RecentGroupList } from '@/app/groups/recent-group-list' | ||
import { Button } from '@/components/ui/button' | ||
import { Plus } from 'lucide-react' | ||
import { Metadata } from 'next' | ||
import Link from 'next/link' | ||
|
||
export const metadata: Metadata = { | ||
title: 'Recently visited groups', | ||
} | ||
|
||
export default async function GroupsPage() { | ||
return ( | ||
<> | ||
<div className="flex justify-between items-center gap-4"> | ||
<h1 className="font-bold text-2xl"> | ||
<Link href="/groups">My groups</Link> | ||
</h1> | ||
<Button asChild size="icon"> | ||
<Link href="/groups/create"> | ||
<Plus className="w-4 h-4" /> | ||
</Link> | ||
</Button> | ||
</div> | ||
<div> | ||
<RecentGroupList /> | ||
</div> | ||
</> | ||
) | ||
return <RecentGroupList /> | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use client' | ||
import { AddGroupByUrlButton } from '@/app/groups/add-group-by-url-button' | ||
import { RecentGroupList } from '@/app/groups/recent-group-list' | ||
import { Button } from '@/components/ui/button' | ||
import Link from 'next/link' | ||
|
||
export function RecentGroupsPage() { | ||
return ( | ||
<> | ||
<div className="flex flex-col sm:flex-row sm:items-center justify-between gap-2"> | ||
<h1 className="font-bold text-2xl flex-1"> | ||
<Link href="/groups">My groups</Link> | ||
</h1> | ||
<div className="flex gap-2"> | ||
<AddGroupByUrlButton reload={() => {}} /> | ||
<Button asChild> | ||
<Link href="/groups/create"> | ||
{/* <Plus className="w-4 h-4 mr-2" /> */} | ||
<>Create</> | ||
</Link> | ||
</Button> | ||
</div> | ||
</div> | ||
<div> | ||
<RecentGroupList /> | ||
</div> | ||
</> | ||
) | ||
} |