aboutsummaryrefslogtreecommitdiff
path: root/components/travel-advisory
diff options
context:
space:
mode:
authorAndrew Lee <alee14498@protonmail.com>2023-07-17 15:08:57 -0400
committerAndrew Lee <alee14498@protonmail.com>2023-07-17 15:08:57 -0400
commitddbe4fa61425f6a871a23238ce15a0929e201e6e (patch)
treec1d5c2a0674bcbf2cf79180445d8d26518b7009d /components/travel-advisory
parent8fbaca0d8ec9dc1323facb7f4c0029e32cfe5223 (diff)
downloadalure-website-ddbe4fa61425f6a871a23238ce15a0929e201e6e.tar.gz
alure-website-ddbe4fa61425f6a871a23238ce15a0929e201e6e.tar.bz2
alure-website-ddbe4fa61425f6a871a23238ce15a0929e201e6e.zip
Modularizing certain elements; Working information section
Diffstat (limited to 'components/travel-advisory')
-rw-r--r--components/travel-advisory/HistoryModal.js42
-rw-r--r--components/travel-advisory/ListCountries.js66
2 files changed, 108 insertions, 0 deletions
diff --git a/components/travel-advisory/HistoryModal.js b/components/travel-advisory/HistoryModal.js
new file mode 100644
index 0000000..ad9c039
--- /dev/null
+++ b/components/travel-advisory/HistoryModal.js
@@ -0,0 +1,42 @@
+const HistoryModal = ({ isVisible, onClose, countries, dangerLevel, history }) => {
+ if (!isVisible) return null;
+ const handleClose = (e) => {
+ if(e.target.id === 'wrapper') onClose();
+ }
+
+ let historyList;
+ if (history && history.length > 0) {
+ historyList = history.map((event, index) => {
+ return (
+ <li key={index}>{event}</li>
+ )
+ })
+ } else {
+ historyList = <li>Currently no diplomatic tensions in this country.</li>;
+ }
+
+ return (
+ <div id="wrapper" className="fixed inset-0 bg bg-opacity-25 backdrop-blur-sm flex justify-center items-center" onClick={handleClose}>
+ <div className="w-[600px]">
+ <div className="flex flex-col">
+ <div className="bg-zinc-800 p-5 rounded-lg border border-gray-700">
+ <div className="divide-y space-y-3">
+ <div>
+ <h1 className="font-medium text-3xl">{countries}</h1>
+ <h2 className="font-medium text-xl">{dangerLevel}</h2>
+ </div>
+ <div>
+ <h1 className="font-medium text-2xl pt-3">History</h1>
+ <ul>
+ {historyList}
+ </ul>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ )
+}
+
+export default HistoryModal;
diff --git a/components/travel-advisory/ListCountries.js b/components/travel-advisory/ListCountries.js
new file mode 100644
index 0000000..87e01fc
--- /dev/null
+++ b/components/travel-advisory/ListCountries.js
@@ -0,0 +1,66 @@
+"use client"
+import countriesData from '@/app/travel-advisory/countries.json' assert { type: 'json' };
+import HistoryModal from "@/components/travel-advisory/HistoryModal";
+import { useState } from "react";
+
+function getDangerLevel(danger) {
+ let dangerLevel;
+ switch (danger) {
+ case 0:
+ dangerLevel = "Take normal security precautions"
+ break;
+ case 1:
+ dangerLevel = "Exercise a high degree of caution"
+ break;
+ case 2:
+ dangerLevel = "Avoid non-essential travel"
+ break;
+ case 3:
+ dangerLevel = "Avoid all travel"
+ break;
+ default:
+ dangerLevel = "Seems like the danger level is broken!"
+ break;
+ }
+
+ return dangerLevel;
+}
+
+export default function Countries(){
+ // eslint-disable-next-line react-hooks/rules-of-hooks
+ const [showModal, setShowModal] = useState(false);
+ const [selectedCountry, setSelectedCountry] = useState(null);
+ const [selectedDangerLevel, setSelectedDangerLevel] = useState(null);
+ const [selectedCountryHistory, setSelectedCountryHistory] = useState(null);
+ const countries = countriesData.countries;
+
+ return countries.map((country) => {
+ let dangerLevel = getDangerLevel(country.danger);
+
+ const settlementsList = country.settlements.map((settlement) => {
+ return (
+ <div key={settlement.name}>
+ <h2 className="font-medium text-3xl">{settlement.name}</h2>
+ <h2 className="text-base">{getDangerLevel(settlement.danger)}</h2>
+ </div>
+ )
+ })
+
+ return (
+ <div key="countries" className="bg-center bg-no-repeat bg-[image:var(--image-url)] bg-gray-500 bg-blend-multiply" style={{'--image-url': `url(${country.image})`}} >
+ <div className="sm:px-40 px-10 py-10 space-y-3">
+ <h1 className="font-medium text-5xl">{country.name}</h1>
+ <h2 className="text-lg">{dangerLevel}</h2>
+ <div className="space-y-3">{settlementsList}</div>
+ <button className="transition duration-200 ease-in-out px-4 py-2 font-medium rounded-full bg-blue-600 hover:bg-blue-700 active:bg-blue-800" onClick={()=> {
+ setSelectedCountry(country.name);
+ setSelectedDangerLevel(dangerLevel)
+ setSelectedCountryHistory(country.history)
+ setShowModal(true)
+ }}>Information</button>
+ </div>
+ <HistoryModal isVisible={showModal} onClose={() => setShowModal(false)} countries={selectedCountry} dangerLevel={selectedDangerLevel} history={selectedCountryHistory} />
+ </div>
+ )
+ })
+}