-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add page stats * improve add contributor flow * update navbar links + fixes * pages list init * working pages list * file organization * add page deletion and creation flows
- Loading branch information
Showing
27 changed files
with
606 additions
and
124 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IconCheck, IconX } from '@tabler/icons-react'; | ||
|
||
import type { IconType } from '@/util/iconType'; | ||
import { clx } from '@/util/classConcat'; | ||
|
||
export default function BooleanStatus({ | ||
value, | ||
className, | ||
}: { | ||
value: boolean; | ||
className?: string; | ||
}) { | ||
const iconProps: Parameters<IconType>[0] = { | ||
stroke: 1, | ||
}; | ||
return ( | ||
<> | ||
<div className={clx(className)} data-true={value || null}> | ||
{value ? <IconCheck {...iconProps} /> : <IconX {...iconProps} />} | ||
</div> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { IconType } from '@/util/iconType'; | ||
|
||
export type NavLinkType = { | ||
href: string; | ||
text: React.ReactNode; | ||
icon?: IconType; | ||
}; |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use server'; | ||
|
||
import { getUser } from '@/app/_ctx/user/provider'; | ||
import { graphError, graphql } from '@/query/graphql'; | ||
import { graphAuthServer } from '@/query/graphql.server'; | ||
import { ResultOf } from '@graphql-typed-document-node/core'; | ||
|
||
const NEW_CMS_PAGE = graphql(` | ||
mutation CmsPageCreate( | ||
$title: String! | ||
$secure: Boolean! | ||
$publish: Boolean! | ||
$contributorAdd: String | ||
) { | ||
cmsPageCreate( | ||
title: $title | ||
secure: $secure | ||
publish: $publish | ||
contributorAdd: $contributorAdd | ||
) { | ||
id | ||
} | ||
} | ||
`); | ||
type CmsPageOut = ResultOf<typeof NEW_CMS_PAGE>['cmsPageCreate']; | ||
|
||
export async function createNewPage() { | ||
const output: { data: CmsPageOut | null; error: string | null } = { | ||
data: null, | ||
error: null, | ||
}; | ||
try { | ||
const user = (await getUser()) || null; | ||
|
||
const data = await graphAuthServer(NEW_CMS_PAGE, { | ||
title: '', | ||
secure: true, | ||
publish: false, | ||
contributorAdd: user?.id, | ||
}).catch((err) => { | ||
throw graphError(err?.response?.errors); | ||
}); | ||
if (!data?.cmsPageCreate) throw 'SERVER_ERROR'; | ||
|
||
output.data = data.cmsPageCreate; | ||
} catch (error) { | ||
output.error = (error as string) || null; | ||
} finally { | ||
return output; | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...app/cms/page/_components/ViewPageLink.tsx → ...pp/cms/pages/_components/ViewPageLink.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
client/src/app/cms/pages/_components/home/NewPageButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useTransition } from 'react'; | ||
|
||
import { ActionIcon } from '@mantine/core'; | ||
import { IconPlus } from '@tabler/icons-react'; | ||
import { notifications } from '@mantine/notifications'; | ||
|
||
import { createNewPage } from '../../_actions/create'; | ||
import { revalidatePagesList } from './PagesContainer'; | ||
|
||
export default function NewPageButton() { | ||
const [isLoading, loading] = useTransition(); | ||
function createPage() { | ||
loading(async () => { | ||
const { data, error } = await createNewPage(); | ||
if (error || !data) { | ||
notifications.show({ message: 'An error occurred.' }); | ||
return; | ||
} | ||
|
||
revalidatePagesList(); | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<ActionIcon | ||
onClick={createPage} | ||
loading={isLoading} | ||
color="slate" | ||
variant="light" | ||
size="sm" | ||
> | ||
<IconPlus /> | ||
</ActionIcon> | ||
</> | ||
); | ||
} |
58 changes: 58 additions & 0 deletions
58
client/src/app/cms/pages/_components/home/PagesContainer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use client'; | ||
|
||
import { queryClient, useGraphQuery } from '@/query/query'; | ||
import { graphql } from '@/query/graphql'; | ||
import type { ResultOf } from '@graphql-typed-document-node/core'; | ||
|
||
import { SkeletonProvider } from '@/app/_ctx/skeleton/context'; | ||
import PagesList from './PagesList'; | ||
import NewPageButton from './NewPageButton'; | ||
|
||
const GET_PAGES_QUERY = graphql(` | ||
query CmsPages { | ||
cmsPages { | ||
id | ||
slug | ||
title | ||
secure | ||
publish | ||
contributors { | ||
id | ||
} | ||
timestamp { | ||
created | ||
updated | ||
} | ||
} | ||
} | ||
`); | ||
export type PagesType = ResultOf<typeof GET_PAGES_QUERY>['cmsPages']; | ||
export const revalidatePagesList = () => | ||
queryClient.invalidateQueries({ queryKey: [GET_PAGES_QUERY, {}] }); | ||
|
||
// COMPONENT | ||
export default function PagesContainer() { | ||
const pagesQuery = useGraphQuery(GET_PAGES_QUERY, {}); | ||
const pages = pagesQuery.data?.cmsPages ?? null; | ||
|
||
return ( | ||
<> | ||
<div className="mx-auto flex max-w-screen-xl flex-col gap-6 p-6"> | ||
<SkeletonProvider ready={!pagesQuery.isPending}> | ||
<div className="t"> | ||
<h3 className="py-4 text-lg">Pages</h3> | ||
<PagesList pages={pages} /> | ||
</div> | ||
|
||
<div className="t"> | ||
<div className="flex flex-row items-center justify-between"> | ||
<h3 className="py-4 text-lg">Unused (empty) pages</h3> | ||
<NewPageButton /> | ||
</div> | ||
<PagesList pages={pages} unused /> | ||
</div> | ||
</SkeletonProvider> | ||
</div> | ||
</> | ||
); | ||
} |
Oops, something went wrong.