From 107cc7ab5fa84796baefb87396ee7b11d97e66f4 Mon Sep 17 00:00:00 2001 From: Tyler Brown Cifu Shuster Date: Thu, 17 Sep 2020 20:40:59 -0700 Subject: [PATCH] publish: allow unsubscribing from notebooks fixes #3505 --- .../apps/publish/components/lib/Join.tsx | 9 +- .../apps/publish/components/lib/Notebook.tsx | 224 ++++++++++-------- 2 files changed, 126 insertions(+), 107 deletions(-) diff --git a/pkg/interface/src/views/apps/publish/components/lib/Join.tsx b/pkg/interface/src/views/apps/publish/components/lib/Join.tsx index b12825acb..c510df597 100644 --- a/pkg/interface/src/views/apps/publish/components/lib/Join.tsx +++ b/pkg/interface/src/views/apps/publish/components/lib/Join.tsx @@ -4,6 +4,7 @@ import { Spinner } from "~/views/components/Spinner"; import { Notebooks } from "~/types/publish-update"; import { useWaitForProps } from "~/logic/lib/useWaitForProps"; import { RouteComponentProps } from "react-router-dom"; +import { deSig } from "~/logic/lib/util"; interface JoinScreenProps { api: any; // GlobalApi; @@ -21,15 +22,9 @@ export function JoinScreen(props: JoinScreenProps & RouteComponentProps) { const onJoin = useCallback(async () => { joining.current = true; - const action = { - subscribe: { - who: ship.replace("~", ""), - book, - }, - }; try { - await api.publish.publishAction(action); + await api.publish.subscribeNotebook(deSig(ship), book); await waiter((p) => !!p.notebooks?.[ship]?.[book]); props.history.replace(`/~publish/notebook/${ship}/${book}`); } catch (e) { diff --git a/pkg/interface/src/views/apps/publish/components/lib/Notebook.tsx b/pkg/interface/src/views/apps/publish/components/lib/Notebook.tsx index f98f2e6ac..0b2390562 100644 --- a/pkg/interface/src/views/apps/publish/components/lib/Notebook.tsx +++ b/pkg/interface/src/views/apps/publish/components/lib/Notebook.tsx @@ -1,8 +1,9 @@ -import React from "react"; +import React, { PureComponent } from "react"; import { Link, RouteComponentProps, Route, Switch } from "react-router-dom"; import { NotebookPosts } from "./NotebookPosts"; import { Subscribers } from "./Subscribers"; import { Settings } from "./Settings"; +import { Spinner } from '~/views/components/Spinner'; import { roleForShip } from "~/logic/lib/group"; import { Box, @@ -21,6 +22,7 @@ import { Contacts, Rolodex } from "~/types/contact-update"; import GlobalApi from "~/logic/api/global"; import styled from "styled-components"; import {Associations} from "~/types"; +import { deSig } from "~/logic/lib/util"; const TabList = styled(_TabList)` margin-bottom: ${(p) => p.theme.space[4]}px; @@ -42,105 +44,127 @@ interface NotebookProps { associations: Associations; } -export function Notebook(props: NotebookProps & RouteComponentProps) { - const { api, ship, book, notebook, notebookContacts, groups } = props; - - const contact = notebookContacts[ship]; - const group = groups[notebook?.["writers-group-path"]]; - const role = group ? roleForShip(group, window.ship) : undefined; - const isOwn = `~${window.ship}` === ship; - const isAdmin = role === "admin" || isOwn; - - const isWriter = - isOwn || group.tags?.publish?.[`writers-${book}`]?.has(window.ship); - - const notesList = notebook?.["notes-by-date"] || []; - const notes = notebook?.notes || {}; - const showNickname = contact?.nickname && !props.hideNicknames; - - return ( - - - {"<- All Notebooks"} - - - {notebook?.title} -
- by - - {showNickname ? contact?.nickname : ship} - -
- - {isWriter && ( - - - - )} - {!isOwn && ( - - )} - - - - - All Posts - About - {isAdmin && Subscribers} - {isOwn && Settings} - - - - - - - {notebook?.about} - - - - - - - - - - -
- ); +interface NotebookState { + isUnsubscribing: boolean; } +export class Notebook extends PureComponent { + 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 group = groups[notebook?.["writers-group-path"]]; + const role = group ? roleForShip(group, window.ship) : undefined; + const isOwn = `~${window.ship}` === ship; + const isAdmin = role === "admin" || isOwn; + + const isWriter = + isOwn || group.tags?.publish?.[`writers-${book}`]?.has(window.ship); + + const notesList = notebook?.["notes-by-date"] || []; + const notes = notebook?.notes || {}; + const showNickname = contact?.nickname && !hideNicknames; + + return ( + + + {"<- All Notebooks"} + + + {notebook?.title} +
+ by + + {showNickname ? contact?.nickname : ship} + +
+ + {isWriter && ( + + + + )} + {!isOwn + ? this.state.isUnsubscribing + ? + : + : null + } + + + + + All Posts + About + {isAdmin && Subscribers} + {isOwn && Settings} + + + + + + + {notebook?.about} + + + + + + + + + + +
+ ); + } +} export default Notebook;