From 2cdb05276fed5c913d7edc7c68813957973936cb Mon Sep 17 00:00:00 2001 From: Sami Mokaddem Date: Mon, 1 Jul 2024 08:13:08 +0200 Subject: [PATCH] chg: [front] Reorganised project --- src/App.vue | 6 +- src/TheDahboard.vue | 28 ++++ src/components/TheDahboard.vue | 257 --------------------------------- src/components/TheLiveLogs.vue | 122 ++++++++++++++++ src/components/TheScores.vue | 111 ++++++++++++++ src/socket.js | 35 ++++- 6 files changed, 291 insertions(+), 268 deletions(-) create mode 100644 src/TheDahboard.vue delete mode 100644 src/components/TheDahboard.vue create mode 100644 src/components/TheLiveLogs.vue create mode 100644 src/components/TheScores.vue diff --git a/src/App.vue b/src/App.vue index a154ec2..b8eed35 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,7 @@ + + diff --git a/src/components/TheDahboard.vue b/src/components/TheDahboard.vue deleted file mode 100644 index 2ad98d5..0000000 --- a/src/components/TheDahboard.vue +++ /dev/null @@ -1,257 +0,0 @@ - - - diff --git a/src/components/TheLiveLogs.vue b/src/components/TheLiveLogs.vue new file mode 100644 index 0000000..d47b212 --- /dev/null +++ b/src/components/TheLiveLogs.vue @@ -0,0 +1,122 @@ + + + \ No newline at end of file diff --git a/src/components/TheScores.vue b/src/components/TheScores.vue new file mode 100644 index 0000000..d98fb7b --- /dev/null +++ b/src/components/TheScores.vue @@ -0,0 +1,111 @@ + + + \ No newline at end of file diff --git a/src/socket.js b/src/socket.js index 64fa99a..9296114 100644 --- a/src/socket.js +++ b/src/socket.js @@ -1,28 +1,49 @@ -import { reactive } from "vue"; +import { reactive, computed } from "vue"; import { io } from "socket.io-client"; +// "undefined" means the URL will be computed from the `window.location` object +const URL = process.env.NODE_ENV === "production" ? undefined : "http://localhost:3000"; +const MAX_LIVE_LOG = 30 + const initial_state = { notificationEvents: [], notificationCounter: 0, notificationAPICounter: 0, + exercises: [], progresses: {}, } -export const state = reactive({ ...initial_state }); -export const connectionState = reactive({ +const state = reactive({ ...initial_state }); +const connectionState = reactive({ connected: false }) +export const exercises = computed(() => state.exercises) +export const progresses = computed(() => state.progresses) +export const notifications = computed(() => state.notificationEvents) +export const notificationCounter = computed(() => state.notificationCounter) +export const notificationAPICounter = computed(() => state.notificationAPICounter) +export const userCount = computed(() => Object.keys(state.progresses).length) +export const socketConnected = computed(() => connectionState.connected) + export function resetState() { Object.assign(state, initial_state); } -const MAX_LIVE_LOG = 30 +export function fullReload() { + socket.emit("get_exercises", (all_exercises) => { + state.exercises = all_exercises + }) + socket.emit("get_notifications", (all_notifications) => { + state.notificationEvents = all_notifications + }) + socket.emit("get_progress", (all_progress) => { + state.progresses = all_progress + }) +} -// "undefined" means the URL will be computed from the `window.location` object -const URL = process.env.NODE_ENV === "production" ? undefined : "http://localhost:3000"; -export const socket = io(URL, { +const socket = io(URL, { autoConnect: true });