Use more atoms.
This commit is contained in:
parent
bb35a80e97
commit
3b50b1e913
|
|
@ -12,26 +12,31 @@ const versionQueryFn = async () => {
|
||||||
return resp.json();
|
return resp.json();
|
||||||
};
|
};
|
||||||
|
|
||||||
const versionAtom = atomWithQuery(() => ({
|
const versionQueryAtom = atomWithQuery(() => ({
|
||||||
queryKey: ["version"],
|
queryKey: ["version"],
|
||||||
queryFn: versionQueryFn,
|
queryFn: versionQueryFn,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export function Version() {
|
const versionAtom = atom((get) => {
|
||||||
const [{ data, isPending, isError }] = useAtom(versionAtom);
|
const version = get(versionQueryAtom);
|
||||||
|
let parseVersion = () => {
|
||||||
let versionText = () => {
|
if (version.isPending) {
|
||||||
if (isPending) {
|
|
||||||
return "Loading...";
|
return "Loading...";
|
||||||
}
|
}
|
||||||
if (isError) {
|
if (version.isError) {
|
||||||
return "Error loading!";
|
return "Error loading!";
|
||||||
}
|
}
|
||||||
if (!data.status) {
|
if (!version.data.status) {
|
||||||
return "Can not find version";
|
return "Can not find version";
|
||||||
}
|
}
|
||||||
return YAML.stringify(data.message);
|
return YAML.stringify(version.data.message);
|
||||||
};
|
};
|
||||||
|
const versionText = parseVersion();
|
||||||
|
return versionText;
|
||||||
|
});
|
||||||
|
|
||||||
|
export function Version() {
|
||||||
|
let versionText = useAtom(versionAtom);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
|
|
@ -40,7 +45,7 @@ export function Version() {
|
||||||
<Card className="padded">
|
<Card className="padded">
|
||||||
<Card.Title>project.yaml</Card.Title>
|
<Card.Title>project.yaml</Card.Title>
|
||||||
<Card.Body>
|
<Card.Body>
|
||||||
<pre>{versionText()}</pre>
|
<pre>{versionText}</pre>
|
||||||
</Card.Body>
|
</Card.Body>
|
||||||
</Card>
|
</Card>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue