mirror of
https://github.com/aljazceru/landscape-template.git
synced 2026-02-23 15:34:21 +01:00
feat: tag project api, reactive story updating
This commit is contained in:
@@ -117,7 +117,7 @@ const Story = objectType({
|
||||
t.field('project', {
|
||||
type: "Project",
|
||||
resolve(parent) {
|
||||
return null
|
||||
return prisma.story.findUnique({ where: { id: parent.id } }).project();
|
||||
}
|
||||
})
|
||||
|
||||
@@ -429,7 +429,7 @@ const createStory = extendType({
|
||||
type: 'Story',
|
||||
args: { data: StoryInputType },
|
||||
async resolve(_root, args, ctx) {
|
||||
const { id, title, body, cover_image, tags, is_published } = args.data;
|
||||
const { id, title, body, project_id, cover_image, tags, is_published } = args.data;
|
||||
const user = await getUserByPubKey(ctx.userPubKey);
|
||||
|
||||
// Do some validation
|
||||
@@ -536,6 +536,11 @@ const createStory = extendType({
|
||||
cover_image: '',
|
||||
excerpt,
|
||||
is_published: was_published || is_published,
|
||||
project: {
|
||||
connect: {
|
||||
id: project_id,
|
||||
}
|
||||
},
|
||||
tags: {
|
||||
connectOrCreate:
|
||||
tags.map(tag => {
|
||||
@@ -581,6 +586,11 @@ const createStory = extendType({
|
||||
}
|
||||
})
|
||||
},
|
||||
project: {
|
||||
connect: {
|
||||
id: project_id,
|
||||
}
|
||||
},
|
||||
user: {
|
||||
connect: {
|
||||
id: user.id,
|
||||
|
||||
@@ -203,8 +203,8 @@ export default function StoryForm(props: Props) {
|
||||
disabled={loading}
|
||||
>
|
||||
{props.isUpdating ?
|
||||
"Update" :
|
||||
"Publish"
|
||||
(loading ? "Updating..." : "Update") :
|
||||
(loading ? "Publishing..." : "Publish")
|
||||
}
|
||||
</Button>
|
||||
{!props.isPublished &&
|
||||
|
||||
@@ -12,6 +12,12 @@ mutation createStory($data: StoryInputType) {
|
||||
is_published
|
||||
type
|
||||
cover_image
|
||||
project {
|
||||
id
|
||||
title
|
||||
hashtag
|
||||
thumbnail_image
|
||||
}
|
||||
# comments_count
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ function CreateStoryPage() {
|
||||
story: state.staging.story || storageService.get()
|
||||
}))
|
||||
|
||||
|
||||
const formMethods = useForm<CreateStoryType>({
|
||||
resolver: yupResolver(schema) as Resolver<CreateStoryType>,
|
||||
shouldFocusError: false,
|
||||
@@ -66,6 +67,7 @@ function CreateStoryPage() {
|
||||
tags: story?.tags ?? [],
|
||||
body: story?.body ?? '',
|
||||
is_published: story?.is_published ?? false,
|
||||
project: story?.project,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -933,7 +933,7 @@ export type CreateStoryMutationVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type CreateStoryMutation = { __typename?: 'Mutation', createStory: { __typename?: 'Story', id: number, title: string, createdAt: any, body: string, votes_count: number, is_published: boolean | null, type: string, cover_image: string | null, tags: Array<{ __typename?: 'Tag', id: number, title: string }> } | null };
|
||||
export type CreateStoryMutation = { __typename?: 'Mutation', createStory: { __typename?: 'Story', id: number, title: string, createdAt: any, body: string, votes_count: number, is_published: boolean | null, type: string, cover_image: string | null, tags: Array<{ __typename?: 'Tag', id: number, title: string }>, project: { __typename?: 'Project', id: number, title: string, hashtag: string, thumbnail_image: string } | null } | null };
|
||||
|
||||
export type DeleteStoryMutationVariables = Exact<{
|
||||
deleteStoryId: Scalars['Int'];
|
||||
@@ -1722,6 +1722,12 @@ export const CreateStoryDocument = gql`
|
||||
is_published
|
||||
type
|
||||
cover_image
|
||||
project {
|
||||
id
|
||||
title
|
||||
hashtag
|
||||
thumbnail_image
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user