1
0
Fork 0
mirror of https://github.com/binwiederhier/ntfy.git synced 2025-05-15 12:06:11 +02:00

Automatic account sync with react

This commit is contained in:
binwiederhier 2023-01-02 22:21:11 -05:00
parent d666cab77a
commit bb583eaa72
5 changed files with 81 additions and 57 deletions
web/src/components

View file

@ -5,7 +5,7 @@ import {
CardContent,
FormControl,
Select,
Stack, styled,
Stack,
Table,
TableBody,
TableCell,
@ -482,6 +482,11 @@ const Reservations = () => {
const [dialogKey, setDialogKey] = useState(0);
const [dialogOpen, setDialogOpen] = useState(false);
if (!session.exists() || !account) {
return <></>;
}
const reservations = account.reservations || [];
const handleAddClick = () => {
setDialogKey(prev => prev+1);
setDialogOpen(true);
@ -495,6 +500,7 @@ const Reservations = () => {
setDialogOpen(false);
try {
await accountApi.upsertAccess(reservation.topic, reservation.everyone);
await accountApi.sync();
console.debug(`[Preferences] Added topic reservation`, reservation);
} catch (e) {
console.log(`[Preferences] Error topic reservation.`, e);
@ -502,10 +508,6 @@ const Reservations = () => {
// FIXME handle 401/403
};
if (!session.exists() || !account) {
return <></>;
}
return (
<Card sx={{ padding: 1 }} aria-label={t("prefs_reservations_title")}>
<CardContent sx={{ paddingBottom: 1 }}>
@ -515,7 +517,7 @@ const Reservations = () => {
<Paragraph>
{t("prefs_reservations_description")}
</Paragraph>
{account.reservations.length > 0 && <ReservationsTable reservations={account.reservations}/>}
{reservations.length > 0 && <ReservationsTable reservations={reservations}/>}
</CardContent>
<CardActions>
<Button onClick={handleAddClick}>{t("prefs_reservations_add_button")}</Button>
@ -523,7 +525,7 @@ const Reservations = () => {
key={`reservationAddDialog${dialogKey}`}
open={dialogOpen}
reservation={null}
reservations={account.reservations}
reservations={reservations}
onCancel={handleDialogCancel}
onSubmit={handleDialogSubmit}
/>
@ -552,6 +554,7 @@ const ReservationsTable = (props) => {
setDialogOpen(false);
try {
await accountApi.upsertAccess(reservation.topic, reservation.everyone);
await accountApi.sync();
console.debug(`[Preferences] Added topic reservation`, reservation);
} catch (e) {
console.log(`[Preferences] Error topic reservation.`, e);
@ -562,6 +565,7 @@ const ReservationsTable = (props) => {
const handleDeleteClick = async (reservation) => {
try {
await accountApi.deleteAccess(reservation.topic);
await accountApi.sync();
console.debug(`[Preferences] Deleted topic reservation`, reservation);
} catch (e) {
console.log(`[Preferences] Error topic reservation.`, e);