Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling fix/latest-papers-link into develop #670

Merged
merged 6 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dicty-frontpage/src/app/layout/FrontPageApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const FrontPageApp = () => {
<HeaderWithAuth clientRouter={frontpageRouter} />
<NavbarWithAuth theme={navTheme} />
<main className={classes.main}>
<Container maxWidth="lg">
<Container maxWidth="xl">
<ErrorBoundary>
<RouterProvider router={frontpageRouter} />
</ErrorBoundary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ const LatestPaperItem = ({ data }: LatestPaperItemProperties) => {
<li className={listItem}>
<Box className={mainContent}>
<Typography className={mainContent}>
<Link
className={link}
to={`/publication/${
import.meta.env.VITE_PUBLICATION_URL
}/${pubmedId}`}>
<Link className={link} to={`/publication/${pubmedId}`}>
{`${authors}. (${date}). `}
</Link>
{`${title} `}
Expand Down
4 changes: 2 additions & 2 deletions apps/stock-center/src/pages/index/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CatalogLinks,
FileLinks,
} from "@dictybase/ui-dsc"
import { EditView, LoadingDisplay, OtherError } from "@dictybase/ui-common"
import { EditEditor, LoadingDisplay, OtherError } from "@dictybase/ui-common"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { match, P } from "ts-pattern"
import { ACCESS, useTokenAndUser } from "auth"
Expand All @@ -33,7 +33,7 @@ const EditHomepage = () => {
.with(
{ data: { contentBySlug: P.select({ content: P.string }) } },
(content) => (
<EditView
<EditEditor
data={content}
userId={user?.email as string}
token={token as string}
Expand Down
8 changes: 6 additions & 2 deletions apps/stock-center/src/pages/index/editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
CatalogLinks,
FileLinks,
} from "@dictybase/ui-dsc"
import { EditableView, LoadingDisplay, OtherError } from "@dictybase/ui-common"
import {
EditableEditor,
LoadingDisplay,
OtherError,
} from "@dictybase/ui-common"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { match, P } from "ts-pattern"
import { ACCESS } from "auth"
Expand All @@ -30,7 +34,7 @@ const EditableHomepage = () => {
{match(result)
.with(
{ data: { contentBySlug: P.select({ content: P.string }) } },
(content) => <EditableView data={content} />,
(content) => <EditableEditor data={content} />,
)
.with({ loading: true }, () => <LoadingDisplay rows={4} />)
.with({ error: P.not(undefined) }, () => <OtherError />)
Expand Down
4 changes: 2 additions & 2 deletions apps/stock-center/src/pages/index/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CatalogLinks,
FileLinks,
} from "@dictybase/ui-dsc"
import { ContentView, LoadingDisplay, OtherError } from "@dictybase/ui-common"
import { LoadingDisplay, OtherError, ContentEditor } from "@dictybase/ui-common"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { match, P } from "ts-pattern"
import { ACCESS } from "auth"
Expand All @@ -31,7 +31,7 @@ const ShowHomepage = () => {
{match(result)
.with(
{ data: { contentBySlug: P.select({ content: P.string }) } },
(content) => <ContentView data={content} />,
(content) => <ContentEditor data={content} />,
)
.with({ loading: true }, () => <LoadingDisplay rows={4} />)
.with({ error: P.not(undefined) }, () => <OtherError />)
Expand Down
4 changes: 2 additions & 2 deletions apps/stock-center/src/pages/index/show.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CatalogLinks,
FileLinks,
} from "@dictybase/ui-dsc"
import { ContentView, LoadingDisplay, OtherError } from "@dictybase/ui-common"
import { LoadingDisplay, OtherError, ContentEditor } from "@dictybase/ui-common"
import { useContentBySlugQuery } from "dicty-graphql-schema"
import { match, P } from "ts-pattern"
import { ACCESS } from "auth"
Expand All @@ -31,7 +31,7 @@ const ShowHomepage = () => {
{match(result)
.with(
{ data: { contentBySlug: P.select({ content: P.string }) } },
(content) => <ContentView data={content} />,
(content) => <ContentEditor data={content} />,
)
.with({ loading: true }, () => <LoadingDisplay rows={4} />)
.with({ error: P.not(undefined) }, () => <OtherError />)
Expand Down
66 changes: 66 additions & 0 deletions packages/ui-common/src/EditablePages/AddPageEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { useNavigate } from "react-router-dom"
import { useCreateContentMutation } from "dicty-graphql-schema"
import { Editor } from "editor"
import { createAddPageToolbar } from "./createAddPageToolbar"

type AddPageEditorProperties = {
userId: string
token: string
namespace: string
slug: string
contentPath: string
}

/**
* This is the view component so an authorized user can add a new page.
*/
const AddPageEditor = ({
userId,
token,
namespace,
slug,
contentPath,
}: AddPageEditorProperties) => {
const navigate = useNavigate()
const [createContent] = useCreateContentMutation({
context: {
headers: {
Authorization: `Bearer ${token}`,
},
},
})

const handleSaveClick = async (value: any) => {
try {
await createContent({
variables: {
input: {
name: slug,
// eslint-disable-next-line camelcase
created_by: userId,
content: value,
namespace,
},
},
})
navigate("../editable", { relative: "path" })
} catch {
// Toggle some error notification
}
}

const handleCancelClick = () => {
navigate("../notfoundauth", { relative: "path" })
}

return (
<Editor
toolbar={createAddPageToolbar(contentPath)}
handleSave={handleSaveClick}
handleCancel={handleCancelClick}
editable
/>
)
}

export { AddPageEditor }
57 changes: 12 additions & 45 deletions packages/ui-common/src/EditablePages/AddPageView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useNavigate } from "react-router-dom"
import { useCreateContentMutation } from "dicty-graphql-schema"
import { Editor } from "editor"
import { createAddPageToolbar } from "./createAddPageToolbar"
import { Container } from "@material-ui/core"
import { AddPageEditor } from "./AddPageEditor"

type AddPageViewProperties = {
userId: string
Expand All @@ -20,47 +18,16 @@ const AddPageView = ({
namespace,
slug,
contentPath,
}: AddPageViewProperties) => {
const navigate = useNavigate()
const [createContent] = useCreateContentMutation({
context: {
headers: {
Authorization: `Bearer ${token}`,
},
},
})

const handleSaveClick = async (value: any) => {
try {
await createContent({
variables: {
input: {
name: slug,
// eslint-disable-next-line camelcase
created_by: userId,
content: value,
namespace,
},
},
})
navigate("../editable", { relative: "path" })
} catch {
// Toggle some error notification
}
}

const handleCancelClick = () => {
navigate("../notfoundauth", { relative: "path" })
}

return (
<Editor
toolbar={createAddPageToolbar(contentPath)}
handleSave={handleSaveClick}
handleCancel={handleCancelClick}
editable
}: AddPageViewProperties) => (
<Container>
<AddPageEditor
userId={userId}
token={token}
contentPath={contentPath}
slug={slug}
namespace={namespace}
/>
)
}
</Container>
)

export { AddPageView }
20 changes: 20 additions & 0 deletions packages/ui-common/src/EditablePages/ContentEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { type ContentBySlugQuery } from "dicty-graphql-schema"
import { Editor } from "editor"

type ContentEditorProperties = {
data: NonNullable<ContentBySlugQuery["contentBySlug"]>
}

/**
* A React component that renders the a view for editable content pages.
*
* @returns The rendered ContentView component.
*/
const ContentEditor = ({ data }: ContentEditorProperties) => (
<Editor
editable={false}
content={{ storageKey: data.slug, editorState: data.content }}
/>
)

export { ContentEditor }
10 changes: 5 additions & 5 deletions packages/ui-common/src/EditablePages/ContentView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Container } from "@material-ui/core"
import { type ContentBySlugQuery } from "dicty-graphql-schema"
import { Editor } from "editor"
import { ContentEditor } from "./ContentEditor"

type ContentViewProperties = {
data: NonNullable<ContentBySlugQuery["contentBySlug"]>
Expand All @@ -11,10 +12,9 @@ type ContentViewProperties = {
* @returns The rendered ContentView component.
*/
const ContentView = ({ data }: ContentViewProperties) => (
<Editor
editable={false}
content={{ storageKey: data.slug, editorState: data.content }}
/>
<Container>
<ContentEditor data={data} />
</Container>
)

export { ContentView }
63 changes: 63 additions & 0 deletions packages/ui-common/src/EditablePages/EditEditor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* eslint-disable camelcase */
import { useNavigate } from "react-router-dom"
import {
type ContentBySlugQuery,
useUpdateContentMutation,
} from "dicty-graphql-schema"
import { Editor } from "editor"
import { createToolbarWrapper } from "./createToolbarWrapper"

type EditEditorProperties = {
data: NonNullable<ContentBySlugQuery["contentBySlug"]>
userId: string
token: string
}

const EditEditor = ({ data, userId, token }: EditEditorProperties) => {
const { id, updated_by, updated_at, slug, content } = data
const [updateContent] = useUpdateContentMutation({
context: {
headers: {
Authorization: `Bearer ${token}`,
},
},
})
const navigate = useNavigate()
const onSave = async (contentValue: string) => {
try {
await updateContent({
variables: {
input: {
id,
updated_by: userId,
content: contentValue,
},
},
})
navigate("../editable", { relative: "path" })
} catch {
// Toggle some error notification
}
}
const onCancel = () => {
navigate("../editable", { relative: "path" })
}

const Toolbar = createToolbarWrapper(
updated_at,
updated_by.first_name,
updated_by.last_name,
)

return (
<Editor
toolbar={Toolbar}
handleSave={onSave}
handleCancel={onCancel}
editable
content={{ storageKey: slug, editorState: content }}
/>
)
}

export { EditEditor }
Loading
Loading