diff --git a/customtypes/section/index.json b/customtypes/section/index.json new file mode 100644 index 0000000..9290728 --- /dev/null +++ b/customtypes/section/index.json @@ -0,0 +1,38 @@ +{ + "format": "custom", + "id": "section", + "label": "Section", + "repeatable": true, + "status": true, + "json": { + "Main": { + "uid": { + "config": { + "label": "UID" + }, + "type": "UID" + }, + "name": { + "type": "Text", + "config": { + "label": "Name", + "placeholder": "" + } + }, + "short_name": { + "type": "Text", + "config": { + "label": "Short Name", + "placeholder": "" + } + }, + "color": { + "type": "Color", + "config": { + "label": "Color", + "placeholder": "" + } + } + } + } +} diff --git a/customtypes/team_members/index.json b/customtypes/team_members/index.json index f0ab6af..c5bafc2 100644 --- a/customtypes/team_members/index.json +++ b/customtypes/team_members/index.json @@ -26,20 +26,6 @@ "placeholder": "" } }, - "section": { - "type": "Select", - "config": { - "label": "Section", - "placeholder": "", - "options": [ - "TUDSaT Board", - "RAPID - Rocket Team", - "TRACE - CubeSat Team", - "TUDSaT PR" - ], - "default_value": "TUDSaT Board" - } - }, "highlight": { "type": "Boolean", "config": { @@ -56,6 +42,14 @@ "constraint": {}, "thumbnails": [] } + }, + "section": { + "type": "Link", + "config": { + "label": "Section", + "select": "document", + "customtypes": ["section"] + } } } } diff --git a/prismicio-types.d.ts b/prismicio-types.d.ts index d5136c1..70eb528 100644 --- a/prismicio-types.d.ts +++ b/prismicio-types.d.ts @@ -265,6 +265,60 @@ interface PageDocumentData { export type PageDocument = prismic.PrismicDocumentWithUID, "page", Lang>; +/** + * Content for Section documents + */ +interface SectionDocumentData { + /** + * Name field in *Section* + * + * - **Field Type**: Text + * - **Placeholder**: *None* + * - **API ID Path**: section.name + * - **Tab**: Main + * - **Documentation**: https://prismic.io/docs/field#key-text + */ + name: prismic.KeyTextField; + + /** + * Short Name field in *Section* + * + * - **Field Type**: Text + * - **Placeholder**: *None* + * - **API ID Path**: section.short_name + * - **Tab**: Main + * - **Documentation**: https://prismic.io/docs/field#key-text + */ + short_name: prismic.KeyTextField; + + /** + * Color field in *Section* + * + * - **Field Type**: Color + * - **Placeholder**: *None* + * - **API ID Path**: section.color + * - **Tab**: Main + * - **Documentation**: https://prismic.io/docs/field#color + */ + color: prismic.ColorField; +} + +/** + * Section document from Prismic + * + * - **API ID**: `section` + * - **Repeatable**: `true` + * - **Documentation**: https://prismic.io/docs/custom-types + * + * @typeParam Lang - Language API ID of the document. + */ +export type SectionDocument = + prismic.PrismicDocumentWithUID< + Simplify, + "section", + Lang + >; + /** * Item in *Settings → Socials* */ @@ -441,23 +495,6 @@ export interface TeamMembersDocumentDataTeamMembersItem { */ position: prismic.KeyTextField; - /** - * Section field in *Team Members → Team Members* - * - * - **Field Type**: Select - * - **Placeholder**: *None* - * - **Default Value**: TUDSaT Board - * - **API ID Path**: team_members.team_members[].section - * - **Documentation**: https://prismic.io/docs/field#select - */ - section: prismic.SelectField< - | "TUDSaT Board" - | "RAPID - Rocket Team" - | "TRACE - CubeSat Team" - | "TUDSaT PR", - "filled" - >; - /** * Highlight field in *Team Members → Team Members* * @@ -478,6 +515,16 @@ export interface TeamMembersDocumentDataTeamMembersItem { * - **Documentation**: https://prismic.io/docs/field#image */ image: prismic.ImageField; + + /** + * Section field in *Team Members → Team Members* + * + * - **Field Type**: Content Relationship + * - **Placeholder**: *None* + * - **API ID Path**: team_members.team_members[].section + * - **Documentation**: https://prismic.io/docs/field#link-content-relationship + */ + section: prismic.ContentRelationshipField<"section">; } /** @@ -519,6 +566,7 @@ export type AllDocumentTypes = | HeaderDocument | HomeDocument | PageDocument + | SectionDocument | SettingsDocument | SponsorsDocument | TeamMembersDocument; @@ -1714,6 +1762,8 @@ declare module "@prismicio/client" { PageDocument, PageDocumentData, PageDocumentDataSlicesSlice, + SectionDocument, + SectionDocumentData, SettingsDocument, SettingsDocumentData, SettingsDocumentDataSocialsItem, diff --git a/src/components/ui/card.tsx b/src/components/ui/card.tsx index 03da485..9411b65 100644 --- a/src/components/ui/card.tsx +++ b/src/components/ui/card.tsx @@ -7,7 +7,7 @@ const Card = React.forwardRef; */ const TeamMembers = async ({ slice }: TeamMembersProps) => { const client = createClient(); - const teamMembers = await client.getSingle("team_members"); - const sections = [...new Set(teamMembers.data.team_members.map((member) => member.section))]; + const teamMembers = await client.getSingle("team_members", { + fetchLinks: ["section.name", "section.color"], + }); + const sections = await client.getAllByType("section"); return ( { > {slice.variation === "full" ? (
- {sections.map((section) => ( -
-

{section}

+ {sections.reverse().map((section) => ( +
+

{section.data.name}

{teamMembers.data.team_members - .filter((member) => member.section === section) + .filter( + (member) => + isFilledRelatedData(member.section, "section", "name") && + member.section.data.name === section.data.name, + ) .map((member) => ( - + ))}
@@ -55,7 +62,15 @@ const TeamMembers = async ({ slice }: TeamMembersProps) => { {teamMembers.data.team_members .filter((member) => member.highlight) .map((member) => ( - + ))}
@@ -66,9 +81,16 @@ const TeamMembers = async ({ slice }: TeamMembersProps) => { export default TeamMembers; -function TeamMemberCard({ member }: { member: Content.TeamMembersDocumentDataTeamMembersItem }) { +function TeamMemberCard({ + member, + color, +}: { member: Content.TeamMembersDocumentDataTeamMembersItem; color?: ColorField }) { return ( - + ); } + +function hexToRgba(hex: string, opacity: number): string { + const hexValue = hex.replace("#", ""); + const r = Number.parseInt(hexValue.substring(0, 2), 16); + const g = Number.parseInt(hexValue.substring(2, 4), 16); + const b = Number.parseInt(hexValue.substring(4, 6), 16); + return `rgba(${r}, ${g}, ${b}, ${opacity})`; +}