feat: tag project api, reactive story updating

This commit is contained in:
MTG2000
2022-10-04 10:41:09 +03:00
parent bd44334f69
commit c7e9acd948
5 changed files with 29 additions and 5 deletions

View File

@@ -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,

View File

@@ -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 &&

View File

@@ -12,6 +12,12 @@ mutation createStory($data: StoryInputType) {
is_published
type
cover_image
project {
id
title
hashtag
thumbnail_image
}
# comments_count
}
}

View File

@@ -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,
},
});

View File

@@ -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
}
}
}
`;