Skip to content

Commit

Permalink
Merge pull request #10 from Q42/fix/make-new-pages-unpublished
Browse files Browse the repository at this point in the history
Make new pages unpublished
  • Loading branch information
djohalo2 authored Dec 21, 2023
2 parents 4c16450 + 4ef887e commit 7242bb8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
10 changes: 6 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"@sanity/icons": "^2.7.0",
"@sanity/incompatible-plugin": "^1.0.4",
"@sanity/ui": "^1.9.3",
"@sanity/uuid": "^3.0.2",
"lodash": "^4.17.21",
"next-sanity": "^7.0.4",
"sanity-plugin-utils": "^1.6.2"
Expand Down
2 changes: 2 additions & 0 deletions src/components/PageTreeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { usePageTreeConfig } from '../hooks/usePageTreeConfig';
import { useClient } from 'sanity';
import { useRouter } from 'sanity/router';
import styled from 'styled-components';
import { generateDraftId } from '../helpers/uuid';

export type PageTreeEditorProps = {
pageTree: PageTreeItem[];
Expand Down Expand Up @@ -111,6 +112,7 @@ export const PageTreeEditor = ({

const addRootPage = useCallback(async () => {
const doc = await client.create({
_id: generateDraftId(),
_type: config.rootSchemaType,
});
const path = resolveIntentLink('edit', { id: doc._id, type: doc._type });
Expand Down
2 changes: 2 additions & 0 deletions src/components/PageTreeViewItemActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useRouter } from 'sanity/router';
import { usePageTreeConfig } from '../hooks/usePageTreeConfig';
import { PageTreeItem } from '../types';
import { getLanguageFromConfig } from '../helpers/config';
import { generateDraftId } from '../helpers/uuid';

export type PageTreeViewItemActionsProps = {
page: PageTreeItem;
Expand All @@ -23,6 +24,7 @@ export const PageTreeViewItemActions = ({ page, onActionOpen, onActionClose }: P
const onAdd = async (type: string) => {
const language = getLanguageFromConfig(config);
const doc = await client.create({
_id: generateDraftId(),
_type: type,
parent: config.rootSchemaType === type ? undefined : { _type: 'reference', _ref: page._id },
...(language ? { [language]: page[language] } : {}),
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/uuid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { uuid } from '@sanity/uuid';

export const generateDraftId = () => `drafts.${uuid()}`;

0 comments on commit 7242bb8

Please sign in to comment.