diff --git a/src/components/App.tsx b/src/components/App.tsx index 981565d..23b7cbc 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -58,9 +58,10 @@ function App(props: AppProps) { window.toolDbWorker = toolDbWorkerRef.current; window.toolDbWorker.addEventListener("message", (e) => { + // console.warn("Worker REDUX_ACTION", action.type, action.arg); if (e.data.type === "REDUX_ACTION") { const action = e.data.arg; - // console.warn("Worker REDUX_ACTION", action.type, action.arg); + console.warn("Worker REDUX_ACTION", action.type, action.arg); reduxAction(dispatch, { type: action.type, arg: action.arg, diff --git a/src/info.json b/src/info.json index 1039041..2157be8 100644 --- a/src/info.json +++ b/src/info.json @@ -1 +1 @@ -{"version":"6.3.1","branch":"dev","timestamp":1694221792794} \ No newline at end of file +{"version":"6.3.1","branch":"dev","timestamp":1694805357905} \ No newline at end of file diff --git a/src/toolDb/upsertDbCards.ts b/src/toolDb/upsertDbCards.ts index 0258d9d..4e69cfa 100644 --- a/src/toolDb/upsertDbCards.ts +++ b/src/toolDb/upsertDbCards.ts @@ -4,8 +4,7 @@ import reduxAction from "../redux/reduxAction"; import store from "../redux/stores/rendererStore"; import { DbCardsData, defaultCardsData } from "../types/dbTypes"; import getLocalSetting from "../utils/getLocalSetting"; -import getUserNamespacedKey from "./getUserNamespacedKey"; -import { getLocalData, putData } from "./worker-wrapper"; +import { getData, putData } from "./worker-wrapper"; export default async function upsertDbCards(cards: Cards) { console.log("> Upsert cards", cards); @@ -13,38 +12,34 @@ export default async function upsertDbCards(cards: Cards) { const uuid = getLocalSetting("playerId") || "default"; const { dispatch } = store; - const { pubKey } = store.getState().renderer; + getData(`${uuid}-cards`, true).then((uuidData) => { + if (uuidData) { + const newData = { + cards, + prevCards: + new Date().getTime() - (uuidData as DbCardsData).updated > + 1000 * 60 * 24 + ? (uuidData as DbCardsData).cards + : (uuidData as DbCardsData).prevCards, + updated: new Date().getTime(), + }; - getLocalData(getUserNamespacedKey(pubKey, `${uuid}-cards`)).then( - (uuidData) => { - if (uuidData) { - const newData = { + reduxAction(dispatch, { + type: "SET_UUID_CARDS_DATA", + arg: { cards: newData, uuid }, + }); + + putData(`${uuid}-cards`, newData, true); + } else { + putData( + `${uuid}-cards`, + { + ...defaultCardsData, cards, - prevCards: - new Date().getTime() - (uuidData as DbCardsData).updated > - 1000 * 60 * 24 - ? (uuidData as DbCardsData).cards - : (uuidData as DbCardsData).prevCards, updated: new Date().getTime(), - }; - - reduxAction(dispatch, { - type: "SET_UUID_CARDS_DATA", - arg: { cards: newData, uuid }, - }); - - putData(`${uuid}-cards`, newData, true); - } else { - putData( - `${uuid}-cards`, - { - ...defaultCardsData, - cards, - updated: new Date().getTime(), - }, - true - ); - } + }, + true + ); } - ); + }); } diff --git a/src/toolDb/upsertDbInventory.ts b/src/toolDb/upsertDbInventory.ts index 848de53..b77246a 100644 --- a/src/toolDb/upsertDbInventory.ts +++ b/src/toolDb/upsertDbInventory.ts @@ -6,8 +6,7 @@ import { defaultInventoryData, } from "../types/dbTypes"; import getLocalSetting from "../utils/getLocalSetting"; -import getUserNamespacedKey from "./getUserNamespacedKey"; -import { getLocalData, putData } from "./worker-wrapper"; +import { getData, putData } from "./worker-wrapper"; export default async function upsertDbInventory( inventory: Partial @@ -17,33 +16,29 @@ export default async function upsertDbInventory( const uuid = getLocalSetting("playerId") || "default"; const { dispatch } = store; - const { pubKey } = store.getState().renderer; + getData(`${uuid}-inventory`, true).then((uuidData) => { + if (uuidData) { + const newData: DbInventoryData = { + ...(uuidData as DbInventoryData), + ...inventory, + updated: new Date().getTime(), + }; - getLocalData(getUserNamespacedKey(pubKey, `${uuid}-inventory`)).then( - (uuidData) => { - if (uuidData) { - const newData: DbInventoryData = { - ...(uuidData as DbInventoryData), - ...inventory, - updated: new Date().getTime(), - }; - - reduxAction(dispatch, { - type: "SET_UUID_INVENTORY_DATA", - arg: { inventory: newData, uuid }, - }); + reduxAction(dispatch, { + type: "SET_UUID_INVENTORY_DATA", + arg: { inventory: newData, uuid }, + }); - putData(`${uuid}-inventory`, newData, true); - } else { - putData( - `${uuid}-inventory`, - { - ...defaultInventoryData, - updated: new Date().getTime(), - }, - true - ); - } + putData(`${uuid}-inventory`, newData, true); + } else { + putData( + `${uuid}-inventory`, + { + ...defaultInventoryData, + updated: new Date().getTime(), + }, + true + ); } - ); + }); } diff --git a/src/toolDb/upsertDbRank.ts b/src/toolDb/upsertDbRank.ts index 255abb6..c5e5a83 100644 --- a/src/toolDb/upsertDbRank.ts +++ b/src/toolDb/upsertDbRank.ts @@ -7,8 +7,7 @@ import { defaultRankData, } from "../types/dbTypes"; import getLocalSetting from "../utils/getLocalSetting"; -import getUserNamespacedKey from "./getUserNamespacedKey"; -import { getLocalData, putData } from "./worker-wrapper"; +import { getData, putData } from "./worker-wrapper"; export default async function upsertDbRank(rank: Partial) { console.log("> Upsert rank", rank); @@ -18,42 +17,44 @@ export default async function upsertDbRank(rank: Partial) { const pubKey = getLocalSetting("pubkey"); - getLocalData(getUserNamespacedKey(pubKey, `${uuid}-rank`)).then( - (uuidData) => { - if (uuidData) { - const newData: DbRankData = { - ...(uuidData as DbRankData), - ...rank, - updated: new Date().getTime(), - }; + getData(`${uuid}-rank`, true).then((uuidData) => { + console.warn("uuidData", uuidData); + if (uuidData) { + const newData: DbRankData = { + ...(uuidData as DbRankData), + ...rank, + updated: new Date().getTime(), + }; + + console.warn("newData", newData); - reduxAction(dispatch, { - type: "SET_UUID_RANK_DATA", - arg: { rank: newData, uuid }, - }); + reduxAction(dispatch, { + type: "SET_UUID_RANK_DATA", + arg: { rank: newData, uuid }, + }); - putData(`${uuid}-rank`, newData, true); - putData(`rank-${pubKey}`, { - ...newData, - uuid, - pubKey: pubKey, - }); - } else { - putData( - `${uuid}-rank`, - { - ...defaultRankData, - updated: new Date().getTime(), - }, - true - ); - putData(`rank-${pubKey}`, { + putData(`${uuid}-rank`, newData, true); + putData(`rank-${pubKey}`, { + ...newData, + uuid, + pubKey: pubKey, + }); + } else { + console.warn("defaultRankData", defaultRankData); + putData( + `${uuid}-rank`, + { ...defaultRankData, updated: new Date().getTime(), - uuid, - pubKey: pubKey, - }); - } + }, + true + ); + putData(`rank-${pubKey}`, { + ...defaultRankData, + updated: new Date().getTime(), + uuid, + pubKey: pubKey, + }); } - ); + }); } diff --git a/src/toolDb/upsertDbuserdata.ts b/src/toolDb/upsertDbuserdata.ts index 0e798d7..33f4759 100644 --- a/src/toolDb/upsertDbuserdata.ts +++ b/src/toolDb/upsertDbuserdata.ts @@ -1,7 +1,7 @@ import { DbUserids } from "../types/dbTypes"; import { getData, putData } from "./worker-wrapper"; -export default async function upsertDbUserids(newData: DbUserids) { +export default async function upsertDbUserdata(newData: DbUserids) { console.log("> Upsert userdata", newData); getData("userids", true) diff --git a/tooldb-worker/getDataLocal.ts b/tooldb-worker/getDataLocal.ts index 011d8ff..92f2a59 100644 --- a/tooldb-worker/getDataLocal.ts +++ b/tooldb-worker/getDataLocal.ts @@ -4,7 +4,7 @@ export default function getDataLocal(msgId: string, key: string) { return new Promise((resolve) => { self.toolDb.store.get(key, (err, data) => { if (err) { - self.postMessage({ type: `${msgId}_ERR` }); + self.postMessage({ type: `${msgId}_ERR`, err }); } else if (data) { try { const json = JSON.parse(data); @@ -13,10 +13,10 @@ export default function getDataLocal(msgId: string, key: string) { resolve(json.v); } catch (_e) { - self.postMessage({ type: `${msgId}_ERR` }); + self.postMessage({ type: `${msgId}_ERR`, err: _e }); } } else { - self.postMessage({ type: `${msgId}_ERR` }); + self.postMessage({ type: `${msgId}_ERR`, err: "No data" }); } }); });