snort/packages/app/src/Pages/subscribe/ManageSubscription.tsx

72 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-04-13 18:43:43 +00:00
import { useEffect, useState } from "react";
import { FormattedMessage } from "react-intl";
import { Link, useNavigate } from "react-router-dom";
2023-04-13 18:43:43 +00:00
2023-11-17 11:52:10 +00:00
import PageSpinner from "@/Element/PageSpinner";
import useEventPublisher from "@/Hooks/useEventPublisher";
import SnortApi, { Subscription, SubscriptionError } from "@/External/SnortApi";
2023-04-17 21:22:00 +00:00
import { mapSubscriptionErrorCode } from ".";
import SubscriptionCard from "./SubscriptionCard";
2023-11-17 11:52:10 +00:00
import { ErrorOrOffline } from "@/Element/ErrorOrOffline";
2023-04-13 18:43:43 +00:00
export default function ManageSubscriptionPage() {
2023-10-13 15:34:31 +00:00
const { publisher } = useEventPublisher();
2023-04-13 18:43:43 +00:00
const api = new SnortApi(undefined, publisher);
const navigate = useNavigate();
2023-04-13 18:43:43 +00:00
const [subs, setSubs] = useState<Array<Subscription>>();
2023-10-31 15:40:12 +00:00
const [error, setError] = useState<Error>();
2023-04-13 18:43:43 +00:00
2023-10-31 15:40:12 +00:00
async function loadSubs() {
setError(undefined);
try {
const s = await api.listSubscriptions();
setSubs(s);
} catch (e) {
if (e instanceof Error) {
setError(e);
2023-04-13 18:43:43 +00:00
}
2023-10-31 15:40:12 +00:00
}
}
useEffect(() => {
loadSubs();
2023-04-13 18:43:43 +00:00
}, []);
2023-10-31 15:40:57 +00:00
if (!(error instanceof SubscriptionError) && error instanceof Error)
return <ErrorOrOffline error={error} onRetry={loadSubs} className="main-content p" />;
2023-04-13 18:43:43 +00:00
if (subs === undefined) {
return <PageSpinner />;
}
return (
<div className="main-content p flex flex-col g16">
2023-04-13 18:43:43 +00:00
<h2>
<FormattedMessage defaultMessage="Subscriptions" id="J+dIsA" />
2023-04-13 18:43:43 +00:00
</h2>
2023-04-17 21:22:00 +00:00
{subs.map(a => (
<SubscriptionCard sub={a} key={a.id} />
))}
{subs.length !== 0 && (
Squashed commit of the following: commit 87cda09ac6442820a0b16933989525dcb53a4425 Merge: 02d9bbf7 2bec5d95 Author: Karnage <karnagebitcoin@gmail.com> Date: Tue Sep 19 23:13:32 2023 +0900 Merge branch 'css-fixes' commit 2bec5d95c00476537dc5460f01557af12c1baa7b Author: Karnage <karnagebitcoin@gmail.com> Date: Tue Sep 19 22:40:27 2023 +0900 minor tweak on tabs commit 776005e5eaafd5a8bc94cbf7821579a5bb831b1c Author: Karnage <karnagebitcoin@gmail.com> Date: Tue Sep 19 00:28:53 2023 +0900 added subscription tier borders in light mode commit 66a55feb9950f433787d2a6966b200339462c4c6 Author: Karnage <karnagebitcoin@gmail.com> Date: Tue Sep 19 00:28:43 2023 +0900 fixed tab colors in light mode commit 830cc3c973301d2ce63745e1e328c69a219db1ef Author: Karnage <karnagebitcoin@gmail.com> Date: Tue Sep 19 00:28:29 2023 +0900 secondary color adjustment commit 8c9939f3484c2dd5678ac72795dba7fa7f970402 Author: Karnage <karnagebitcoin@gmail.com> Date: Tue Sep 19 00:12:46 2023 +0900 szh menu shadow fix commit a59124f91055a4a9a3758823dee76e8bc44c5e83 Author: Karnage <karnagebitcoin@gmail.com> Date: Tue Sep 19 00:01:34 2023 +0900 misc fixes commit a4da5d86677eadace1b86df2d72e35255178a5f0 Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 17:50:15 2023 +0900 Re-ordered reactions for consistency commit 665162b6918b1666f1413884d4b4185d4df0f74a Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 13:25:55 2023 +0900 styled light load more button commit a3058168d6df685cdf9d2871f8e3b335318eedcb Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 00:38:16 2023 +0900 styled subscriptions a bit commit dcc940d96cefeca476e16891c148e2058fb48fd7 Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 00:22:39 2023 +0900 adjusted input border to 2px and font size 15 commit 690e1662eeded6eab9f3029ce168d44b35604dca Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 00:22:12 2023 +0900 fixed settings tabs paddings commit a5809c4c7d502da42788c6c758d6025e79699cf5 Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 00:05:45 2023 +0900 removed some double borders commit d1e0c331ed665c63160c2ae83f9e010b666c39df Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 00:05:28 2023 +0900 follow is primary now commit 338bc03aa3616906326fe0a777a63c04dc4a7f48 Author: Karnage <karnagebitcoin@gmail.com> Date: Mon Sep 18 00:05:10 2023 +0900 made follow button a primary commit 4b5eb0c4fc71e0a8cf822ba8cac8facc53301e1e Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 23:43:12 2023 +0900 made follows you into a label commit 0a9d616402528311f4feba53f0ba9171b0640274 Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 23:35:07 2023 +0900 created secondary button bg variable commit 2abcab804adf392e8f7ff2907762bc35c77f0297 Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 23:34:41 2023 +0900 added gap to profile buttons commit 04a54ddb0d7b19c5ea7f420645c6bd3d37747c17 Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 23:34:26 2023 +0900 change new note button color commit 2d2401586af70187785cff693061666d1de343f2 Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 22:57:01 2023 +0900 forget what I did here commit 14d8bd255cc41e5450b18908b807e3d745c10fbe Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 22:35:32 2023 +0900 adjusted new note button position commit e3a6143626424b898aad43fc2eb1625336342c16 Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 22:32:37 2023 +0900 added primary button colors commit 4d02bfef54668d1a09f0615634d6be540c9837ea Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 18:51:37 2023 +0900 cleaned up modal reactions commit 891f7985c6cf674d03188a95b3ca807ecb16c0bc Author: Karnage <karnagebitcoin@gmail.com> Date: Sun Sep 17 00:10:46 2023 +0900 minimized error text from scary to less scary commit dc563e7ded8794e43ed14409d5ffeb917172b800 Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 23:50:27 2023 +0900 adjusted search colors in light mode commit 328cc853794c9b32abf8eab067bfd3f9b1a76aee Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 22:59:33 2023 +0900 revert main font size, adjust thread root size commit 2e55cbcbc1bc6e9494410ec77052adb3fd8bbbcf Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 22:49:09 2023 +0900 re-styled quoted replies note creator commit a3257eecff0a028a22d975eec778daeb73d8ec2e Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 22:38:00 2023 +0900 got rid of weird filter menu shadow and radius commit 258d51c6fddb65d3afecd595a1fd9352c2cfa13e Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 22:12:03 2023 +0900 adjusted header bottom spacing per design to 8px commit 03669925086e8a4995124d6e9077d61373fa89d3 Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 22:00:34 2023 +0900 adjusted gap to 16 per design commit 9a1c77b0dd876632ecd313d25ce163204ff89897 Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 21:56:50 2023 +0900 set root font size to 16px per design commit 4d0a91317d8946465b0d591db3d13c2e3df63ff8 Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 21:50:57 2023 +0900 made search full width commit 3ea6b4ca005b27003f1554d53def14337620af2a Author: Karnage <karnagebitcoin@gmail.com> Date: Sat Sep 16 21:47:29 2023 +0900 fixed line height on thread root note
2023-09-22 08:33:21 +00:00
<button className="primary" onClick={() => navigate("/subscribe")}>
<FormattedMessage defaultMessage="Buy Subscription" id="SP0+yi" />
</button>
)}
2023-04-13 18:43:43 +00:00
{subs.length === 0 && (
<p>
<FormattedMessage
2023-11-20 19:16:47 +00:00
defaultMessage="It looks like you dont have any subscriptions, you can get one {link}"
id="W1yoZY"
2023-04-13 18:43:43 +00:00
values={{
link: (
<Link to="/subscribe">
<FormattedMessage defaultMessage="here" id="hniz8Z" />
2023-04-13 18:43:43 +00:00
</Link>
),
}}
/>
</p>
)}
2023-10-31 15:40:12 +00:00
{error instanceof SubscriptionError && <b className="error">{mapSubscriptionErrorCode(error)}</b>}
2023-08-21 13:58:57 +00:00
</div>
2023-04-13 18:43:43 +00:00
);
}