mirror of
https://github.com/hexastack/hexabot
synced 2025-02-23 12:59:14 +00:00
fix: update useTabUuid hooks
This commit is contained in:
parent
09ec35f520
commit
50406af6c2
@ -6,25 +6,23 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useEffect, useRef } from "react";
|
import { useRef } from "react";
|
||||||
|
|
||||||
import { generateId } from "@/utils/generateId";
|
import { generateId } from "@/utils/generateId";
|
||||||
|
|
||||||
export const useTabUuid = (key: string = "tab_uuid") => {
|
const getOrCreateTabId = () => {
|
||||||
const tabUuidRef = useRef<string | null>(null);
|
let tabId = sessionStorage.getItem("tab_uuid");
|
||||||
|
|
||||||
useEffect(() => {
|
if (!tabId) {
|
||||||
const storedUuid = sessionStorage.getItem(key);
|
tabId = generateId();
|
||||||
|
sessionStorage.setItem("tab_uuid", tabId);
|
||||||
|
}
|
||||||
|
|
||||||
if (storedUuid) {
|
return tabId;
|
||||||
tabUuidRef.current = storedUuid;
|
};
|
||||||
} else {
|
|
||||||
const newUuid = generateId();
|
|
||||||
|
|
||||||
sessionStorage.setItem(key, newUuid);
|
export const useTabUuid = () => {
|
||||||
tabUuidRef.current = newUuid;
|
const tabUuidRef = useRef<string | null>(getOrCreateTabId());
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return tabUuidRef;
|
return tabUuidRef;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user