Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
7b38f1f
Add click on canadianFlag + hours next to frenchFlag. add a current t…
foufie4 Mar 26, 2024
789d350
dropdown menu displayed when clicking on the canadian flag
foufie4 Mar 28, 2024
3a42491
click on canadian flag done but dropdown list display is not good
foufie4 Mar 29, 2024
b5df910
click on canadian flag done but dropdown list display is not good
foufie4 Mar 29, 2024
6791860
dropdown doesn't appear on click
foufie4 Apr 2, 2024
1444543
display of drop-down list to adjust, have to click on canadian flag t…
foufie4 Apr 3, 2024
36fece1
display of drop-down list to adjust
foufie4 Apr 4, 2024
0fe0db6
click on the Canadian flag to open the drop-down menu DONE
foufie4 Apr 5, 2024
9882218
click on the Canadian flag to open the drop-down menu DONE
foufie4 Apr 8, 2024
ad99da1
display of the flag corresponding to the time zone
foufie4 Apr 10, 2024
4d124eb
the user can select a time zone, the Canadian flag updates automatica…
foufie4 Apr 10, 2024
1f32a0a
add timezones manually. there are 11 timezones + different flags corr…
foufie4 Apr 11, 2024
a7acd26
corresponding flags and timezones automatically refresh when country …
foufie4 Apr 12, 2024
82234e8
Merge branch 'main' into TimeZoneClick
foufie4 Apr 15, 2024
e33b704
comment lines, correct errors. TimeZoneClick can be closed
foufie4 Apr 15, 2024
5350b5a
Merge branch 'main' into 107-add-cliquer-sur-le-drapeau-canadien-
mortifia Apr 15, 2024
a5bb410
Merge branch '107-add-cliquer-sur-le-drapeau-canadien-' into TimeZone…
foufie4 Apr 16, 2024
8e5eb55
Merge branch 'main' of https://github.com/Unitystation-fork/Unitystat…
foufie4 Apr 16, 2024
58d3d0a
Merge branch 'main' into TimeZoneClick
foufie4 Apr 16, 2024
bb698b0
correcting conflicts
foufie4 Apr 16, 2024
6b5f213
Merge branch 'TimeZoneClick' into 107-add-cliquer-sur-le-drapeau-cana…
foufie4 Apr 16, 2024
8d5307c
correcting conflicts
foufie4 Apr 16, 2024
afce7ec
mini correction
mortifia Apr 17, 2024
8b53989
Merge branch 'TimeZoneClick' into 107-add-cliquer-sur-le-drapeau-cana…
mortifia Apr 17, 2024
fe46a1e
Merge pull request #142 from Unitystation-fork/107-add-cliquer-sur-le…
mortifia Apr 17, 2024
d7a8d4f
Merge pull request #144 from Unitystation-fork/TimeZoneClick
mortifia Apr 17, 2024
90b34ea
correcting the style
foufie4 Apr 17, 2024
6c466fa
correcting the style
foufie4 Apr 17, 2024
067e952
Merge branch '107-add-cliquer-sur-le-drapeau-canadien-' of https://gi…
foufie4 Apr 17, 2024
35da79c
still have to correct some errors
foufie4 Apr 19, 2024
2f371d3
correcting error
foufie4 Apr 26, 2024
28f72fe
correcting error
foufie4 Apr 26, 2024
e34a5d2
still some little errors to correct, ticket 107 almost done, every ti…
foufie4 May 3, 2024
776c5d1
dropdown, timezone + flags done, N107 can be closed
foufie4 May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/img/flag-australia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-guadeloupe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-guyane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-martinique.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-mayotte.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-reunion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-russia.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-uk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/img/flag-usa.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
204 changes: 175 additions & 29 deletions components/Header.vue
Original file line number Diff line number Diff line change
@@ -1,55 +1,137 @@
<template>
<header>
<img
src="@/assets/img/305474881_500277108772915_4425958856109240367_n.jpg"
alt="twitch"
/>
<!-- Image of the Twitch logo, representing the brand or project. -->
<img src="@/assets/img/305474881_500277108772915_4425958856109240367_n.jpg" alt="twitch" />
<!-- Main heading welcoming users to the project. -->
<h1>Bienvenue sur le projet milestone !</h1>

<p>
<!-- Container for displaying flags and times corresponding to different timezones. -->
<p class="flag-container">
<!-- Static image showing the French flag. -->
<img class="flag" src="~/assets/img/flag-france.png" alt="french-flag" />
{{ frenchDate }}
<img
class="flag"
src="~/assets/img/flag-canada.png"
alt="canadian-flag"
/>
{{ canadianDate }}
<!-- Displays time in France's timezone, updated dynamically. -->
{{ frenchTime }}

<!-- Dropdown menu for selecting and displaying Canadian timezones and flags. -->
<div class="dropdown" @click="toggleCanadianDropdown">
<!-- Dynamic image sourced from a computed method, showing the selected flag. -->
<img class="flag" :src="getFlagUrl(selectedTimeZone.flagUrl)" :alt="selectedTimeZone.label" />
<span class="dropdown-indicator">&#9660;</span>
<!-- Displays time in the selected Canadian timezone. -->
{{ canadianTime }}

<!-- Client-only encapsulation to ensure this part is rendered client-side. -->
<client-only>
<!-- Dropdown menu showing when the flag is clicked, allows timezone selection. -->
<ul v-show="canadianDropdownOpen" class="dropdown-menu">
<!-- Iterates over a list of timezones, creating a list item for each. -->
<li v-for="timezone in timezones" :key="timezone.label" @click="selectTimeZone(timezone)">
{{ timezone.label }}
</li>
</ul>
</client-only>
</div>
</p>

<div class="btns" v-if="!jwtStore.jwt">
<!-- Buttons for user account actions, shown based on conditional logic. -->
<div class="btns" v-if="isCreateButtonVisible">
<!-- Link to account creation, opens in a new tab. -->
<a href="https://vu.fr/mGJw" target="_blank">
<button @click="hideCreateButton">Create account</button>
</a>
</div>

<!-- Login and logout buttons displayed based on user authentication status. -->
<div class="btns">
<button v-if="!jwtStore.jwt" @click="$emit('login'), hideCreateButton">Login</button>
<button v-if="jwtStore.jwt" @click="jwtStore.logout(), showCreateButton">Logout</button>
<!-- Shows login button if the user is not authenticated. -->
<button v-if="!jwtStore.jwt" @click="$emit('login')">Login</button>
<!-- Shows logout button if the user is authenticated. -->
<button v-if="jwtStore.jwt" @click="performLogout">Logout</button>
</div>
</header>
</template>

<!-- script UX and timezone -->
<script setup lang="ts">
import { useJwtStore } from "~/stores/jwt";
import { ref, onMounted, onUnmounted, computed } from 'vue';
import { useJwtStore } from '@/stores/jwt';
import { defineStore, storeToRefs } from 'pinia';

// Interface defining the structure for a timezone object.
interface Timezone {
label: string;
timezone: string;
flagUrl: string;
}

// Setup for JWT-based authentication store.
const jwtStore = useJwtStore();
const { jwt } = storeToRefs(jwtStore);

// Reactive state declarations.
const canadianDropdownOpen = ref(false);
const now = ref(new Date());

// Predefined list of timezones, each with a label, timezone string, and flag URL.
const timezones: Timezone[] = [
{ label: 'Canada', timezone: 'America/Toronto', flagUrl: "flag-canada.png" },
{ label: 'USA Ouest', timezone: 'America/Los_Angeles', flagUrl: "flag-usa.png" },
{ label: 'USA Centre', timezone: 'America/Chicago', flagUrl: "flag-usa.png" },
{ label: 'United Kingdom', timezone: 'Europe/London', flagUrl: "flag-uk.png" },
{ label: 'Russie', timezone: 'Europe/Moscow', flagUrl: "flag-russia.png" },
{ label: 'Australie', timezone: 'Australia/Sydney', flagUrl: "flag-australia.png" },
{ label: 'Guadeloupe', timezone: 'America/Guadeloupe', flagUrl: "flag-guadeloupe.png" },
{ label: 'Martinique', timezone: 'America/Martinique', flagUrl: "flag-martinique.png" },
{ label: 'Guyane', timezone: 'America/Cayenne', flagUrl: "flag-guyane.png" },
{ label: 'La Réunion', timezone: 'Indian/Reunion', flagUrl: "flag-reunion.png" },
];

// Reactive reference to the currently selected timezone, defaulting to the first in the list.
const selectedTimeZone = ref<Timezone>(timezones[0]);

// Interval identifier for time updates.
let intervalId: number;

// function to select a timezone and update the flag and time
const selectTimeZone = (timezone: Timezone) => {
selectedTimeZone.value = timezone; // this will change both the flag and the timezone
canadianDropdownOpen.value = false; // close the dropdown menu
};

// Toggles the visibility of the dropdown menu.
function toggleCanadianDropdown() {
canadianDropdownOpen.value = !canadianDropdownOpen.value;
}

// Returns the full URL for a given flag image path.
function getFlagUrl(path: string): string {
return new URL(`../assets/img/${path}`, import.meta.url).href;
}

let now = new Date();
// Computed properties for displaying times in specific timezones.
const canadianTime = computed(() => now.value.toLocaleTimeString('en-CA', { timeZone: selectedTimeZone.value.timezone, hour12: false }));
const frenchTime = computed(() => now.value.toLocaleTimeString('fr-FR', { timeZone: 'Europe/Paris', hour12: false }));

let frenchDate = now.toLocaleString("fr-FR", {
hour: "2-digit",
minute: "2-digit",
hour12: false,
timeZone: "Europe/Paris",
// Lifecycle hooks to set up and tear down a timer that updates the current time.
onMounted(() => {
intervalId = window.setInterval(() => {
now.value = new Date();
}, 1000);
});
let canadianDate = now.toLocaleString("fr-FR", {
hour: "2-digit",
minute: "2-digit",
hour12: false,
timeZone: "America/Toronto",
onUnmounted(() => {
window.clearInterval(intervalId);
});

const jwtStore = useJwtStore();
// UI control reference to manage the visibility of the create account button.
const isCreateButtonVisible = ref(true);
function hideCreateButton() {
isCreateButtonVisible.value = false;
}

// Direct usage of the jwtStore to handle user logout.
function performLogout() {
jwtStore.logout();
}
</script>

<style scoped>
Expand Down Expand Up @@ -86,6 +168,26 @@ img {
vertical-align: middle;
}

.hidden-select {
display: none;
}

.flag-container {
display: flex;
align-items: center;
gap: 10px;
}

.hidden-select {
display: none;
}

.flag-container {
display: flex;
align-items: center;
gap: 10px;
}

.flag {
height: 36px;
width: 36px;
Expand All @@ -94,7 +196,51 @@ img {
margin-bottom: 6px;
}

.flag-label {
cursor: pointer;
}

.flag-emoji {
font-size: 1.2em;
}

.dropdown {
position: relative;
cursor: pointer;
}

.dropdown-indicator {
user-select: none;
margin-left: 5px;
}

.dropdown-menu {
position: absolute;
top: calc(100% + 16px);
left: 13px;
background-color: rgb(102, 101, 210);
list-style: none;
padding: 0;
margin: 0;
box-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.13);
z-index: 1000;
max-height: 200px;
overflow-y: auto;
}

.dropdown-menu[style*="display: none;"] {
display: none;
}

.dropdown-menu li {
padding: 5px 10px;
}

.dropdown-menu li:hover {
background-color: #ffffff24;
}

.add-btn {
font-size: 1em;
}
</style>
</style>
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://v3.nuxtjs.org/api/configuration/nuxt.config
export default defineNuxtConfig({
export default({
ssr: true,
app: {
head: {
Expand Down
Loading