publish: allow unsubscribing from notebooks

fixes #3505
This commit is contained in:
Tyler Brown Cifu Shuster 2020-09-17 20:40:59 -07:00
parent 91ddc70c60
commit 107cc7ab5f
2 changed files with 126 additions and 107 deletions

View File

@ -4,6 +4,7 @@ import { Spinner } from "~/views/components/Spinner";
import { Notebooks } from "~/types/publish-update"; import { Notebooks } from "~/types/publish-update";
import { useWaitForProps } from "~/logic/lib/useWaitForProps"; import { useWaitForProps } from "~/logic/lib/useWaitForProps";
import { RouteComponentProps } from "react-router-dom"; import { RouteComponentProps } from "react-router-dom";
import { deSig } from "~/logic/lib/util";
interface JoinScreenProps { interface JoinScreenProps {
api: any; // GlobalApi; api: any; // GlobalApi;
@ -21,15 +22,9 @@ export function JoinScreen(props: JoinScreenProps & RouteComponentProps) {
const onJoin = useCallback(async () => { const onJoin = useCallback(async () => {
joining.current = true; joining.current = true;
const action = {
subscribe: {
who: ship.replace("~", ""),
book,
},
};
try { try {
await api.publish.publishAction(action); await api.publish.subscribeNotebook(deSig(ship), book);
await waiter((p) => !!p.notebooks?.[ship]?.[book]); await waiter((p) => !!p.notebooks?.[ship]?.[book]);
props.history.replace(`/~publish/notebook/${ship}/${book}`); props.history.replace(`/~publish/notebook/${ship}/${book}`);
} catch (e) { } catch (e) {

View File

@ -1,8 +1,9 @@
import React from "react"; import React, { PureComponent } from "react";
import { Link, RouteComponentProps, Route, Switch } from "react-router-dom"; import { Link, RouteComponentProps, Route, Switch } from "react-router-dom";
import { NotebookPosts } from "./NotebookPosts"; import { NotebookPosts } from "./NotebookPosts";
import { Subscribers } from "./Subscribers"; import { Subscribers } from "./Subscribers";
import { Settings } from "./Settings"; import { Settings } from "./Settings";
import { Spinner } from '~/views/components/Spinner';
import { roleForShip } from "~/logic/lib/group"; import { roleForShip } from "~/logic/lib/group";
import { import {
Box, Box,
@ -21,6 +22,7 @@ import { Contacts, Rolodex } from "~/types/contact-update";
import GlobalApi from "~/logic/api/global"; import GlobalApi from "~/logic/api/global";
import styled from "styled-components"; import styled from "styled-components";
import {Associations} from "~/types"; import {Associations} from "~/types";
import { deSig } from "~/logic/lib/util";
const TabList = styled(_TabList)` const TabList = styled(_TabList)`
margin-bottom: ${(p) => p.theme.space[4]}px; margin-bottom: ${(p) => p.theme.space[4]}px;
@ -42,8 +44,20 @@ interface NotebookProps {
associations: Associations; associations: Associations;
} }
export function Notebook(props: NotebookProps & RouteComponentProps) { interface NotebookState {
const { api, ship, book, notebook, notebookContacts, groups } = props; isUnsubscribing: boolean;
}
export class Notebook extends PureComponent<NotebookProps & RouteComponentProps, NotebookState> {
constructor(props) {
super(props);
this.state = {
isUnsubscribing: false
};
}
render() {
const { api, ship, book, notebook, notebookContacts, groups, history, hideNicknames, associations } = this.props;
const contact = notebookContacts[ship]; const contact = notebookContacts[ship];
const group = groups[notebook?.["writers-group-path"]]; const group = groups[notebook?.["writers-group-path"]];
@ -56,7 +70,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
const notesList = notebook?.["notes-by-date"] || []; const notesList = notebook?.["notes-by-date"] || [];
const notes = notebook?.notes || {}; const notes = notebook?.notes || {};
const showNickname = contact?.nickname && !props.hideNicknames; const showNickname = contact?.nickname && !hideNicknames;
return ( return (
<Box <Box
@ -88,11 +102,21 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
</Button> </Button>
</Link> </Link>
)} )}
{!isOwn && ( {!isOwn
<Button ml={isWriter ? 2 : 0} error border> ? this.state.isUnsubscribing
? <Spinner awaiting={this.state.isUnsubscribing} classes="mt2 ml2" text="Unsubscribing..." />
: <Button ml={isWriter ? 2 : 0} error border onClick={() => {
this.setState({ isUnsubscribing: true });
api.publish.unsubscribeNotebook(deSig(ship), book).then(() => {
history.push("/~publish");
}).catch(() => {
this.setState({ isUnsubscribing: false });
});
}}>
Unsubscribe Unsubscribe
</Button> </Button>
)} : null
}
</Row> </Row>
<Box gridColumn={["1/2", "1/3"]}> <Box gridColumn={["1/2", "1/3"]}>
<Tabs> <Tabs>
@ -110,7 +134,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
host={ship} host={ship}
book={book} book={book}
contacts={notebookContacts} contacts={notebookContacts}
hideNicknames={props.hideNicknames} hideNicknames={hideNicknames}
/> />
</TabPanel> </TabPanel>
<TabPanel> <TabPanel>
@ -132,7 +156,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
api={api} api={api}
notebook={notebook} notebook={notebook}
contacts={notebookContacts} contacts={notebookContacts}
associations={props.associations} associations={associations}
groups={groups} groups={groups}
/> />
</TabPanel> </TabPanel>
@ -141,6 +165,6 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
</Box> </Box>
</Box> </Box>
); );
}
} }
export default Notebook; export default Notebook;