From ec657cb8f8c58cc9b785456b1a57b2a901d8c3ff Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Tue, 6 Oct 2020 13:44:21 -0500 Subject: [PATCH] interface: clean up publish --- .../views/apps/publish/PublishResource.tsx | 2 +- pkg/interface/src/views/apps/publish/app.tsx | 176 ------------------ .../publish/components/{lib => }/Author.tsx | 0 .../components/{lib => }/CommentInput.tsx | 2 +- .../components/{lib => }/CommentItem.tsx | 0 .../publish/components/{lib => }/Comments.tsx | 0 .../publish/components/{lib => }/EditPost.tsx | 0 .../components/{lib => }/GroupifyForm.tsx | 0 .../components/{lib => }/MarkdownEditor.tsx | 0 .../components/{lib => }/MarkdownField.tsx | 0 .../components/{lib => }/MetadataForm.tsx | 2 +- .../publish/components/{lib => }/Note.tsx | 0 .../publish/components/{lib => }/NoteForm.tsx | 2 +- .../components/{lib => }/NoteNavigation.tsx | 0 .../components/{lib => }/NotePreview.tsx | 0 .../components/{lib => }/NoteRoutes.tsx | 0 .../publish/components/{lib => }/Notebook.tsx | 0 .../components/{lib => }/NotebookPosts.tsx | 0 .../components/{lib => }/NotebookRoutes.tsx | 13 +- .../publish/components/{lib => }/Settings.tsx | 0 .../components/{lib => }/Subscribers.tsx | 0 .../apps/publish/components/lib/GroupItem.tsx | 45 ----- .../apps/publish/components/lib/Join.tsx | 54 ------ .../publish/components/lib/NotebookItem.tsx | 52 ------ .../apps/publish/components/lib/Sidebar.tsx | 128 ------------- .../apps/publish/components/lib/Welcome.tsx | 32 ---- .../views/apps/publish/components/lib/new.tsx | 103 ---------- .../publish/components/{lib => }/new-post.tsx | 0 .../apps/publish/components/skeleton.tsx | 133 ------------- 29 files changed, 11 insertions(+), 733 deletions(-) delete mode 100644 pkg/interface/src/views/apps/publish/app.tsx rename pkg/interface/src/views/apps/publish/components/{lib => }/Author.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/CommentInput.tsx (95%) rename pkg/interface/src/views/apps/publish/components/{lib => }/CommentItem.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/Comments.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/EditPost.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/GroupifyForm.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/MarkdownEditor.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/MarkdownField.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/MetadataForm.tsx (97%) rename pkg/interface/src/views/apps/publish/components/{lib => }/Note.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/NoteForm.tsx (96%) rename pkg/interface/src/views/apps/publish/components/{lib => }/NoteNavigation.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/NotePreview.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/NoteRoutes.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/Notebook.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/NotebookPosts.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/NotebookRoutes.tsx (89%) rename pkg/interface/src/views/apps/publish/components/{lib => }/Settings.tsx (100%) rename pkg/interface/src/views/apps/publish/components/{lib => }/Subscribers.tsx (100%) delete mode 100644 pkg/interface/src/views/apps/publish/components/lib/GroupItem.tsx delete mode 100644 pkg/interface/src/views/apps/publish/components/lib/Join.tsx delete mode 100644 pkg/interface/src/views/apps/publish/components/lib/NotebookItem.tsx delete mode 100644 pkg/interface/src/views/apps/publish/components/lib/Sidebar.tsx delete mode 100644 pkg/interface/src/views/apps/publish/components/lib/Welcome.tsx delete mode 100644 pkg/interface/src/views/apps/publish/components/lib/new.tsx rename pkg/interface/src/views/apps/publish/components/{lib => }/new-post.tsx (100%) delete mode 100644 pkg/interface/src/views/apps/publish/components/skeleton.tsx diff --git a/pkg/interface/src/views/apps/publish/PublishResource.tsx b/pkg/interface/src/views/apps/publish/PublishResource.tsx index e946aed76..79be77669 100644 --- a/pkg/interface/src/views/apps/publish/PublishResource.tsx +++ b/pkg/interface/src/views/apps/publish/PublishResource.tsx @@ -5,7 +5,7 @@ import GlobalApi from "~/logic/api/global"; import { StoreState } from "~/logic/store/type"; import { Association } from "~/types"; import { RouteComponentProps } from "react-router-dom"; -import { NotebookRoutes } from "./components/lib/NotebookRoutes"; +import { NotebookRoutes } from "./components/NotebookRoutes"; type PublishResourceProps = StoreState & { association: Association; diff --git a/pkg/interface/src/views/apps/publish/app.tsx b/pkg/interface/src/views/apps/publish/app.tsx deleted file mode 100644 index 4673221af..000000000 --- a/pkg/interface/src/views/apps/publish/app.tsx +++ /dev/null @@ -1,176 +0,0 @@ -import React, { useRef, useEffect } from "react"; -import { Route, Switch, useLocation, withRouter } from "react-router-dom"; -import { Center, Text } from "@tlon/indigo-react"; -import _ from "lodash"; -import Helmet from "react-helmet"; - -import "./css/custom.css"; - -import { Skeleton } from "./components/skeleton"; -import { NewScreen } from "./components/lib/new"; -import { JoinScreen } from "./components/lib/Join"; -import { StoreState } from "~/logic/store/type"; -import GlobalApi from "~/logic/api/global"; -import GlobalSubscription from "~/logic/subscription/global"; -import { NotebookRoutes } from "./components/lib/NotebookRoutes"; - -type PublishAppProps = StoreState & { - api: GlobalApi; - ship: string; - subscription: GlobalSubscription; -}; - -const RouterSkeleton = withRouter(Skeleton); - -export default function PublishApp(props: PublishAppProps) { - const unreadTotal = useRef(0); - - useEffect(() => { - document.title = - unreadTotal.current > 0 - ? `(${unreadTotal.current}) OS1 - Publish` - : "OS1 - Publish"; - }, [unreadTotal.current]); - - useEffect(() => { - props.subscription.startApp("publish"); - props.api.publish.fetchNotebooks(); - - return () => { - props.subscription.stopApp("publish"); - }; - }, []); - - const contacts = props.contacts ? props.contacts : {}; - - const notebooks = props.notebooks ? props.notebooks : {}; - - const location = useLocation(); - - unreadTotal.current = _.chain(notebooks) - .values() - .map(_.values) - .flatten() // flatten into array of notebooks - .map("num-unread") - .reduce((acc, count) => acc + count, 0) - .value(); - - const { - api, - groups, - sidebarShown, - invites, - associations, - hideNicknames, - hideAvatars, - remoteContentPolicy - } = props; - - const active = location.pathname.endsWith("/~publish") - ? "sidebar" - : "rightPanel"; - - return ( - <> - - {unreadTotal > 0 ? `(${unreadTotal}) ` : ""}OS1 - Publish - - - - - -
- - Select or create a notebook to begin. - -
-
- { - return ( - - ); - }} - /> - { - const ship = props.match.params.ship || ""; - const notebook = props.match.params.notebook || ""; - return ( - - ); - }} - /> - { - const view = props.match.params.view - ? props.match.params.view - : "posts"; - - const ship = props.match.params.ship || ""; - const book = props.match.params.notebook || ""; - - const bookGroupPath = - notebooks?.[ship]?.[book]?.["subscribers-group-path"]; - - const notebookContacts = - bookGroupPath in contacts ? contacts[bookGroupPath] : {}; - - const notebook = notebooks?.[ship]?.[book]; - return ( - - ); - }} - /> -
-
-
- - ); -} diff --git a/pkg/interface/src/views/apps/publish/components/lib/Author.tsx b/pkg/interface/src/views/apps/publish/components/Author.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/Author.tsx rename to pkg/interface/src/views/apps/publish/components/Author.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/CommentInput.tsx b/pkg/interface/src/views/apps/publish/components/CommentInput.tsx similarity index 95% rename from pkg/interface/src/views/apps/publish/components/lib/CommentInput.tsx rename to pkg/interface/src/views/apps/publish/components/CommentInput.tsx index 1a4b4a82f..d02c3819e 100644 --- a/pkg/interface/src/views/apps/publish/components/lib/CommentInput.tsx +++ b/pkg/interface/src/views/apps/publish/components/CommentInput.tsx @@ -1,7 +1,7 @@ import React from "react"; import * as Yup from "yup"; import { Formik, FormikHelpers, Form, useFormikContext } from "formik"; -import { AsyncButton } from "../../../../components/AsyncButton"; +import { AsyncButton } from "../../../components/AsyncButton"; import { ManagedTextAreaField as TextArea } from "@tlon/indigo-react"; interface FormSchema { diff --git a/pkg/interface/src/views/apps/publish/components/lib/CommentItem.tsx b/pkg/interface/src/views/apps/publish/components/CommentItem.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/CommentItem.tsx rename to pkg/interface/src/views/apps/publish/components/CommentItem.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/Comments.tsx b/pkg/interface/src/views/apps/publish/components/Comments.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/Comments.tsx rename to pkg/interface/src/views/apps/publish/components/Comments.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/EditPost.tsx b/pkg/interface/src/views/apps/publish/components/EditPost.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/EditPost.tsx rename to pkg/interface/src/views/apps/publish/components/EditPost.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/GroupifyForm.tsx b/pkg/interface/src/views/apps/publish/components/GroupifyForm.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/GroupifyForm.tsx rename to pkg/interface/src/views/apps/publish/components/GroupifyForm.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/MarkdownEditor.tsx b/pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/MarkdownEditor.tsx rename to pkg/interface/src/views/apps/publish/components/MarkdownEditor.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/MarkdownField.tsx b/pkg/interface/src/views/apps/publish/components/MarkdownField.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/MarkdownField.tsx rename to pkg/interface/src/views/apps/publish/components/MarkdownField.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/MetadataForm.tsx b/pkg/interface/src/views/apps/publish/components/MetadataForm.tsx similarity index 97% rename from pkg/interface/src/views/apps/publish/components/lib/MetadataForm.tsx rename to pkg/interface/src/views/apps/publish/components/MetadataForm.tsx index 05065ba2c..a055a51ef 100644 --- a/pkg/interface/src/views/apps/publish/components/lib/MetadataForm.tsx +++ b/pkg/interface/src/views/apps/publish/components/MetadataForm.tsx @@ -1,5 +1,5 @@ import React, { useEffect } from "react"; -import { AsyncButton } from "../../../../components/AsyncButton"; +import { AsyncButton } from "../../../components/AsyncButton"; import * as Yup from "yup"; import { Box, diff --git a/pkg/interface/src/views/apps/publish/components/lib/Note.tsx b/pkg/interface/src/views/apps/publish/components/Note.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/Note.tsx rename to pkg/interface/src/views/apps/publish/components/Note.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/NoteForm.tsx b/pkg/interface/src/views/apps/publish/components/NoteForm.tsx similarity index 96% rename from pkg/interface/src/views/apps/publish/components/lib/NoteForm.tsx rename to pkg/interface/src/views/apps/publish/components/NoteForm.tsx index efcc457fd..0f5f569f9 100644 --- a/pkg/interface/src/views/apps/publish/components/lib/NoteForm.tsx +++ b/pkg/interface/src/views/apps/publish/components/NoteForm.tsx @@ -6,7 +6,7 @@ import { Row, Col, } from "@tlon/indigo-react"; -import { AsyncButton } from "../../../../components/AsyncButton"; +import { AsyncButton } from "../../../components/AsyncButton"; import { Formik, Form, FormikHelpers } from "formik"; import { MarkdownField } from "./MarkdownField"; diff --git a/pkg/interface/src/views/apps/publish/components/lib/NoteNavigation.tsx b/pkg/interface/src/views/apps/publish/components/NoteNavigation.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/NoteNavigation.tsx rename to pkg/interface/src/views/apps/publish/components/NoteNavigation.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/NotePreview.tsx b/pkg/interface/src/views/apps/publish/components/NotePreview.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/NotePreview.tsx rename to pkg/interface/src/views/apps/publish/components/NotePreview.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/NoteRoutes.tsx b/pkg/interface/src/views/apps/publish/components/NoteRoutes.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/NoteRoutes.tsx rename to pkg/interface/src/views/apps/publish/components/NoteRoutes.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/Notebook.tsx b/pkg/interface/src/views/apps/publish/components/Notebook.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/Notebook.tsx rename to pkg/interface/src/views/apps/publish/components/Notebook.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/NotebookPosts.tsx b/pkg/interface/src/views/apps/publish/components/NotebookPosts.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/NotebookPosts.tsx rename to pkg/interface/src/views/apps/publish/components/NotebookPosts.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/NotebookRoutes.tsx b/pkg/interface/src/views/apps/publish/components/NotebookRoutes.tsx similarity index 89% rename from pkg/interface/src/views/apps/publish/components/lib/NotebookRoutes.tsx rename to pkg/interface/src/views/apps/publish/components/NotebookRoutes.tsx index 534da2f74..6ff051f31 100644 --- a/pkg/interface/src/views/apps/publish/components/lib/NotebookRoutes.tsx +++ b/pkg/interface/src/views/apps/publish/components/NotebookRoutes.tsx @@ -1,15 +1,16 @@ import React, { useEffect } from "react"; import { RouteComponentProps, Link, Route, Switch } from "react-router-dom"; import { Box, Text } from "@tlon/indigo-react"; -import GlobalApi from "../../../../api/global"; -import { PublishContent } from "./PublishContent"; -import { Notebook as INotebook } from "../../../../types/publish-update"; -import { Groups } from "../../../../types/group-update"; -import { Contacts, Rolodex } from "../../../../types/contact-update"; +import GlobalApi from "~/api/global"; +import { Notebook as INotebook } from "~/types/publish-update"; +import { Groups } from "~/types/group-update"; +import { Contacts, Rolodex } from "~/types/contact-update"; +import { LocalUpdateRemoteContentPolicy, Associations } from "~/types"; + import Notebook from "./Notebook"; import NewPost from "./new-post"; import { NoteRoutes } from './NoteRoutes'; -import { LocalUpdateRemoteContentPolicy, Associations } from "~/types"; + interface NotebookRoutesProps { api: GlobalApi; diff --git a/pkg/interface/src/views/apps/publish/components/lib/Settings.tsx b/pkg/interface/src/views/apps/publish/components/Settings.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/Settings.tsx rename to pkg/interface/src/views/apps/publish/components/Settings.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/Subscribers.tsx b/pkg/interface/src/views/apps/publish/components/Subscribers.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/Subscribers.tsx rename to pkg/interface/src/views/apps/publish/components/Subscribers.tsx diff --git a/pkg/interface/src/views/apps/publish/components/lib/GroupItem.tsx b/pkg/interface/src/views/apps/publish/components/lib/GroupItem.tsx deleted file mode 100644 index dd5ffb731..000000000 --- a/pkg/interface/src/views/apps/publish/components/lib/GroupItem.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import React, { Component } from 'react'; -import { Box, Text } from "@tlon/indigo-react"; -import { NotebookItem } from './NotebookItem'; - -export class GroupItem extends Component { - render() { - const { props } = this; - const association = props.association ? props.association : {}; - - let title = association['app-path'] ? association['app-path'] : 'Unmanaged Notebooks'; - if (association.metadata && association.metadata.title) { - title = association.metadata.title !== '' - ? association.metadata.title : title; - } - - const groupedBooks = props.groupedBooks ? props.groupedBooks : []; - const first = (props.index === 0) ? 'pt1' : 'pt6'; - - const notebookItems = groupedBooks.map((each, i) => { - const unreads = props.notebooks[each]['num-unread'] || 0; - let title = each.substr(1); - if (props.notebooks[each].title) { - title = (props.notebooks[each].title !== '') - ? props.notebooks[each].title : title; - } - return ( - - ); - }); - return ( - - {title} - {notebookItems} - - ); - } -} - -export default GroupItem; diff --git a/pkg/interface/src/views/apps/publish/components/lib/Join.tsx b/pkg/interface/src/views/apps/publish/components/lib/Join.tsx deleted file mode 100644 index f3f413a77..000000000 --- a/pkg/interface/src/views/apps/publish/components/lib/Join.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import React, { useCallback, useState, useRef, useEffect } from "react"; -import { Col, Text, ErrorLabel } from "@tlon/indigo-react"; -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; - ship: string; - book: string; - notebooks: Notebooks; -} - -export function JoinScreen(props: JoinScreenProps & RouteComponentProps) { - const { book, ship, api } = props; - const [error, setError] = useState(false); - const joining = useRef(false); - - const waiter = useWaitForProps(props); - - const onJoin = useCallback(async () => { - joining.current = true; - - try { - await api.publish.subscribeNotebook(deSig(ship), book); - await waiter((p) => !!p.notebooks?.[ship]?.[book]); - props.history.replace(`/~publish/notebook/${ship}/${book}`); - } catch (e) { - console.error(e); - setError(true); - } finally { - joining.current = false; - } - }, [waiter, api, ship, book]); - - useEffect(() => { - if (joining.current) { - return; - } - onJoin(); - }, [onJoin]); - - return ( - - Joining Notebook - - {error && Unable to join notebook} - - ); -} - -export default JoinScreen; diff --git a/pkg/interface/src/views/apps/publish/components/lib/NotebookItem.tsx b/pkg/interface/src/views/apps/publish/components/lib/NotebookItem.tsx deleted file mode 100644 index 4a03475e7..000000000 --- a/pkg/interface/src/views/apps/publish/components/lib/NotebookItem.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import React, { Component } from "react"; -import { Box, Text } from "@tlon/indigo-react"; -import { Link } from "react-router-dom"; - -import { HoverBox } from "../../../../components/HoverBox"; - -interface NotebookItemProps { - selected: boolean; - title: string; - path: string; - unreadCount: number; -} - -function UnreadCount(props: { unread: number }) { - return ( - - {props.unread} - - ); -} - -export function NotebookItem(props: NotebookItemProps) { - return ( - - - {props.title} - {props.unreadCount > 0 && } - - - ); -} - -export default NotebookItem; diff --git a/pkg/interface/src/views/apps/publish/components/lib/Sidebar.tsx b/pkg/interface/src/views/apps/publish/components/lib/Sidebar.tsx deleted file mode 100644 index 3842e3be8..000000000 --- a/pkg/interface/src/views/apps/publish/components/lib/Sidebar.tsx +++ /dev/null @@ -1,128 +0,0 @@ -import React, { Component } from "react"; -import { Box, Text, Col } from "@tlon/indigo-react"; -import { Link } from "react-router-dom"; -import SidebarInvite from "~/views/components/Sidebar/SidebarInvite"; -import { Welcome } from "./Welcome"; -import { GroupItem } from "./GroupItem"; -import { alphabetiseAssociations } from "~/logic/lib/util"; - -export function Sidebar(props: any) { - const sidebarInvites = !(props.invites && props.invites["/publish"]) - ? null - : Object.keys(props.invites["/publish"]).map((uid) => { - return ( - props.api.invite.accept("/publish", uid)} - onDecline={() => props.api.invite.decline("/publish", uid)} - /> - ); - }); - const associations = - props.associations && "contacts" in props.associations - ? alphabetiseAssociations(props.associations.contacts) - : {}; - - const notebooks = {}; - Object.keys(props.notebooks).map((host) => { - Object.keys(props.notebooks[host]).map((notebook) => { - const title = `${host}/${notebook}`; - notebooks[title] = props.notebooks[host][notebook]; - }); - }); - - const groupedNotebooks = {}; - Object.keys(notebooks).map((book) => { - const path = notebooks[book]["subscribers-group-path"] - ? notebooks[book]["subscribers-group-path"] - : book; - if (path in associations) { - if (groupedNotebooks[path]) { - const array = groupedNotebooks[path]; - array.push(book); - groupedNotebooks[path] = array; - } else { - groupedNotebooks[path] = [book]; - } - } else { - if (groupedNotebooks["/~/"]) { - const array = groupedNotebooks["/~/"]; - array.push(book); - groupedNotebooks["/~/"] = array; - } else { - groupedNotebooks["/~/"] = [book]; - } - } - }); - - const selectedGroups = props.selectedGroups ? props.selectedGroups : []; - const groupedItems = Object.keys(associations) - .map((each, i) => { - const books = groupedNotebooks[each] || []; - if (books.length === 0) return; - if ( - selectedGroups.length === 0 && - groupedNotebooks["/~/"] && - groupedNotebooks["/~/"].length !== 0 - ) { - i = i + 1; - } - return ( - - ); - }); - if ( - selectedGroups.length === 0 && - groupedNotebooks["/~/"] && - groupedNotebooks["/~/"].length !== 0 - ) { - groupedItems.unshift( - - ); - } - - const display = props.hidden ? ['none', 'block'] : 'block'; - - return ( - - - - New Notebook - - - - - {sidebarInvites} - {groupedItems} - - - ); -} - -export default Sidebar; diff --git a/pkg/interface/src/views/apps/publish/components/lib/Welcome.tsx b/pkg/interface/src/views/apps/publish/components/lib/Welcome.tsx deleted file mode 100644 index 451566e56..000000000 --- a/pkg/interface/src/views/apps/publish/components/lib/Welcome.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import React from "react"; -import { Box } from "@tlon/indigo-react"; -import { useLocalStorageState } from "~/logic/lib/useLocalStorageState"; - -export function Welcome(props: Parameters[0]) { - const [wasWelcomed, setWasWelcomed] = useLocalStorageState( - "urbit-publish:wasWelcomed", - false - ); - - if (wasWelcomed) { - return null; - } - return ( - - - Notebooks are for longer-form writing and discussion. Each Notebook is a - collection of Markdown-formatted notes with optional comments. - - { setWasWelcomed(true) }} - > - Close this - - - ); -} - -export default Welcome; diff --git a/pkg/interface/src/views/apps/publish/components/lib/new.tsx b/pkg/interface/src/views/apps/publish/components/lib/new.tsx deleted file mode 100644 index 8a4b5360f..000000000 --- a/pkg/interface/src/views/apps/publish/components/lib/new.tsx +++ /dev/null @@ -1,103 +0,0 @@ -import React, { useCallback } from "react"; -import { Box, ManagedTextInputField as Input, Col } from "@tlon/indigo-react"; -import { Formik, Form } from "formik"; -import * as Yup from "yup"; -import GlobalApi from "~/logic/api/global"; -import { AsyncButton } from "~/views/components/AsyncButton"; -import { FormError } from "~/views/components/FormError"; -import { RouteComponentProps } from "react-router-dom"; -import { stringToSymbol } from "~/logic/lib/util"; -import GroupSearch from "~/views/components/GroupSearch"; -import { Associations } from "~/types/metadata-update"; -import { useWaitForProps } from "~/logic/lib/useWaitForProps"; -import { Notebooks } from "~/types/publish-update"; -import { Groups } from "~/types/group-update"; - -interface FormSchema { - name: string; - description: string; - group?: string; -} - -const formSchema = Yup.object({ - name: Yup.string().required("Notebook must have a name"), - description: Yup.string(), - group: Yup.string(), -}); - -interface NewScreenProps { - api: GlobalApi; - associations: Associations; - notebooks: Notebooks; - groups: Groups; -} - -export function NewScreen(props: NewScreenProps & RouteComponentProps) { - const { history } = props; - - const waiter = useWaitForProps(props, 5000); - - const onSubmit = async (values: FormSchema, actions) => { - const bookId = stringToSymbol(values.name); - try { - const { name, description, group } = values; - await props.api.publish.newBook(bookId, name, description, group); - await waiter((p) => !!p?.notebooks?.[`~${window.ship}`]?.[bookId]); - if (!group) { - await waiter((p) => !!p?.groups?.[`/ship/~${window.ship}/${bookId}`]); - } - actions.setStatus({ success: null }); - history.push(`/~publish/notebook/~${window.ship}/${bookId}`); - } catch (e) { - console.error(e); - actions.setStatus({ error: "Notebook creation failed" }); - } - }; - return ( - - New Notebook - -
- - - - - - - - Create Notebook - - - - -
-
- - ); -} - -export default NewScreen; diff --git a/pkg/interface/src/views/apps/publish/components/lib/new-post.tsx b/pkg/interface/src/views/apps/publish/components/new-post.tsx similarity index 100% rename from pkg/interface/src/views/apps/publish/components/lib/new-post.tsx rename to pkg/interface/src/views/apps/publish/components/new-post.tsx diff --git a/pkg/interface/src/views/apps/publish/components/skeleton.tsx b/pkg/interface/src/views/apps/publish/components/skeleton.tsx deleted file mode 100644 index cac1bf61d..000000000 --- a/pkg/interface/src/views/apps/publish/components/skeleton.tsx +++ /dev/null @@ -1,133 +0,0 @@ -import React, { useRef, SyntheticEvent, useEffect } from "react"; -import { Box, Center } from "@tlon/indigo-react"; -import { Sidebar } from "./lib/Sidebar"; -import ErrorBoundary from "~/views/components/ErrorBoundary"; -import { Notebooks } from "~/types/publish-update"; -import { Rolodex } from "~/types/contact-update"; -import { Invites } from "~/types/invite-update"; -import GlobalApi from "~/logic/api/global"; -import { Associations } from "~/types/metadata-update"; -import { RouteComponentProps } from "react-router-dom"; - -type SkeletonProps = RouteComponentProps<{ - ship?: string; - notebook?: string; - noteId?: string; -}> & { - notebooks: Notebooks; - invites: Invites; - associations: Associations; - contacts: Rolodex; - api: GlobalApi; - children: React.ReactNode; -}; - -export function Skeleton(props: SkeletonProps) { - const { api, notebooks } = props; - const { ship, notebook, noteId } = props.match.params; - const scrollRef = useRef(); - - const path = - (ship && - notebook && - `${props.match.params.ship}/${props.match.params.notebook}`) || - undefined; - - const onScroll = (e: React.UIEvent) => { - const { scrollHeight, scrollTop, clientHeight } = e.target as HTMLDivElement; - const distanceFromBottom = scrollHeight - scrollTop - clientHeight; - if (noteId && notebook && ship) { - const note = notebooks?.[ship]?.[notebook]?.notes?.[noteId]; - if (!note || !note.comments) { - return; - } - const loadedComments = note.comments?.length; - const fullyLoaded = note["num-comments"] === loadedComments; - if (distanceFromBottom < 40) { - if (!fullyLoaded) { - api.publish.fetchCommentsPage( - ship, - notebook, - noteId, - loadedComments, - 30 - ); - } - if (!note.read) { - api.publish.publishAction({ - read: { - who: ship.slice(1), - book: notebook, - note: noteId, - }, - }); - } - } - } else if (notebook && ship) { - } - }; - - // send read immediately if we aren't in a scrollable container - useEffect(() => { - if(!(noteId && notebook && ship)) { - return; - } - const note = notebooks?.[ship]?.[notebook]?.notes?.[noteId]; - setTimeout(() => { - const { clientHeight, scrollHeight } = scrollRef.current; - const isScrolling = clientHeight < scrollHeight; - if(!isScrolling && note) { - api.publish.publishAction({ - read: { - who: ship.slice(1), - book: notebook, - note: noteId, - }, - }); - } - - }, 1500); - }, [noteId, notebook, ship, notebooks]) - - const hideSidebar = path || props.location.pathname.endsWith('/new') - - const panelDisplay = !hideSidebar ? ["none", "block"] : "block"; - return ( - - - - - ); -} - -export default Skeleton;