Merge pull request #54 from codex-storage/releases/v0.0.6

Refs/heads/releases/v0.0.6
This commit is contained in:
Arnaud 2024-10-15 15:25:32 +02:00 committed by GitHub
commit beb10450b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 460 additions and 405 deletions

752
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
"type": "git", "type": "git",
"url": "https://github.com/codex-storage/codex-marketplace-ui" "url": "https://github.com/codex-storage/codex-marketplace-ui"
}, },
"version": "0.0.5", "version": "0.0.6",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite --host 127.0.0.1 --port 5173", "dev": "vite --host 127.0.0.1 --port 5173",
@ -24,7 +24,7 @@
"React" "React"
], ],
"dependencies": { "dependencies": {
"@codex-storage/marketplace-ui-components": "^0.0.18", "@codex-storage/marketplace-ui-components": "^0.0.20",
"@codex-storage/sdk-js": "^0.0.8", "@codex-storage/sdk-js": "^0.0.8",
"@sentry/browser": "^8.32.0", "@sentry/browser": "^8.32.0",
"@sentry/react": "^8.31.0", "@sentry/react": "^8.31.0",

View File

@ -1,4 +1,4 @@
import { useQueryClient } from "@tanstack/react-query"; import { useMutation, useQueryClient } from "@tanstack/react-query";
import { useState } from "react"; import { useState } from "react";
import { Button, Input, Toast } from "@codex-storage/marketplace-ui-components"; import { Button, Input, Toast } from "@codex-storage/marketplace-ui-components";
import { CodexSdk } from "../../sdk/codex"; import { CodexSdk } from "../../sdk/codex";
@ -7,6 +7,14 @@ export function CodexUrlSettings() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const [url, setUrl] = useState(CodexSdk.url); const [url, setUrl] = useState(CodexSdk.url);
const [toast, setToast] = useState({ time: 0, message: "" }); const [toast, setToast] = useState({ time: 0, message: "" });
const { mutateAsync } = useMutation({
mutationFn: (url: string) => CodexSdk.updateURL(url),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["spr"] });
setToast({ message: "Settings saved successfully.", time: Date.now() });
},
});
const onChange = (e: React.FormEvent<HTMLInputElement>) => { const onChange = (e: React.FormEvent<HTMLInputElement>) => {
const value = e.currentTarget.value; const value = e.currentTarget.value;
@ -15,12 +23,7 @@ export function CodexUrlSettings() {
} }
}; };
const onClick = () => { const onClick = () => mutateAsync(url);
CodexSdk.updateURL(url).then(() => {
queryClient.invalidateQueries();
setToast({ message: "Settigns saved successfully.", time: Date.now() });
});
};
return ( return (
<> <>

View File

@ -1,15 +1,15 @@
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { CodexSdk } from "../../sdk/codex"; import { CodexSdk } from "../../sdk/codex";
import { Placeholder, Spinner } from "@codex-storage/marketplace-ui-components";
import { Promises } from "../../utils/promises"; import { Promises } from "../../utils/promises";
import { CircleX } from "lucide-react"; import { Spinner } from "@codex-storage/marketplace-ui-components";
export function Debug() { export function Debug() {
const { data, isPending, isError, error } = useQuery({ const { data, isPending } = useQuery({
queryFn: () => queryFn: () =>
CodexSdk.debug() CodexSdk.debug()
.info() .info()
.then((s) => Promises.rejectOnError(s)), .then((s) => Promises.rejectOnError(s)),
queryKey: ["debug"], queryKey: ["debug"],
// No need to retry because if the connection to the node // No need to retry because if the connection to the node
@ -36,19 +36,10 @@ export function Debug() {
); );
} }
if (isError) {
return (
<Placeholder
Icon={<CircleX size={"4em"}></CircleX>}
title="Something went wrong"
message={error.message}></Placeholder>
);
}
return ( return (
<> <>
<h3>Debug</h3> <h3>Debug</h3>
<pre>{JSON.stringify(data, null, 2)}</pre> <pre key={Date.now()}>{JSON.stringify(data, null, 2)}</pre>
</> </>
); );
} }

View File

@ -5,10 +5,9 @@ import { CodexSdk } from "../../sdk/codex";
export function Download() { export function Download() {
const [cid, setCid] = useState(""); const [cid, setCid] = useState("");
console.info(cid);
const onDownload = () => { const onDownload = () => {
const url = CodexSdk.url() + "/api/codex/v1/data/"; const url = CodexSdk.url() + "/api/codex/v1/data/";
window.open(url + cid, "_target"); window.open(url + cid + "/network", "_target");
}; };
const onCidChange = (e: ChangeEvent<HTMLInputElement>) => const onCidChange = (e: ChangeEvent<HTMLInputElement>) =>

View File

@ -8,7 +8,6 @@ import {
import { Promises } from "../../utils/promises"; import { Promises } from "../../utils/promises";
const report = false; const report = false;
export let isCodexOnline: boolean | null = null;
export function NodeIndicator() { export function NodeIndicator() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
@ -41,13 +40,16 @@ export function NodeIndicator() {
gcTime: 0, gcTime: 0,
}); });
isCodexOnline = !isError && !!data; const isCodexOnline = !isError && !!data;
useEffect(() => { useEffect(() => {
queryClient.invalidateQueries({ queryClient.invalidateQueries({
type: "active", type: "active",
refetchType: "all", refetchType: "all",
}); });
// Dispatch an event in order to reset Sentry error boundary
document.dispatchEvent(new CustomEvent("codexinvalidatequeries"));
}, [queryClient, isCodexOnline]); }, [queryClient, isCodexOnline]);
return ( return (

View File

@ -3,6 +3,7 @@ import { PeerPin } from "./types";
import { countriesCoordinates } from "./countries"; import { countriesCoordinates } from "./countries";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import "./PeerCountryCell.css"; import "./PeerCountryCell.css";
import { useEffect } from "react";
export type Props = { export type Props = {
address: string; address: string;
@ -24,21 +25,12 @@ export function PeerCountryCell({ address, onPinAdd }: Props) {
return fetch(import.meta.env.VITE_GEO_IP_URL + "/" + ip) return fetch(import.meta.env.VITE_GEO_IP_URL + "/" + ip)
.then((res) => res.json()) .then((res) => res.json())
.then((json) => { .then((json) =>
const coordinate = countriesCoordinates.find( countriesCoordinates.find((c) => c.iso === json.country)
(c) => c.iso === json.country );
);
if (coordinate) {
onPinAdd({
lat: parseFloat(coordinate.lat),
lng: parseFloat(coordinate.lng),
});
}
return coordinate;
});
}, },
refetchOnMount: true,
queryKey: [address], queryKey: [address],
// Enable only when the address exists // Enable only when the address exists
@ -56,6 +48,15 @@ export function PeerCountryCell({ address, onPinAdd }: Props) {
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
}); });
useEffect(() => {
if (data) {
onPinAdd({
lat: parseFloat(data.lat),
lng: parseFloat(data.lng),
});
}
}, [data]);
return ( return (
<Cell> <Cell>
<div className="peerCountry"> <div className="peerCountry">

View File

@ -9,6 +9,8 @@ import { useCallback, useState } from "react";
import { PeerPin } from "../../components/Peers/types"; import { PeerPin } from "../../components/Peers/types";
import "./peers.css"; import "./peers.css";
import { CodexSdk } from "../../sdk/codex"; import { CodexSdk } from "../../sdk/codex";
import { ErrorBoundary } from "@sentry/react";
import { ErrorPlaceholder } from "../../components/ErrorPlaceholder/ErrorPlaceholder";
// This function accepts the same arguments as DottedMap in the example above. // This function accepts the same arguments as DottedMap in the example above.
const mapJsonString = getMapJSON({ height: 60, grid: "diagonal" }); const mapJsonString = getMapJSON({ height: 60, grid: "diagonal" });
@ -102,5 +104,12 @@ const Peers = () => {
}; };
export const Route = createFileRoute("/dashboard/peers")({ export const Route = createFileRoute("/dashboard/peers")({
component: Peers, component: () => (
<ErrorBoundary
fallback={({ error }) => (
<ErrorPlaceholder error={error} subtitle="Cannot retrieve the data." />
)}>
<Peers />
</ErrorBoundary>
),
}); });

View File

@ -5,6 +5,7 @@ import { Debug } from "../../components/Debug/Debug";
import { CodexUrlSettings } from "../../components/CodexUrllSettings/CodexUrlSettings"; import { CodexUrlSettings } from "../../components/CodexUrllSettings/CodexUrlSettings";
import { ErrorBoundary } from "@sentry/react"; import { ErrorBoundary } from "@sentry/react";
import { ErrorPlaceholder } from "../../components/ErrorPlaceholder/ErrorPlaceholder"; import { ErrorPlaceholder } from "../../components/ErrorPlaceholder/ErrorPlaceholder";
import { useEffect } from "react";
export const Route = createFileRoute("/dashboard/settings")({ export const Route = createFileRoute("/dashboard/settings")({
component: () => ( component: () => (
@ -35,12 +36,25 @@ export const Route = createFileRoute("/dashboard/settings")({
<div className="settings"> <div className="settings">
<ErrorBoundary <ErrorBoundary
fallback={({ error }) => ( fallback={({ error, resetError }) => {
<ErrorPlaceholder useEffect(() => {
error={error} document.addEventListener("codexinvalidatequeries", resetError);
subtitle="Cannot retrieve the data."
/> return () => {
)}> document.removeEventListener(
"codexinvalidatequeries",
resetError
);
};
}, [resetError]);
return (
<ErrorPlaceholder
error={error}
subtitle="Cannot retrieve the data."
/>
);
}}>
<Debug /> <Debug />
</ErrorBoundary> </ErrorBoundary>
</div> </div>