generated from nihalgonsalves/node-typescript-eslint-template
-
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
1 parent
331d899
commit 7a93bc2
Showing
9 changed files
with
269 additions
and
39 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
packages/backend/prisma/migrations/20231007200736_add_is_archived_to_sheets/migration.sql
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,3 @@ | ||
-- AlterTable | ||
ALTER TABLE "sheets" | ||
ADD COLUMN "is_archived" BOOLEAN NOT NULL DEFAULT false; |
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
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,34 +1,124 @@ | ||
import { AnimatePresence } from 'framer-motion'; | ||
import { motion } from 'framer-motion'; | ||
import { useMemo, useState } from 'react'; | ||
import { MdGroup, MdListAlt } from 'react-icons/md'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import type { SheetsResponse } from '@nihalgonsalves/expenses-shared/types/sheet'; | ||
|
||
import { collapse } from '../utils/framer'; | ||
import { clsxtw } from '../utils/utils'; | ||
|
||
import { Avatar } from './Avatar'; | ||
import { ExpandMoreButton } from './ExpandMoreButton'; | ||
|
||
export const SheetsList = ({ sheets }: { sheets: SheetsResponse }) => ( | ||
<div className="flex flex-col gap-4"> | ||
{sheets.length === 0 && <div className="alert">No sheets</div>} | ||
{sheets.map((sheet) => ( | ||
<div key={sheet.id} className="flex items-center gap-4 h-14"> | ||
<Link | ||
className="btn btn-ghost no-animation flex-grow justify-start gap-4 text-start text-xl normal-case text-primary" | ||
to={ | ||
sheet.type === 'PERSONAL' | ||
? `/sheets/${sheet.id}` | ||
: `/groups/${sheet.id}` | ||
} | ||
> | ||
{sheet.type === 'PERSONAL' ? <MdListAlt /> : <MdGroup />} | ||
{sheet.name} | ||
</Link> | ||
{sheet.type === 'GROUP' && ( | ||
<div className="avatar-group -space-x-6"> | ||
{sheet.participants.map((participant) => ( | ||
<Avatar key={participant.id} name={participant.name} /> | ||
const partitionSheets = (sheets: SheetsResponse) => { | ||
const personal: SheetsResponse = []; | ||
const group: SheetsResponse = []; | ||
const archived: SheetsResponse = []; | ||
|
||
for (const sheet of sheets) { | ||
if (sheet.isArchived) { | ||
archived.push(sheet); | ||
} else if (sheet.type === 'PERSONAL') { | ||
personal.push(sheet); | ||
} else { | ||
group.push(sheet); | ||
} | ||
} | ||
|
||
return { personal, group, archived }; | ||
}; | ||
|
||
const SheetItem = ({ sheet }: { sheet: SheetsResponse[0] }) => { | ||
const link = | ||
sheet.type === 'PERSONAL' ? `/sheets/${sheet.id}` : `/groups/${sheet.id}`; | ||
|
||
return ( | ||
<div key={sheet.id} className="flex items-center gap-4 h-14"> | ||
<Link | ||
className="btn btn-ghost no-animation flex-grow justify-start gap-4 text-start text-xl normal-case text-primary" | ||
to={link} | ||
> | ||
{sheet.type === 'PERSONAL' ? <MdListAlt /> : <MdGroup />} | ||
{sheet.name} | ||
</Link> | ||
{sheet.type === 'GROUP' && ( | ||
<div className="avatar-group -space-x-6"> | ||
{sheet.participants.map((participant) => ( | ||
<Avatar key={participant.id} name={participant.name} /> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export const SheetsList = ({ sheets }: { sheets: SheetsResponse }) => { | ||
const { personal, group, archived } = useMemo( | ||
() => partitionSheets(sheets), | ||
[sheets], | ||
); | ||
|
||
const [showArchived, setShowArchived] = useState(false); | ||
|
||
return sheets.length === 0 ? ( | ||
<div className="flex flex-col gap-4"> | ||
<div className="alert">No sheets</div> | ||
</div> | ||
) : ( | ||
<div className="flex flex-col md:grid md:grid-cols-2 gap-4"> | ||
<div className="flex flex-col flex-grow gap-4 card card-compact card-bordered"> | ||
<div className="card-body"> | ||
<h2 className="card-title">Personal Sheets</h2> | ||
{personal.map((sheet) => ( | ||
<SheetItem key={sheet.id} sheet={sheet} /> | ||
))} | ||
</div> | ||
</div> | ||
|
||
{group.length > 0 && ( | ||
<div className="flex flex-col flex-grow gap-4 card card-compact card-bordered"> | ||
<div className="card-body"> | ||
<h2 className="card-title">Group Sheets</h2> | ||
|
||
{group.map((sheet) => ( | ||
<SheetItem key={sheet.id} sheet={sheet} /> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
))} | ||
</div> | ||
); | ||
</div> | ||
)} | ||
|
||
{archived.length > 0 && ( | ||
<div | ||
className={clsxtw( | ||
'flex flex-col flex-grow gap-4 card card-compact card-bordered', | ||
showArchived ? '' : 'opacity-50', | ||
)} | ||
> | ||
<div className="card-body"> | ||
<h2 className="card-title flex justify-between"> | ||
Archived Sheets | ||
<ExpandMoreButton | ||
expand={showArchived} | ||
onClick={() => { | ||
setShowArchived((prev) => !prev); | ||
}} | ||
/> | ||
</h2> | ||
|
||
<AnimatePresence initial={false}> | ||
{showArchived && ( | ||
<motion.div {...collapse}> | ||
{archived.map((sheet) => ( | ||
<SheetItem key={sheet.id} sheet={sheet} /> | ||
))} | ||
</motion.div> | ||
)} | ||
</AnimatePresence> | ||
</div> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; |
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.