Skip to content

Commit

Permalink
Load contributions at set up
Browse files Browse the repository at this point in the history
  • Loading branch information
bob0005 committed Dec 27, 2024
1 parent 707156b commit 231402a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 20 deletions.
32 changes: 32 additions & 0 deletions client/src/dojo/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
40 changes: 20 additions & 20 deletions client/src/ui/layouts/World.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 231402a

Please sign in to comment.