From 231402a02ae2ca413c97701faa93de4cbb5282b8 Mon Sep 17 00:00:00 2001 From: Bob Date: Fri, 27 Dec 2024 01:02:12 +0100 Subject: [PATCH] Load contributions at set up --- client/src/dojo/setup.ts | 32 ++++++++++++++++++++++++++ client/src/ui/layouts/World.tsx | 40 ++++++++++++++++----------------- 2 files changed, 52 insertions(+), 20 deletions(-) diff --git a/client/src/dojo/setup.ts b/client/src/dojo/setup.ts index 0af269aaa..5e31740e2 100644 --- a/client/src/dojo/setup.ts +++ b/client/src/dojo/setup.ts @@ -146,6 +146,38 @@ export async function setup(config: DojoConfig & { state: AppStore }) { } // fetch all existing entities from torii + setLoading(LoadingStateKey.Hyperstructure, true); + await getEntities( + network.toriiClient, + { + Composite: { + operator: "Or", + clauses: [ + { + Keys: { + keys: [undefined, undefined], + pattern_matching: "FixedLen", + models: ["s0_eternum-Epoch", "s0_eternum-Progress"], + }, + }, + { + Keys: { + keys: [undefined, undefined, undefined], + pattern_matching: "FixedLen", + models: ["s0_eternum-Contribution"], + }, + }, + ], + }, + }, + network.contractComponents as any, + [], + [], + 40_000, + false, + ).finally(() => { + setLoading(LoadingStateKey.Hyperstructure, false); + }); setLoading(LoadingStateKey.SingleKey, true); await getEntities( diff --git a/client/src/ui/layouts/World.tsx b/client/src/ui/layouts/World.tsx index e23211191..3b5e24fef 100644 --- a/client/src/ui/layouts/World.tsx +++ b/client/src/ui/layouts/World.tsx @@ -231,26 +231,26 @@ export const World = ({ backgroundImage }: { backgroundImage: string }) => { fetch(); }, []); - useEffect(() => { - const fetch = async () => { - try { - setLoading(LoadingStateKey.Hyperstructure, true); - console.log("AddToSubscriptionStart - 4"); - await Promise.all([ - debouncedAddHyperstructureSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any, () => - setLoading(LoadingStateKey.Hyperstructure, false), - ), - ]); - } catch (error) { - console.error("Fetch failed", error); - } finally { - // Ensure loading states are reset even if there's an error - setLoading(LoadingStateKey.Hyperstructure, false); - } - }; - - fetch(); - }, []); + // useEffect(() => { + // const fetch = async () => { + // try { + // setLoading(LoadingStateKey.Hyperstructure, true); + // console.log("AddToSubscriptionStart - 4"); + // await Promise.all([ + // debouncedAddHyperstructureSubscription(dojo.network.toriiClient, dojo.network.contractComponents as any, () => + // setLoading(LoadingStateKey.Hyperstructure, false), + // ), + // ]); + // } catch (error) { + // console.error("Fetch failed", error); + // } finally { + // // Ensure loading states are reset even if there's an error + // setLoading(LoadingStateKey.Hyperstructure, false); + // } + // }; + + // fetch(); + // }, []); const openPopup = useUIStore((state) => state.openPopup); useEffect(() => {