Skip to content

Commit

Permalink
useObserveフックの変更を追加***
Browse files Browse the repository at this point in the history
  • Loading branch information
Jun-Murakami committed May 12, 2024
1 parent f6f8764 commit c70f3b9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/hooks/useObserve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const useObserve = () => {
const { syncDb,
checkAndSyncDb,
loadSettingsFromIdb,
loadQuickMemoFromIdb,
loadTreesListFromIdb,
saveItemsIdb,
saveTreesListIdb,
Expand All @@ -59,7 +58,7 @@ export const useObserve = () => {
await checkAndSyncDb();
await loadSettingsFromIdb();
await loadTreesListFromIdb();
await loadQuickMemoFromIdb();
await loadQuickMemoFromDb();
setIsLoading(false);
// ローカルストレージからitems_offlineとtreeName_offline、quick_memo_offlineを読み込む
const { value: itemsOffline } = await Preferences.get({ key: `items_offline` });
Expand Down Expand Up @@ -92,6 +91,7 @@ export const useObserve = () => {
const serverTimestamp = snapshot.val();
const currentLocalTimestamp = useAppStateStore.getState().localTimestamp;
if (serverTimestamp && serverTimestamp > currentLocalTimestamp) {
if (!isLoading) setIsLoading(true);
setLocalTimestamp(serverTimestamp);
const newTreesList = await loadTreesListFromDb(uid);
setTreesList(newTreesList);
Expand All @@ -101,6 +101,7 @@ export const useObserve = () => {
const treeIds = newTreesList.map((tree) => tree.id);
let treeUpdateCount = 0;
for (const treeId of treeIds) {
if (!isLoading) setIsLoading(true);
const treeRef = ref(getDatabase(), `trees/${treeId}`);
await get(treeRef).then(async (snapshot) => {
if (snapshot.exists()) {
Expand All @@ -113,6 +114,7 @@ export const useObserve = () => {
});
}
if (treeUpdateCount == 0) {
if (!isLoading) setIsLoading(true);
const timestampV2Ref = ref(getDatabase(), `users/${uid}/timestampV2`);
await get(timestampV2Ref).then(async (snapshot) => {
if (snapshot.exists()) {
Expand All @@ -125,6 +127,7 @@ export const useObserve = () => {
}
const currentTree = useTreeStateStore.getState().currentTree;
if (currentTree) {
if (!isLoading) setIsLoading(true);
setPrevCurrentTree(null);
await loadCurrentTreeData(currentTree);
}
Expand Down

0 comments on commit c70f3b9

Please sign in to comment.