Browse Source

fix: Participant number gets statically saved now.

master
Denis Thiessen 6 months ago
parent
commit
91bfd10831
  1. 19
      src/components/RandomIDComponent.jsx

19
src/components/RandomIDComponent.jsx

@ -1,15 +1,32 @@
import React from "react"; import React from "react";
import { createStore } from 'zustand/vanilla'
import { persist, createJSONStorage } from 'zustand/middleware'
import { getTranslation } from "../core/i18n/I18NHandler"; import { getTranslation } from "../core/i18n/I18NHandler";
var randomId = 0; 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() { function RandomIDComponent() {
randomId = Math.floor(Math.random() * 89999) + 10000; randomId = Math.floor(Math.random() * 89999) + 10000;
setState({ participant_id: "" + randomId })
return (<div><h3>Your ID:</h3><p>{randomId}</p></div>); return (<div><h3>Your ID:</h3><p>{randomId}</p></div>);
} }
export function getUserID() { export function getUserID() {
return randomId;
return getState().participant_id;
} }
export default RandomIDComponent; export default RandomIDComponent;
Loading…
Cancel
Save