added book details, update, delete. fixes
This commit is contained in:
parent
d1da980501
commit
b5738c610d
12 changed files with 290 additions and 16 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { gql } from '@apollo/client';
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { BookOverviewTabs } from '@app/client/components/BookOverviewTabs';
|
||||
import { Pagination } from '@app/client/components/Pagination';
|
||||
import { reviewFragment } from '@app/client/fragments';
|
||||
|
|
@ -6,7 +6,7 @@ import { useIdentity } from '@app/client/hooks/identity';
|
|||
import { usePaginatedQuery } from '@app/client/hooks/usePaginatedQuery';
|
||||
import { useToastMutation } from '@app/client/hooks/useToastMutation';
|
||||
import { Skeleton, Stack, Text } from '@chakra-ui/react';
|
||||
import { BookReviewCreateMutation, BookReviewsQuery } from '@generated/types';
|
||||
import { BookReviewCreateMutation, BookReviewsDataQuery, BookReviewsQuery } from '@generated/types';
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { useState } from 'react';
|
||||
import { bookQuery } from '../overview';
|
||||
|
|
@ -36,17 +36,25 @@ function RouteComponent() {
|
|||
}
|
||||
});
|
||||
|
||||
const { data: authorData } = useQuery<BookReviewsDataQuery>(bookAuthorQuery, {
|
||||
variables: { id }
|
||||
});
|
||||
|
||||
const { update: reviewCreate } = useToastMutation<BookReviewCreateMutation>({
|
||||
mutation: bookReviewCreateMutation,
|
||||
successMsg: 'Review posted!',
|
||||
refetchQueries: [bookReviewsQuery, bookQuery]
|
||||
});
|
||||
|
||||
if (data == null) return <Skeleton />;
|
||||
if (data == null || authorData == null) return <Skeleton />;
|
||||
|
||||
return (
|
||||
<>
|
||||
<BookOverviewTabs bookId={id} currentTab="reviews" />
|
||||
<BookOverviewTabs
|
||||
isAuthor={authorData.bookOne.author.id === identity?.data.id}
|
||||
bookId={id}
|
||||
currentTab="reviews"
|
||||
/>
|
||||
|
||||
{identity != null && reviewsPage === 1 && (
|
||||
<ReviewInput
|
||||
|
|
@ -97,6 +105,17 @@ function RouteComponent() {
|
|||
);
|
||||
}
|
||||
|
||||
const bookAuthorQuery = gql`
|
||||
query BookReviewsData($id: ID!) {
|
||||
bookOne(id: $id) {
|
||||
id
|
||||
author {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const bookReviewsQuery = gql`
|
||||
query BookReviews($input: ReviewManyInput!) {
|
||||
reviewMany(input: $input) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue