From 91bfd1083156645ad6981a5e87d8e30e1f474e7c Mon Sep 17 00:00:00 2001 From: Denis Thiessen Date: Mon, 27 May 2024 16:50:29 +0200 Subject: [PATCH] fix: Participant number gets statically saved now. --- src/components/RandomIDComponent.jsx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/RandomIDComponent.jsx b/src/components/RandomIDComponent.jsx index 95d3dc8..f865024 100644 --- a/src/components/RandomIDComponent.jsx +++ b/src/components/RandomIDComponent.jsx @@ -1,15 +1,32 @@ import React from "react"; +import { createStore } from 'zustand/vanilla' +import { persist, createJSONStorage } from 'zustand/middleware' import { getTranslation } from "../core/i18n/I18NHandler"; var randomId = 0; +export const participantIdLogState = createStore( + persist( + () => ({ + participant_id: "" + }), + { + name: 'participant-id-storage', // name of the item in the storage (must be unique) + storage: createJSONStorage(() => sessionStorage), // (optional) by default, 'localStorage' is used + }, + ), + ) + +const { getState, setState } = participantIdLogState; + function RandomIDComponent() { randomId = Math.floor(Math.random() * 89999) + 10000; + setState({ participant_id: "" + randomId }) return (

Your ID:

{randomId}

); } export function getUserID() { - return randomId; + return getState().participant_id; } export default RandomIDComponent; \ No newline at end of file