Skip to content

Commit

Permalink
✨ feat (App Frontend): Regional Groups Lookup for Chairs (#166)
Browse files Browse the repository at this point in the history
branch: 164-add-regional-groups-lookup-for-chairs
  • Loading branch information
Strehk authored May 12, 2024
1 parent 49f09ab commit 051cda4
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import React, { useContext } from "react";
import React, { useContext, useState } from "react";
import { ScrollPanel } from "primereact/scrollpanel";
import DashboardHeader from "@/components/dashboard/header";
import { useI18nContext } from "@/i18n/i18n-react";
Expand All @@ -17,19 +17,25 @@ import SetStatusWidget from "@/components/dashboard/chair/set_status";
import SpeakersListAddingPolicyWidget from "@/components/dashboard/chair/speakers_list_adding_policy";
import Button from "@/components/button";
import {
faArrowsRotate,
faEarth,
faMagnifyingGlass,
faPodium,
faPresentationScreen,
faRecycle,
} from "@fortawesome/pro-solid-svg-icons";
import ConfigWrapper from "@/components/dashboard/chair/config_wrapper";
import StateOfDebateWidget from "@/components/dashboard/chair/state_of_debate";
import { useSpeakersListMiniature } from "@/contexts/speakers_list_miniature";
import RegionalGroupsLookup from "@/components/dashboard/chair/regional_groups_lookup";

export default function ChairDashboardPage() {
const { LL } = useI18nContext();
const conferenceId = useContext(ConferenceIdContext);
const committeeId = useContext(CommitteeIdContext);

const [regionalGroupModalOpen, setRegionalGroupModalOpen] = useState(false);

const { toggleSpeakersListMiniature } = useSpeakersListMiniature();

return (
Expand Down Expand Up @@ -93,24 +99,36 @@ export default function ChairDashboardPage() {
title={LL.chairs.dashboard.configurations.regionalGroups.TITLE()}
description={LL.chairs.dashboard.configurations.regionalGroups.DESCRIPTION()}
>
<Button
faIcon={faEarth}
label={LL.chairs.dashboard.configurations.regionalGroups.BUTTON()}
onClick={() => {
window.open(
`/app/${conferenceId}/committee/${committeeId}/regional_groups`,
"_blank",
"noopener,noreferrer",
);
}}
className="w-full"
/>
<div className="flex gap-2 w-full">
<Button
faIcon={faMagnifyingGlass}
label={LL.chairs.dashboard.configurations.regionalGroups.BUTTON_LOOKUP()}
onClick={() => setRegionalGroupModalOpen(true)}
className="w-full"
/>
<Button
faIcon={faArrowsRotate}
label={LL.chairs.dashboard.configurations.regionalGroups.BUTTON_PRESENTATION()}
onClick={() => {
window.open(
`/app/${conferenceId}/committee/${committeeId}/regional_groups`,
"_blank",
"noopener,noreferrer",
);
}}
className="w-full"
/>
</div>
</ConfigWrapper>
</div>
</div>
</ScrollPanel>
</div>
</AgendaItemDataProvider>
<RegionalGroupsLookup
lookupVisible={regionalGroupModalOpen}
setLookupVisible={setRegionalGroupModalOpen}
/>
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export default function RegionalGroups() {
);
});

useEffect(() => {
const interval = setInterval(() => {
setCurrentGroupIndex((prev) =>
prev === Object.keys(groupNames).length * 2 - 1 ? 0 : prev + 1,
);
}, 5000);
return () => clearInterval(interval);
}, []);

const groupNames = {
africa: LL.chairs.dashboard.configurations.regionalGroups.AFRICA(),
asia: LL.chairs.dashboard.configurations.regionalGroups.ASIA(),
Expand All @@ -64,13 +73,22 @@ export default function RegionalGroups() {
}
};

function Group({
group,
groupName,
}: {
group: string;
groupName: string;
}) {
const getMapColor = (group: string) => {
switch (group) {
case "africa":
return "#FF0000";
case "asia":
return "#008800";
case "america":
return "#0000FF";
case "eastern_europe":
return "#FF8800";
case "western_europe":
return "#8800FF";
}
};

function Group({ group, groupName }: { group: string; groupName: string }) {
return (
<motion.div
className="p-10 bg-primary-950 rounded-lg flex flex-col items-center absolute top-6 left-6 bottom-6 right-6"
Expand All @@ -84,7 +102,7 @@ export default function RegionalGroups() {
<div className="flex flex-wrap gap-2 mt-10 max-h-[70vh] justify-center items-center">
{currentGroupIndex % 2 === 0 ? (
<WorldMap
color="blue"
color={getMapColor(group)}
size="responsive"
frame={false}
strokeOpacity={1}
Expand Down
126 changes: 126 additions & 0 deletions chase/frontend/components/dashboard/chair/regional_groups_lookup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import React, { useState, useEffect, useContext, useReducer } from "react";
import { useI18nContext } from "@/i18n/i18n-react";
import { useBackend } from "@/contexts/backend";
import { useBackendCall } from "@/hooks/useBackendCall";
import regionalGroups from "@/data/regional_groups.json";
import {
CommitteeIdContext,
ConferenceIdContext,
} from "@/contexts/committee_data";
import { alpha3ToAlpha2 } from "@/misc/countryCodeUtils";
import getCountryNameByCode from "@/misc/get_country_name_by_code";
import { NormalFlag } from "@/components/flag_templates";
import { Dialog } from "primereact/dialog";
import { InputText } from "primereact/inputtext";

export default function RegionalGroupsLookup({
lookupVisible,
setLookupVisible,
}: {
lookupVisible: boolean;
setLookupVisible: (visible: boolean) => void;
}) {
const { LL, locale } = useI18nContext();
const { backend } = useBackend();

const conferenceId = useContext(ConferenceIdContext);
const committeeId = useContext(CommitteeIdContext);

const [filter, setFilter] = useState("");

const [unfilteredPresentDelegations] = useBackendCall(
// TODO
backend
// biome-ignore lint/style/noNonNullAssertion:
.conference({ conferenceId: conferenceId! })
// biome-ignore lint/style/noNonNullAssertion:
.committee({ committeeId: committeeId! }).delegations.get,
false,
);

const presentDelegations = unfilteredPresentDelegations?.filter(
(delegation) =>
getCountryNameByCode(delegation.nation.alpha3Code, locale)
.toLowerCase()
.includes(filter.toLowerCase()),
);

const groupNames = {
africa: LL.chairs.dashboard.configurations.regionalGroups.AFRICA(),
asia: LL.chairs.dashboard.configurations.regionalGroups.ASIA(),
america: LL.chairs.dashboard.configurations.regionalGroups.LATIN_AMERICA(),
eastern_europe:
LL.chairs.dashboard.configurations.regionalGroups.EASTERN_EUROPE(),
western_europe:
LL.chairs.dashboard.configurations.regionalGroups.WESTERN_EUROPE(),
};

const checkInRegionalGroup = (alpha3Code: string, group) => {
try {
return regionalGroups[group].includes(alpha3ToAlpha2(alpha3Code));
} catch {
return false;
}
};

function Group({ group, groupName }: { group: string; groupName: string }) {
return (
<div
className="p-6 bg-primary-950 rounded-lg flex flex-col items-center"
key={group}
>
<h2 className="font-bold text-3xl">{groupName}</h2>
<div className="flex flex-wrap gap-2 mt-4 max-h-[70vh] justify-center items-center">
{presentDelegations
?.filter((delegation) =>
checkInRegionalGroup(delegation.nation.alpha3Code, group),
)
.sort((a, b) =>
getCountryNameByCode(a.nation.alpha3Code, locale).localeCompare(
getCountryNameByCode(b.nation.alpha3Code, locale),
),
)
.map((delegation) => (
<div
key={delegation.id}
className="bg-primary-900 rounded-lg p-2 flex gap-4 items-center"
>
<NormalFlag countryCode={delegation.nation.alpha3Code} />
<div className="text-md font-bold">
{getCountryNameByCode(delegation.nation.alpha3Code, locale)}
</div>
</div>
))}
</div>
</div>
);
}

return (
<Dialog
header={LL.chairs.dashboard.configurations.regionalGroups.TITLE()}
visible={lookupVisible}
onHide={() => setLookupVisible(false)}
style={{ width: "80vw" }}
dismissableMask
>
<InputText
placeholder={LL.chairs.dashboard.configurations.regionalGroups.FILTER()}
value={filter}
onChange={(e) => setFilter(e.target.value)}
className="w-full my-5"
/>
<div className="flex gap-2 w-full flex-col">
{Object.keys(groupNames)
.filter((group) =>
presentDelegations?.some((delegation) =>
checkInRegionalGroup(delegation.nation.alpha3Code, group),
),
)
.map((group) => (
<Group key={group} group={group} groupName={groupNames[group]} />
))}
</div>
</Dialog>
);
}
10 changes: 7 additions & 3 deletions chase/frontend/i18n/de/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ const de = {

configs: {
pressWebsiteTitle: "Presse Website",
pressWebsiteDescription: "Hier kannst du die URL der Pressewebsite konfigurieren.",
pressWebsiteDescription:
"Hier kannst du die URL der Pressewebsite konfigurieren.",
feedbackWebsiteTitle: "Feedback Website",
feedbackWebsiteDescription: "Hier kannst du die URL der Feedbackwebsite konfigurieren.",
feedbackWebsiteDescription:
"Hier kannst du die URL der Feedbackwebsite konfigurieren.",
successToast: "Einstellungen gespeichert",
},

Expand Down Expand Up @@ -556,7 +558,9 @@ const de = {
TITLE: "Regionalgruppen",
DESCRIPTION:
"Öffne eine Übersicht der Regionalgruppen und weise Delegationen zu.",
BUTTON: "Regionalgruppen Öffnen",
BUTTON_PRESENTATION: "Präsentations-Loop",
BUTTON_LOOKUP: "Regionalgruppen nachschlagen",
FILTER: "Filtern...",
AFRICA: "Afrika",
ASIA: "Asien and Ozeanien",
LATIN_AMERICA: "Lateinamerika und Karibik",
Expand Down
4 changes: 3 additions & 1 deletion chase/frontend/i18n/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,9 @@ const en = {
TITLE: "Regional Groups",
DESCRIPTION:
"Open the regional groups page to show the regional groups of the committee.",
BUTTON: "Open Regional Groups",
BUTTON_PRESENTATION: "Open in Presentation Mode",
BUTTON_LOOKUP: "Open Lookup",
FILTER: "Filter...",
AFRICA: "Africa",
ASIA: "Asia and Pacific",
LATIN_AMERICA: "Latin America and Caribbean",
Expand Down
24 changes: 20 additions & 4 deletions chase/frontend/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1554,9 +1554,17 @@ type RootTranslation = {
*/
DESCRIPTION: string
/**
* O​p​e​n​ ​R​e​g​i​o​n​a​l​ ​G​r​o​u​p​s
* O​p​e​n​ ​i​n​ ​P​r​e​s​e​n​t​a​t​i​o​n​ ​M​o​d​e
*/
BUTTON: string
BUTTON_PRESENTATION: string
/**
* O​p​e​n​ ​L​o​o​k​u​p
*/
BUTTON_LOOKUP: string
/**
* F​i​l​t​e​r​.​.​.
*/
FILTER: string
/**
* A​f​r​i​c​a
*/
Expand Down Expand Up @@ -3456,9 +3464,17 @@ export type TranslationFunctions = {
*/
DESCRIPTION: () => LocalizedString
/**
* Open Regional Groups
* Open in Presentation Mode
*/
BUTTON: () => LocalizedString
BUTTON_PRESENTATION: () => LocalizedString
/**
* Open Lookup
*/
BUTTON_LOOKUP: () => LocalizedString
/**
* Filter...
*/
FILTER: () => LocalizedString
/**
* Africa
*/
Expand Down

0 comments on commit 051cda4

Please sign in to comment.