frontend client for gemstone. decentralised workplace app

refactor: abstract more queries

serenity 15d47c4a e395aa5c

Changed files
+40 -18
src
+3 -9
src/components/Settings/LatticeInfo.tsx
···
import type { AtUri } from "@/lib/types/atproto";
import type { SystemsGmstnDevelopmentLattice } from "@/lib/types/lexicon/systems.gmstn.development.lattice";
import { useCurrentPalette } from "@/providers/ThemeProvider";
-
import { getOwnerInfoFromLattice } from "@/queries/get-owner-info-from-lattice";
-
import { useQuery } from "@tanstack/react-query";
+
import { useLatticeInfoQuery } from "@/queries/hooks/useLatticeInfoQuery";
import { BadgeCheck, X } from "lucide-react-native";
import { View } from "react-native";
···
};
}) => {
const latticeDomain = lattice.uri.rKey;
-
const { isLoading, data: latticeInfo } = useQuery({
-
queryKey: ["shardInfo", latticeDomain],
-
queryFn: async () => {
-
return await getOwnerInfoFromLattice(latticeDomain);
-
},
-
retry: 1,
-
});
+
const { useQuery } = useLatticeInfoQuery(latticeDomain);
+
const { isLoading, data: latticeInfo } = useQuery();
const { semantic } = useCurrentPalette();
return (
+3 -9
src/components/Settings/ShardInfo.tsx
···
import type { AtUri } from "@/lib/types/atproto";
import type { SystemsGmstnDevelopmentShard } from "@/lib/types/lexicon/systems.gmstn.development.shard";
import { useCurrentPalette } from "@/providers/ThemeProvider";
-
import { getOwnerInfoFromShard } from "@/queries/get-owner-info-from-shard";
-
import { useQuery } from "@tanstack/react-query";
+
import { useShardInfoQuery } from "@/queries/hooks/useShardInfoQuery";
import { BadgeCheck, X } from "lucide-react-native";
import { View } from "react-native";
···
};
}) => {
const shardDomain = shard.uri.rKey;
-
const { isLoading, data: shardInfo } = useQuery({
-
queryKey: ["shardInfo", shardDomain],
-
queryFn: async () => {
-
return await getOwnerInfoFromShard(shardDomain);
-
},
-
retry: 1,
-
});
+
const { useQuery } = useShardInfoQuery(shardDomain);
+
const { isLoading, data: shardInfo } = useQuery();
const { semantic } = useCurrentPalette();
return (
+17
src/queries/hooks/useLatticeInfoQuery.ts
···
+
import { getOwnerInfoFromLattice } from "@/queries/get-owner-info-from-lattice";
+
import { useQuery } from "@tanstack/react-query";
+
+
export const useLatticeInfoQuery = (latticeDomain: string) => {
+
const queryKey = ["latticeInfo", latticeDomain];
+
return {
+
queryKey,
+
useQuery: () =>
+
useQuery({
+
queryKey,
+
queryFn: async () => {
+
return await getOwnerInfoFromLattice(latticeDomain);
+
},
+
retry: 1,
+
}),
+
};
+
};
+17
src/queries/hooks/useShardInfoQuery.ts
···
+
import { getOwnerInfoFromShard } from "@/queries/get-owner-info-from-shard";
+
import { useQuery } from "@tanstack/react-query";
+
+
export const useShardInfoQuery = (shardDomain: string) => {
+
const queryKey = ["shardInfo", shardDomain];
+
return {
+
queryKey,
+
useQuery: () =>
+
useQuery({
+
queryKey,
+
queryFn: async () => {
+
return await getOwnerInfoFromShard(shardDomain);
+
},
+
retry: 1,
+
}),
+
};
+
};