mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 17:41:33 +03:00
publish: refactor for new sidebar
This commit is contained in:
parent
62e2dc6cb0
commit
8fe45b63b1
38
pkg/interface/src/views/apps/publish/PublishResource.tsx
Normal file
38
pkg/interface/src/views/apps/publish/PublishResource.tsx
Normal file
@ -0,0 +1,38 @@
|
||||
import React from "react";
|
||||
|
||||
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";
|
||||
|
||||
type PublishResourceProps = StoreState & {
|
||||
association: Association;
|
||||
api: GlobalApi;
|
||||
baseUrl: string;
|
||||
} & RouteComponentProps;
|
||||
|
||||
export function PublishResource(props: PublishResourceProps) {
|
||||
const { association, api, baseUrl, notebooks } = props;
|
||||
const appPath = association["app-path"];
|
||||
const [, ship, book] = appPath.split("/");
|
||||
const notebook = notebooks[ship][book];
|
||||
const notebookContacts = props.contacts[association["group-path"]];
|
||||
|
||||
return (
|
||||
<NotebookRoutes
|
||||
api={api}
|
||||
ship={ship}
|
||||
book={book}
|
||||
contacts={props.contacts}
|
||||
groups={props.groups}
|
||||
notebook={notebook}
|
||||
notebookContacts={notebookContacts}
|
||||
rootUrl={baseUrl}
|
||||
baseUrl={`${baseUrl}/resource/publish/${ship}/${book}`}
|
||||
history={props.history}
|
||||
match={props.match}
|
||||
location={props.location}
|
||||
/>
|
||||
);
|
||||
}
|
@ -24,6 +24,7 @@ interface NoteProps {
|
||||
api: GlobalApi;
|
||||
hideAvatars: boolean;
|
||||
hideNicknames: boolean;
|
||||
rootUrl?: string;
|
||||
}
|
||||
|
||||
export function Note(props: NoteProps & RouteComponentProps) {
|
||||
@ -33,12 +34,12 @@ export function Note(props: NoteProps & RouteComponentProps) {
|
||||
api.publish.fetchNote(ship, book, noteId);
|
||||
}, [ship, book, noteId]);
|
||||
|
||||
const baseUrl = `/~publish/notebook/${props.ship}/${props.book}`;
|
||||
const rootUrl = props.rootUrl || `/~publish/notebook/${props.ship}/${props.book}`;
|
||||
|
||||
const deletePost = async () => {
|
||||
setDeleting(true);
|
||||
await api.publish.delNote(ship.slice(1), book, noteId);
|
||||
props.history.push(baseUrl);
|
||||
props.history.push(rootUrl);
|
||||
};
|
||||
|
||||
const comments = note?.comments || [];
|
||||
@ -77,7 +78,7 @@ export function Note(props: NoteProps & RouteComponentProps) {
|
||||
gridRowGap={4}
|
||||
mx="auto"
|
||||
>
|
||||
<Link to={baseUrl}>
|
||||
<Link to={rootUrl}>
|
||||
<Text>{"<- Notebook Index"}</Text>
|
||||
</Link>
|
||||
<Col>
|
||||
|
@ -54,7 +54,7 @@ export function NoteNavigation(props: NoteNavigationProps) {
|
||||
}
|
||||
|
||||
if (next) {
|
||||
nextUrl = `/~publish/notebook/${props.ship}/${props.book}/note/${props.nextId}`;
|
||||
nextUrl = `${props.prevId}`;
|
||||
nextComponent = (
|
||||
<NavigationItem
|
||||
title={next.title}
|
||||
@ -64,7 +64,7 @@ export function NoteNavigation(props: NoteNavigationProps) {
|
||||
);
|
||||
}
|
||||
if (prev) {
|
||||
prevUrl = `/~publish/notebook/${props.ship}/${props.book}/note/${props.prevId}`;
|
||||
prevUrl = `${props.prevId}`;
|
||||
prevComponent = (
|
||||
<NavigationItem
|
||||
title={prev.title}
|
||||
|
@ -38,7 +38,7 @@ export function NotePreview(props: NotePreviewProps) {
|
||||
}
|
||||
const date = moment(note["date-created"]).fromNow();
|
||||
//const popout = props.popout ? "popout/" : "";
|
||||
const url = `/~publish/notebook/${props.host}/${props.book}/note/${note["note-id"]}`;
|
||||
const url = `${props.book}/note/${note["note-id"]}`;
|
||||
|
||||
return (
|
||||
<Link to={url}>
|
||||
|
@ -16,12 +16,16 @@ interface NoteRoutesProps {
|
||||
notebook: Notebook;
|
||||
contacts: Contacts;
|
||||
api: GlobalApi;
|
||||
hideNicknames: boolean;
|
||||
hideAvatars: boolean;
|
||||
baseUrl?: string;
|
||||
rootUrl?: string;
|
||||
}
|
||||
|
||||
export function NoteRoutes(props: NoteRoutesProps & RouteComponentProps) {
|
||||
const { ship, book, noteId } = props;
|
||||
|
||||
const baseUrl = `/~publish/notebook/${ship}/${book}/note/${noteId}`;
|
||||
const baseUrl = props.baseUrl || `/~publish/notebook/${ship}/${book}/note/${noteId}`;
|
||||
|
||||
const relativePath = (path: string) => `${baseUrl}${path}`;
|
||||
return (
|
||||
|
@ -38,6 +38,8 @@ interface NotebookProps {
|
||||
contacts: Rolodex;
|
||||
groups: Groups;
|
||||
hideNicknames: boolean;
|
||||
baseUrl: string;
|
||||
rootUrl: string;
|
||||
}
|
||||
|
||||
export function Notebook(props: NotebookProps & RouteComponentProps) {
|
||||
@ -56,6 +58,8 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
|
||||
const notes = notebook?.notes || {};
|
||||
const showNickname = contact?.nickname && !props.hideNicknames;
|
||||
|
||||
const relativePath = (p: string) => props.baseUrl + p;
|
||||
|
||||
return (
|
||||
<Box
|
||||
pt={4}
|
||||
@ -68,7 +72,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
|
||||
gridColumnGap={3}
|
||||
>
|
||||
<Box display={["block", "none"]} gridColumn={["1/2", "1/3"]}>
|
||||
<Link to="/~publish">{"<- All Notebooks"}</Link>
|
||||
<Link to={props.rootUrl}>{"<- All Notebooks"}</Link>
|
||||
</Box>
|
||||
<Box>
|
||||
<Text> {notebook?.title}</Text>
|
||||
@ -80,7 +84,7 @@ export function Notebook(props: NotebookProps & RouteComponentProps) {
|
||||
</Box>
|
||||
<Row justifyContent={["flex-start", "flex-end"]}>
|
||||
{isWriter && (
|
||||
<Link to={`/~publish/notebook/${ship}/${book}/new`}>
|
||||
<Link to={relativePath('/new')}>
|
||||
<Button primary border>
|
||||
New Post
|
||||
</Button>
|
||||
|
@ -10,6 +10,7 @@ interface NotebookPostsProps {
|
||||
notes: Notes;
|
||||
host: string;
|
||||
book: string;
|
||||
baseUrl: string;
|
||||
hideNicknames?: boolean;
|
||||
}
|
||||
|
||||
@ -30,6 +31,7 @@ export function NotebookPosts(props: NotebookPostsProps) {
|
||||
note={note}
|
||||
contact={props.contacts[note.author.substr(1)]}
|
||||
hideNicknames={props.hideNicknames}
|
||||
baseUrl={props.baseUrl}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
@ -8,19 +8,18 @@ import { Groups } from "../../../../types/group-update";
|
||||
import { Contacts, Rolodex } from "../../../../types/contact-update";
|
||||
import Notebook from "./Notebook";
|
||||
import NewPost from "./new-post";
|
||||
import { NoteRoutes } from './NoteRoutes';
|
||||
import { NoteRoutes } from "./NoteRoutes";
|
||||
|
||||
interface NotebookRoutesProps {
|
||||
api: GlobalApi;
|
||||
ship: string;
|
||||
book: string;
|
||||
notes: any;
|
||||
notebook: INotebook;
|
||||
notebookContacts: Contacts;
|
||||
contacts: Rolodex;
|
||||
groups: Groups;
|
||||
hideAvatars: boolean;
|
||||
hideNicknames: boolean;
|
||||
baseUrl?: string;
|
||||
rootUrl?: string;
|
||||
}
|
||||
|
||||
export function NotebookRoutes(
|
||||
@ -33,8 +32,8 @@ export function NotebookRoutes(
|
||||
api.publish.fetchNotebook(ship, book);
|
||||
}, [ship, book]);
|
||||
|
||||
|
||||
const baseUrl = `/~publish/notebook/${ship}/${book}`;
|
||||
const baseUrl = props.baseUrl || `/~publish/notebook/${ship}/${book}`;
|
||||
const rootUrl = props.rootUrl || '/~publish';
|
||||
|
||||
const relativePath = (path: string) => `${baseUrl}${path}`;
|
||||
return (
|
||||
@ -43,7 +42,7 @@ export function NotebookRoutes(
|
||||
path={baseUrl}
|
||||
exact
|
||||
render={(routeProps) => {
|
||||
return <Notebook {...props} />;
|
||||
return <Notebook {...props} rootUrl={rootUrl} baseUrl={baseUrl} />;
|
||||
}}
|
||||
/>
|
||||
<Route
|
||||
@ -55,6 +54,7 @@ export function NotebookRoutes(
|
||||
book={book}
|
||||
ship={ship}
|
||||
notebook={notebook}
|
||||
baseUrl={baseUrl}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
@ -63,8 +63,11 @@ export function NotebookRoutes(
|
||||
render={(routeProps) => {
|
||||
const { noteId } = routeProps.match.params;
|
||||
const note = notebook?.notes[noteId];
|
||||
const noteUrl = relativePath(`/note/${noteId}`);
|
||||
return (
|
||||
<NoteRoutes
|
||||
rootUrl={baseUrl}
|
||||
baseUrl={noteUrl}
|
||||
api={api}
|
||||
book={book}
|
||||
ship={ship}
|
||||
@ -72,8 +75,8 @@ export function NotebookRoutes(
|
||||
notebook={notebook}
|
||||
note={note}
|
||||
contacts={notebookContacts}
|
||||
hideAvatars={props.hideAvatars}
|
||||
hideNicknames={props.hideNicknames}
|
||||
hideAvatars={false}
|
||||
hideNicknames={false}
|
||||
{...routeProps}
|
||||
/>
|
||||
);
|
||||
|
@ -12,6 +12,7 @@ interface NewPostProps {
|
||||
book: string;
|
||||
ship: string;
|
||||
notebook: Notebook;
|
||||
baseUrl: string;
|
||||
}
|
||||
|
||||
export default function NewPost(props: NewPostProps & RouteComponentProps) {
|
||||
@ -42,7 +43,7 @@ export default function NewPost(props: NewPostProps & RouteComponentProps) {
|
||||
await waiter((p) => {
|
||||
return !!p?.notebook?.notes[noteId];
|
||||
});
|
||||
history.push(`/~publish/notebook/${ship}/${book}/note/${noteId}`);
|
||||
history.push(`${props.baseUrl}/note/${noteId}`);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
actions.setStatus({ error: "Posting note failed" });
|
||||
|
Loading…
Reference in New Issue
Block a user