-
Notifications
You must be signed in to change notification settings - Fork 24
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
38ee4c0
commit 0b8a390
Showing
23 changed files
with
592 additions
and
77 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,26 @@ | ||
import { IAttendee, useAuth } from "@context/Auth"; | ||
import { ROLES } from "@lib/user"; | ||
import Link from "next/link"; | ||
|
||
interface Mention { | ||
nickname: string; | ||
name: string; | ||
} | ||
|
||
export default function AttendeeMention({ attendee }: { attendee: Mention }) { | ||
const { user } = useAuth(); | ||
const isSelf = | ||
user && | ||
user.type === ROLES.ATTENDEE && | ||
(user as IAttendee).nickname === attendee.nickname; | ||
|
||
return ( | ||
<Link href={`/attendees/${attendee.nickname}`}> | ||
<span | ||
className={`font-ibold hover:underline ${isSelf ? "text-quinary" : ""}`} | ||
> | ||
{attendee.name} | ||
</span> | ||
</Link> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ReactElement, useEffect, useState } from "react"; | ||
|
||
export default function PaginatedSearch<Elem>({ | ||
limit, | ||
fetchElems, | ||
showElems, | ||
children | ||
} : { | ||
limit: number, | ||
fetchElems: (query: string, offset: number, limit: number) => Promise<Elem[]> | Elem[], | ||
showElems: (elems : Elem[]) => ReactElement | ||
children?: ReactElement | ||
}) { | ||
const [ query, updateQuery ] = useState<string>(""); | ||
const [ offset, updateOffset ] = useState<number>(0); | ||
const [ elems, updateElems ] = useState<Elem[]>([]); | ||
|
||
useEffect(() => { | ||
(async () => { | ||
const fetched = await fetchElems(query, offset, limit); | ||
updateElems(fetched); | ||
})(); | ||
}, [query, offset]); | ||
|
||
return ( | ||
<> | ||
{ /*TODO: search bar and pagination*/ } | ||
{ children } | ||
{ showElems(elems) } | ||
</> | ||
); | ||
} |
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,61 @@ | ||
import { FunctionComponent, Key, ReactNode, createElement } from "react"; | ||
|
||
export enum Align { | ||
Left, | ||
Center, | ||
Right | ||
} | ||
|
||
export function alignToCSS(align: Align): string { | ||
switch (+align) { | ||
case Align.Left: return "text-left justify-self-left"; | ||
case Align.Center: return "text-center justify-self-center"; | ||
case Align.Right: return "text-right justify-self-right"; | ||
} | ||
} | ||
|
||
export type TableColumnProps<T> = { | ||
key?: Key; | ||
header?: string; | ||
headerAlign?: Align; | ||
elemAlign?: Align; | ||
elemPadding?: number; | ||
colSpan?: number; | ||
getter?: (e: T) => ReactNode; | ||
}; | ||
|
||
type ResolvedTableColumnProps<T> = { | ||
key: Key; | ||
header: string; | ||
headerAlign: Align; | ||
elemAlign: Align; | ||
elemPadding: number; | ||
colSpan: number; | ||
getter: (e: T) => ReactNode; | ||
}; | ||
|
||
export function resolveProps<T>(props: TableColumnProps<T>): ResolvedTableColumnProps<T> { | ||
return { | ||
key: Math.random(), | ||
header: "", | ||
headerAlign: Align.Center, | ||
elemAlign: Align.Center, | ||
elemPadding: 0, | ||
colSpan: 1, | ||
getter: (x) => x as ReactNode, | ||
...props | ||
}; | ||
} | ||
|
||
export function printHeader<T>(props : TableColumnProps<T>) { | ||
return ( | ||
<div key={props.key} className={`col-span-${props.colSpan} ${alignToCSS(props.headerAlign)}`}> | ||
{ props.header } | ||
</div> | ||
); | ||
} | ||
|
||
|
||
export default function TableColumn<T>(props : TableColumnProps<T>) { | ||
return createElement<TableColumnProps<T>>(TableColumn<T>, props); | ||
} |
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,39 @@ | ||
import { Key, ReactElement } from "react"; | ||
import TableColumn, { Align, TableColumnProps, alignToCSS, printHeader, resolveProps } from "./TableColumn"; | ||
|
||
export { TableColumn, Align }; | ||
|
||
type TableProps<T> = { | ||
children: ReactElement<TableColumnProps<T>>[]; | ||
elems: T[]; | ||
elemKey?: (elem: T) => Key; | ||
}; | ||
|
||
export default function Table<T>({ children, elems, elemKey } : TableProps<T>) { | ||
const cols = children.map((c) => resolveProps(c.props)); | ||
const totalColSpan = cols.reduce((sum, c) => sum + c.colSpan, 0); | ||
const anyHasHeader = cols.reduce((or, c) => c.header || or, false); | ||
|
||
const printElem = (elem: T, isFirst: boolean, isLast: boolean) => { | ||
const border = isLast ? "" : "boprder-b-solid border-b-2"; | ||
const key = elemKey ? elemKey(elem) : Math.random(); | ||
|
||
return <div key={key} className={`w-full py-4 ${border} grid grid-cols-${totalColSpan} items-center`}> | ||
{ cols.map((c) => | ||
<div key={c.key} className={`col-span-${c.colSpan} ${alignToCSS(c.elemAlign)} px-${c.elemPadding}`}> | ||
{ c.getter(elem) } | ||
</div>) | ||
} | ||
</div>; | ||
} | ||
|
||
return <> | ||
{ | ||
anyHasHeader && | ||
<div className={`w-full py-4 select-none text-iregular font-iregular grid grid-cols-${totalColSpan} items-center`}> | ||
{ cols.map(printHeader) } | ||
</div> | ||
} | ||
{ elems.map((e, i) => printElem(e, i === 0, i === elems.length - 1)) } | ||
</>; | ||
} |
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,9 @@ | ||
export type { | ||
IBadge, | ||
IPrize, | ||
IRedeemable, | ||
IAbstractUser, | ||
IPublicAttendee, | ||
IAttendee, | ||
IStaff, | ||
ISponsor, | ||
|
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.