Fix URL not updated issue

This commit is contained in:
Arnaud 2024-10-08 16:05:59 +02:00
parent 6c96cbe295
commit e6d7d9e619
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
14 changed files with 54 additions and 24 deletions

View File

@ -38,7 +38,7 @@ export function AvailabilityReservations({
error,
} = useQuery({
queryFn: () =>
CodexSdk.marketplace
CodexSdk.marketplace()
.reservations(availability!.id)
.then((s) => Promises.rejectOnError(s)),
queryKey: ["reservations"],

View File

@ -27,18 +27,17 @@ export function useAvailabilityMutation(
...input
}: AvailabilityState) => {
const unit = totalSizeUnit === "gb" ? GB : TB;
const marketplace = CodexSdk.marketplace;
const time = Times.toSeconds(duration, durationUnit);
const fn: (
input: Omit<AvailabilityState, "totalSizeUnit" | "durationUnit">
) => Promise<unknown> = input.id
? (input) =>
marketplace
? (input) =>
CodexSdk.marketplace()
.updateAvailability({ ...input, id: input.id || "" })
.then((s) => Promises.rejectOnError(s))
: (input) =>
marketplace
: (input) =>
CodexSdk.marketplace()
.createAvailability(input)
.then((s) => Promises.rejectOnError(s));

View File

@ -6,7 +6,10 @@ import { CircleX } from "lucide-react";
export function Debug() {
const { data, isPending, isError, error } = useQuery({
queryFn: () => CodexSdk.debug.info().then((s) => Promises.rejectOnError(s)),
queryFn: () =>
CodexSdk.debug()
.info()
.then((s) => Promises.rejectOnError(s)),
queryKey: ["debug"],
// No need to retry because if the connection to the node

View File

@ -15,7 +15,9 @@ export function LogLevel() {
const [level, setLevel] = useState<CodexLogLevel>("DEBUG");
const { mutateAsync, isPending } = useMutation({
mutationFn: (level: CodexLogLevel) =>
CodexSdk.debug.setLogLevel(level).then((s) => Promises.rejectOnError(s)),
CodexSdk.debug()
.setLogLevel(level)
.then((s) => Promises.rejectOnError(s)),
onSuccess: () => {
setToast({
message: "The log level has been updated successfully.",

View File

@ -19,8 +19,11 @@ export function NodeIndicator() {
const { data, isError } = useQuery({
queryKey: ["spr"],
queryFn: async () =>
CodexSdk.node.spr().then((data) => Promises.rejectOnError(data, report)),
queryFn: async () => {
return CodexSdk.node()
.spr()
.then((data) => Promises.rejectOnError(data, report));
},
refetchInterval: 5000,
// No need to retry because we defined a refetch interval

View File

@ -14,7 +14,10 @@ const defaultSpace = {
export function NodeSpaceAllocation() {
const { data: space, isPending } = useQuery({
queryFn: () => CodexSdk.data.space().then((s) => Promises.rejectOnError(s)),
queryFn: () =>
CodexSdk.data()
.space()
.then((s) => Promises.rejectOnError(s)),
queryKey: ["space"],
initialData: defaultSpace,

View File

@ -95,7 +95,7 @@ export function StorageRequestFileChooser({
onSuccess={onSuccess}
editable={false}
onDeleteItem={onDelete}
codexData={CodexSdk.data}
codexData={CodexSdk.data()}
successMessage={"Success, the CID has been copied to the field on top."}
/>
</>

View File

@ -18,7 +18,7 @@ export function useStorageRequestMutation(
const { mutateAsync } = useMutation({
mutationFn: (input: CodexCreateStorageRequestInput) =>
CodexSdk.marketplace
CodexSdk.marketplace()
.createStorageRequest(input)
.then((s) => Promises.rejectOnError(s)),
onSuccess: async () => {

View File

@ -7,7 +7,9 @@ export function useData() {
const { data = { content: [] } satisfies CodexDataResponse } =
useQuery<CodexDataResponse>({
queryFn: () =>
CodexSdk.data.cids().then((res) => Promises.rejectOnError(res)),
CodexSdk.data()
.cids()
.then((res) => Promises.rejectOnError(res)),
queryKey: ["cids"],
initialData: { content: [] } satisfies CodexDataResponse,

View File

@ -179,6 +179,6 @@ class CodexMarketplaceMock extends CodexMarketplace {
export const CodexSdk = {
...Sdk,
marketplace: new CodexMarketplaceMock(import.meta.env.VITE_CODEX_API_URL),
data: new CodexDataMock(import.meta.env.VITE_CODEX_API_URL),
marketplace: () => new CodexMarketplaceMock(CodexSdk.url()),
data: () => new CodexDataMock(CodexSdk.url()),
};

View File

@ -21,7 +21,7 @@ export function Availabilities() {
// Error will be catched in ErrorBounday
const { data: availabilities = [], isPending } = useQuery({
queryFn: () =>
CodexSdk.marketplace
CodexSdk.marketplace()
.availabilities()
.then((s) => Promises.rejectOnError(s))
.then((res) => res.sort((a, b) => b.totalSize - a.totalSize)),
@ -47,7 +47,9 @@ export function Availabilities() {
// Error will be catched in ErrorBounday
const { data: space = defaultSpace } = useQuery({
queryFn: () =>
CodexSdk.data.space().then((s) => Promises.rejectOnError(s)),
CodexSdk.data()
.space()
.then((s) => Promises.rejectOnError(s)),
queryKey: ["space"],
initialData: defaultSpace,

View File

@ -18,6 +18,8 @@ function About() {
queryClient.invalidateQueries({ queryKey: ["cids"] });
};
console.info(CodexSdk.data);
return (
<>
<div className="dashboard">
@ -29,7 +31,11 @@ function About() {
/>
)}>
<Card title="Upload a file">
<Upload multiple codexData={CodexSdk.data} onSuccess={onSuccess} />
<Upload
multiple
codexData={CodexSdk.data()}
onSuccess={onSuccess}
/>
</Card>
</ErrorBoundary>

View File

@ -20,7 +20,9 @@ import { ErrorBoundary } from "@sentry/react";
const Purchases = () => {
const { data, isPending } = useQuery({
queryFn: () =>
CodexSdk.marketplace.purchases().then((s) => Promises.rejectOnError(s)),
CodexSdk.marketplace()
.purchases()
.then((s) => Promises.rejectOnError(s)),
queryKey: ["purchases"],
// No need to retry because if the connection to the node

View File

@ -23,11 +23,19 @@ export const CodexSdk = {
return WebStorage.set("codex-node-url", url);
},
debug: client.debug,
debug() {
return client.debug
},
data: client.data,
data() {
return client.data
},
node: client.node,
node() {
return client.node
},
marketplace: client.marketplace,
marketplace() {
return client.marketplace
},
};