-
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.
- Loading branch information
Showing
9 changed files
with
129 additions
and
138 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,67 @@ | ||
import CollapsibleArchive from '@/_components/collapsible-archive'; | ||
import Empty from '@/_components/empty'; | ||
import SubjectList from '@/_components/subject-list'; | ||
import getCurrentUser from '@/_queries/get-current-user'; | ||
import listSubjects, { ListSubjectsData } from '@/_queries/list-subjects'; | ||
import InformationCircleIcon from '@heroicons/react/24/outline/InformationCircleIcon'; | ||
|
||
export const metadata = { title: 'Subjects' }; | ||
|
||
const Page = () => <SubjectList />; | ||
const Page = async () => { | ||
const [{ data: subjects }, user] = await Promise.all([ | ||
listSubjects(), | ||
getCurrentUser(), | ||
]); | ||
|
||
if (!subjects || !user) return null; | ||
|
||
const { | ||
archivedClientSubjects, | ||
archivedTeamSubjects, | ||
clientSubjects, | ||
teamSubjects, | ||
} = subjects.reduce( | ||
(acc, subject) => { | ||
if (subject.team_id === user.id) { | ||
if (subject.archived) acc.archivedTeamSubjects.push(subject); | ||
else acc.teamSubjects.push(subject); | ||
} else { | ||
if (subject.archived) acc.archivedClientSubjects.push(subject); | ||
else acc.clientSubjects.push(subject); | ||
} | ||
|
||
return acc; | ||
}, | ||
{ | ||
archivedClientSubjects: [] as NonNullable<ListSubjectsData>, | ||
archivedTeamSubjects: [] as NonNullable<ListSubjectsData>, | ||
clientSubjects: [] as NonNullable<ListSubjectsData>, | ||
teamSubjects: [] as NonNullable<ListSubjectsData>, | ||
}, | ||
); | ||
|
||
return ( | ||
<> | ||
{!clientSubjects.length && !teamSubjects.length && ( | ||
<Empty className="mx-4"> | ||
<InformationCircleIcon className="w-7" /> | ||
Subjects can be dogs, cats, humans or | ||
<br /> | ||
anything else you want to track. | ||
</Empty> | ||
)} | ||
<SubjectList | ||
clientSubjects={clientSubjects} | ||
teamSubjects={teamSubjects} | ||
/> | ||
<CollapsibleArchive> | ||
<SubjectList | ||
clientSubjects={archivedClientSubjects} | ||
teamSubjects={archivedTeamSubjects} | ||
/> | ||
</CollapsibleArchive> | ||
</> | ||
); | ||
}; | ||
|
||
export default Page; |
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
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,109 +1,75 @@ | ||
import Avatar from '@/_components/avatar'; | ||
import Button from '@/_components/button'; | ||
import Empty from '@/_components/empty'; | ||
import SubjectMenu from '@/_components/subject-menu'; | ||
import getCurrentUser from '@/_queries/get-current-user'; | ||
import listSubjects, { ListSubjectsData } from '@/_queries/list-subjects'; | ||
import { ListSubjectsData } from '@/_queries/list-subjects'; | ||
import ArrowRightIcon from '@heroicons/react/24/outline/ArrowRightIcon'; | ||
import EllipsisVerticalIcon from '@heroicons/react/24/outline/EllipsisVerticalIcon'; | ||
import InformationCircleIcon from '@heroicons/react/24/outline/InformationCircleIcon'; | ||
|
||
interface SubjectListProps { | ||
archived?: boolean; | ||
clientSubjects: NonNullable<ListSubjectsData>; | ||
teamSubjects: NonNullable<ListSubjectsData>; | ||
} | ||
|
||
const SubjectList = async ({ archived = false }: SubjectListProps) => { | ||
const [{ data: subjects }, user] = await Promise.all([ | ||
listSubjects({ archived }), | ||
getCurrentUser(), | ||
]); | ||
|
||
if (!subjects) return null; | ||
|
||
const { | ||
clientSubjects, | ||
teamSubjects, | ||
}: { | ||
clientSubjects: NonNullable<ListSubjectsData>; | ||
teamSubjects: NonNullable<ListSubjectsData>; | ||
} = subjects.reduce( | ||
(acc, subject) => { | ||
if (!!user && subject.team_id === user.id) acc.teamSubjects.push(subject); | ||
else acc.clientSubjects.push(subject); | ||
return acc; | ||
}, | ||
{ | ||
clientSubjects: [] as NonNullable<ListSubjectsData>, | ||
teamSubjects: [] as NonNullable<ListSubjectsData>, | ||
}, | ||
); | ||
|
||
return ( | ||
<> | ||
{!subjects.length && !archived && ( | ||
<Empty className="mx-4"> | ||
<InformationCircleIcon className="w-7" /> | ||
Subjects can be dogs, cats, humans or | ||
<br /> | ||
anything else you want to track. | ||
</Empty> | ||
)} | ||
{!!teamSubjects.length && ( | ||
<ul className="mx-4 rounded border border-alpha-1 bg-bg-2 py-1"> | ||
{teamSubjects.map((subject) => ( | ||
<li | ||
className="flex items-stretch hover:bg-alpha-1 active:bg-alpha-1" | ||
key={subject.id} | ||
const SubjectList = async ({ | ||
clientSubjects, | ||
teamSubjects, | ||
}: SubjectListProps) => ( | ||
<> | ||
{!!teamSubjects.length && ( | ||
<ul className="mx-4 rounded border border-alpha-1 bg-bg-2 py-1"> | ||
{teamSubjects.map((subject) => ( | ||
<li | ||
className="flex items-stretch hover:bg-alpha-1 active:bg-alpha-1" | ||
key={subject.id} | ||
> | ||
<Button | ||
className="m-0 w-full gap-4 px-4 py-3 pr-0 leading-snug" | ||
href={`/subjects/${subject.id}/events`} | ||
variant="link" | ||
> | ||
<Button | ||
className="m-0 w-full gap-4 px-4 py-3 pr-0 leading-snug" | ||
href={`/subjects/${subject.id}/events`} | ||
variant="link" | ||
> | ||
<Avatar | ||
className="-my-0.5" | ||
file={subject.image_uri} | ||
key={subject.id} | ||
id={subject.id} | ||
size="sm" | ||
/> | ||
{subject.name} | ||
</Button> | ||
<SubjectMenu contentClassName="-mt-12 mr-1.5" subject={subject}> | ||
<div className="group flex items-center justify-center px-2 text-fg-3 hover:text-fg-2 active:text-fg-2"> | ||
<div className="rounded-full p-2 group-hover:bg-alpha-1 group-active:bg-alpha-1"> | ||
<EllipsisVerticalIcon className="w-5" /> | ||
</div> | ||
<Avatar | ||
className="-my-0.5" | ||
file={subject.image_uri} | ||
key={subject.id} | ||
id={subject.id} | ||
size="sm" | ||
/> | ||
{subject.name} | ||
</Button> | ||
<SubjectMenu contentClassName="-mt-12 mr-1.5" subject={subject}> | ||
<div className="group flex items-center justify-center px-2 text-fg-3 hover:text-fg-2 active:text-fg-2"> | ||
<div className="rounded-full p-2 group-hover:bg-alpha-1 group-active:bg-alpha-1"> | ||
<EllipsisVerticalIcon className="w-5" /> | ||
</div> | ||
</SubjectMenu> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
{!!clientSubjects.length && ( | ||
<ul className="mx-4 rounded border border-alpha-1 bg-bg-2 py-1"> | ||
{clientSubjects.map((subject) => ( | ||
<li key={subject.id}> | ||
<Button | ||
className="m-0 w-full gap-6 px-4 py-3 leading-snug hover:bg-alpha-1 active:bg-alpha-1" | ||
href={`/subjects/${subject.id}/events`} | ||
variant="link" | ||
> | ||
<Avatar | ||
className="-my-0.5 -mr-2" | ||
file={subject.image_uri} | ||
id={subject.id} | ||
size="sm" | ||
/> | ||
{subject.name} | ||
<ArrowRightIcon className="ml-auto w-5 shrink-0" /> | ||
</Button> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</> | ||
); | ||
}; | ||
</div> | ||
</SubjectMenu> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
{!!clientSubjects.length && ( | ||
<ul className="mx-4 rounded border border-alpha-1 bg-bg-2 py-1"> | ||
{clientSubjects.map((subject) => ( | ||
<li key={subject.id}> | ||
<Button | ||
className="m-0 w-full gap-6 px-4 py-3 leading-snug hover:bg-alpha-1 active:bg-alpha-1" | ||
href={`/subjects/${subject.id}/events`} | ||
variant="link" | ||
> | ||
<Avatar | ||
className="-my-0.5 -mr-2" | ||
file={subject.image_uri} | ||
id={subject.id} | ||
size="sm" | ||
/> | ||
{subject.name} | ||
<ArrowRightIcon className="ml-auto w-5 shrink-0" /> | ||
</Button> | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</> | ||
); | ||
|
||
export default SubjectList; |
This file was deleted.
Oops, something went wrong.
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