-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathListing.tsx
More file actions
65 lines (51 loc) · 1.69 KB
/
Listing.tsx
File metadata and controls
65 lines (51 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { useParams, Link } from "react-router-dom";
import { useQuery } from "react-query";
import { Strip, Notification } from "@canonical/react-components";
import SectionNav from "../../components/SectionNav";
import ListingForm from "./ListingForm";
import { setPageTitle } from "../../utils";
function Listing(): React.JSX.Element {
const { snapId } = useParams();
const { data, isLoading, refetch, status } = useQuery({
queryKey: ["listing"],
queryFn: async () => {
const response = await fetch(`/api/${snapId}/listing`);
if (!response.ok) {
throw new Error("There was a problem fetching listing data");
}
const data = await response.json();
if (!data.success) {
throw new Error(data.message);
}
return data.data;
},
});
setPageTitle(`Listing data for ${snapId}`);
return (
<>
<h1 className="p-heading--4" aria-live="polite">
<a href="/snaps">My snaps</a> / <a href={`/${snapId}`}>{snapId}</a> /
Listing
</h1>
<SectionNav snapName={snapId} activeTab="listing" />
{isLoading && (
<Strip shallow>
<p>
<i className="p-icon--spinner u-animation--spin"></i> Loading{" "}
{snapId} listing data
</p>
</Strip>
)}
{!isLoading && status === "error" && (
<Strip shallow>
<Notification severity="information">
Editing listing data is not available for this snap. Make sure{" "}
<Link to="/snaps">this snap is published</Link>.
</Notification>
</Strip>
)}
{data && <ListingForm data={data} refetch={refetch} />}
</>
);
}
export default Listing;