Skip to content

Commit 30d2dc0

Browse files
authored
Merge pull request #775 from WatchItDev/app/new/data/structure
feat: adapted the api hooks to use the new data structure
2 parents cfdd342 + e402f28 commit 30d2dc0

File tree

11 files changed

+182
-181
lines changed

11 files changed

+182
-181
lines changed

src/components/publication-detail-main/index.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ import { useAuth } from '@src/hooks/use-auth.ts';
5151
import { useToggleBookmark } from '@src/hooks/use-toggle-bookmark';
5252
import {
5353
useHidePostMutation,
54-
useGetIsPostLikedLazyQuery,
55-
useTogglePostLikeMutation,
54+
useGetIsLikedLazyQuery,
55+
useToggleLikeMutation,
5656
} from '@src/graphql/generated/hooks.tsx';
5757
import { resolveSrc } from '@src/utils/image.ts';
5858
import { useBookmarks } from '@src/hooks/use-bookmark.ts';
@@ -81,8 +81,8 @@ export default function PublicationDetailMain({
8181
const [ hidePost ] = useHidePostMutation();
8282
const { sendNotification } = useNotifications();
8383
const { generatePayload } = useNotificationPayload(sessionData);
84-
const [getIsPostLiked, { loading: postLikedLoading }] = useGetIsPostLikedLazyQuery()
85-
const [ togglePostLike, { loading: togglePostLikeLoading } ] = useTogglePostLikeMutation()
84+
const [getIsLiked, { loading: postLikedLoading }] = useGetIsLikedLazyQuery()
85+
const [ toggleLike, { loading: togglePostLikeLoading } ] = useToggleLikeMutation()
8686
const { has, loading: loadingList } = useBookmarks();
8787
const { toggle, loading: loadingToggle } = useToggleBookmark();
8888

@@ -95,8 +95,18 @@ export default function PublicationDetailMain({
9595
if (!sessionData?.authenticated) return dispatch(openLoginModal());
9696

9797
try {
98-
const res = await togglePostLike({ variables: { input: { postId: post.id } } });
99-
const isNowLiked = res.data?.togglePostLike ?? false;
98+
const res = await toggleLike({
99+
variables: {
100+
input: {
101+
targetId: post.id,
102+
targetType: 'POST'
103+
}
104+
}
105+
});
106+
const isNowLiked = res.data?.toggleLike ?? false;
107+
108+
console.log('hello test', res.data?.toggleLike)
109+
console.log(isNowLiked)
100110

101111
setHasLiked(isNowLiked);
102112
setLikesCount((prev) => prev + (isNowLiked ? 1 : -1));
@@ -132,9 +142,10 @@ export default function PublicationDetailMain({
132142
};
133143

134144
useEffect(() => {
135-
getIsPostLiked({ variables: { postId: post.id } }).then((res) =>
136-
setHasLiked(res.data?.getIsPostLiked ?? false),
137-
);
145+
getIsLiked({ variables: { targetId: post.id } }).then((res) => {
146+
console.log('hello test 2', res.data?.getIsLiked)
147+
setHasLiked(res.data?.getIsLiked ?? false)
148+
});
138149
}, [post.id]);
139150

140151
const handleHide = async () => {

src/graphql/generated/graphql.ts

Lines changed: 109 additions & 51 deletions
Large diffs are not rendered by default.

src/graphql/generated/hooks.tsx

Lines changed: 32 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as Apollo from '@apollo/client';
33
const defaultOptions = {} as const;
44

55
export const ToggleBookmarkDocument = gql`
6-
mutation ToggleBookmark($input: BookmarkPostInput!) {
6+
mutation ToggleBookmark($input: BookmarkInput!) {
77
toggleBookmark(input: $input)
88
}
99
`;
@@ -180,68 +180,37 @@ export function useToggleFollowMutation(baseOptions?: Apollo.MutationHookOptions
180180
export type ToggleFollowMutationHookResult = ReturnType<typeof useToggleFollowMutation>;
181181
export type ToggleFollowMutationResult = Apollo.MutationResult<ToggleFollowMutation>;
182182
export type ToggleFollowMutationOptions = Apollo.BaseMutationOptions<ToggleFollowMutation, ToggleFollowMutationVariables>;
183-
export const ToggleCommentLikeDocument = gql`
184-
mutation ToggleCommentLike($input: LikeCommentInput!) {
185-
toggleCommentLike(input: $input)
183+
export const ToggleLikeDocument = gql`
184+
mutation ToggleLike($input: LikeInput!) {
185+
toggleLike(input: $input)
186186
}
187187
`;
188-
export type ToggleCommentLikeMutationFn = Apollo.MutationFunction<ToggleCommentLikeMutation, ToggleCommentLikeMutationVariables>;
188+
export type ToggleLikeMutationFn = Apollo.MutationFunction<ToggleLikeMutation, ToggleLikeMutationVariables>;
189189

190190
/**
191-
* __useToggleCommentLikeMutation__
191+
* __useToggleLikeMutation__
192192
*
193-
* To run a mutation, you first call `useToggleCommentLikeMutation` within a React component and pass it any options that fit your needs.
194-
* When your component renders, `useToggleCommentLikeMutation` returns a tuple that includes:
193+
* To run a mutation, you first call `useToggleLikeMutation` within a React component and pass it any options that fit your needs.
194+
* When your component renders, `useToggleLikeMutation` returns a tuple that includes:
195195
* - A mutate function that you can call at any time to execute the mutation
196196
* - An object with fields that represent the current status of the mutation's execution
197197
*
198198
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
199199
*
200200
* @example
201-
* const [toggleCommentLikeMutation, { data, loading, error }] = useToggleCommentLikeMutation({
201+
* const [toggleLikeMutation, { data, loading, error }] = useToggleLikeMutation({
202202
* variables: {
203203
* input: // value for 'input'
204204
* },
205205
* });
206206
*/
207-
export function useToggleCommentLikeMutation(baseOptions?: Apollo.MutationHookOptions<ToggleCommentLikeMutation, ToggleCommentLikeMutationVariables>) {
207+
export function useToggleLikeMutation(baseOptions?: Apollo.MutationHookOptions<ToggleLikeMutation, ToggleLikeMutationVariables>) {
208208
const options = {...defaultOptions, ...baseOptions}
209-
return Apollo.useMutation<ToggleCommentLikeMutation, ToggleCommentLikeMutationVariables>(ToggleCommentLikeDocument, options);
209+
return Apollo.useMutation<ToggleLikeMutation, ToggleLikeMutationVariables>(ToggleLikeDocument, options);
210210
}
211-
export type ToggleCommentLikeMutationHookResult = ReturnType<typeof useToggleCommentLikeMutation>;
212-
export type ToggleCommentLikeMutationResult = Apollo.MutationResult<ToggleCommentLikeMutation>;
213-
export type ToggleCommentLikeMutationOptions = Apollo.BaseMutationOptions<ToggleCommentLikeMutation, ToggleCommentLikeMutationVariables>;
214-
export const TogglePostLikeDocument = gql`
215-
mutation TogglePostLike($input: LikePostInput!) {
216-
togglePostLike(input: $input)
217-
}
218-
`;
219-
export type TogglePostLikeMutationFn = Apollo.MutationFunction<TogglePostLikeMutation, TogglePostLikeMutationVariables>;
220-
221-
/**
222-
* __useTogglePostLikeMutation__
223-
*
224-
* To run a mutation, you first call `useTogglePostLikeMutation` within a React component and pass it any options that fit your needs.
225-
* When your component renders, `useTogglePostLikeMutation` returns a tuple that includes:
226-
* - A mutate function that you can call at any time to execute the mutation
227-
* - An object with fields that represent the current status of the mutation's execution
228-
*
229-
* @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2;
230-
*
231-
* @example
232-
* const [togglePostLikeMutation, { data, loading, error }] = useTogglePostLikeMutation({
233-
* variables: {
234-
* input: // value for 'input'
235-
* },
236-
* });
237-
*/
238-
export function useTogglePostLikeMutation(baseOptions?: Apollo.MutationHookOptions<TogglePostLikeMutation, TogglePostLikeMutationVariables>) {
239-
const options = {...defaultOptions, ...baseOptions}
240-
return Apollo.useMutation<TogglePostLikeMutation, TogglePostLikeMutationVariables>(TogglePostLikeDocument, options);
241-
}
242-
export type TogglePostLikeMutationHookResult = ReturnType<typeof useTogglePostLikeMutation>;
243-
export type TogglePostLikeMutationResult = Apollo.MutationResult<TogglePostLikeMutation>;
244-
export type TogglePostLikeMutationOptions = Apollo.BaseMutationOptions<TogglePostLikeMutation, TogglePostLikeMutationVariables>;
211+
export type ToggleLikeMutationHookResult = ReturnType<typeof useToggleLikeMutation>;
212+
export type ToggleLikeMutationResult = Apollo.MutationResult<ToggleLikeMutation>;
213+
export type ToggleLikeMutationOptions = Apollo.BaseMutationOptions<ToggleLikeMutation, ToggleLikeMutationVariables>;
245214
export const CreatePostDocument = gql`
246215
mutation CreatePost($input: CreatePostInput!) {
247216
createPost(input: $input) {
@@ -1031,82 +1000,44 @@ export type GetIsFollowingQueryHookResult = ReturnType<typeof useGetIsFollowingQ
10311000
export type GetIsFollowingLazyQueryHookResult = ReturnType<typeof useGetIsFollowingLazyQuery>;
10321001
export type GetIsFollowingSuspenseQueryHookResult = ReturnType<typeof useGetIsFollowingSuspenseQuery>;
10331002
export type GetIsFollowingQueryResult = Apollo.QueryResult<GetIsFollowingQuery, GetIsFollowingQueryVariables>;
1034-
export const GetIsCommentLikedDocument = gql`
1035-
query GetIsCommentLiked($commentId: String!) {
1036-
getIsCommentLiked(commentId: $commentId)
1037-
}
1038-
`;
1039-
1040-
/**
1041-
* __useGetIsCommentLikedQuery__
1042-
*
1043-
* To run a query within a React component, call `useGetIsCommentLikedQuery` and pass it any options that fit your needs.
1044-
* When your component renders, `useGetIsCommentLikedQuery` returns an object from Apollo Client that contains loading, error, and data properties
1045-
* you can use to render your UI.
1046-
*
1047-
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
1048-
*
1049-
* @example
1050-
* const { data, loading, error } = useGetIsCommentLikedQuery({
1051-
* variables: {
1052-
* commentId: // value for 'commentId'
1053-
* },
1054-
* });
1055-
*/
1056-
export function useGetIsCommentLikedQuery(baseOptions: Apollo.QueryHookOptions<GetIsCommentLikedQuery, GetIsCommentLikedQueryVariables> & ({ variables: GetIsCommentLikedQueryVariables; skip?: boolean; } | { skip: boolean; }) ) {
1057-
const options = {...defaultOptions, ...baseOptions}
1058-
return Apollo.useQuery<GetIsCommentLikedQuery, GetIsCommentLikedQueryVariables>(GetIsCommentLikedDocument, options);
1059-
}
1060-
export function useGetIsCommentLikedLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetIsCommentLikedQuery, GetIsCommentLikedQueryVariables>) {
1061-
const options = {...defaultOptions, ...baseOptions}
1062-
return Apollo.useLazyQuery<GetIsCommentLikedQuery, GetIsCommentLikedQueryVariables>(GetIsCommentLikedDocument, options);
1063-
}
1064-
export function useGetIsCommentLikedSuspenseQuery(baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<GetIsCommentLikedQuery, GetIsCommentLikedQueryVariables>) {
1065-
const options = baseOptions === Apollo.skipToken ? baseOptions : {...defaultOptions, ...baseOptions}
1066-
return Apollo.useSuspenseQuery<GetIsCommentLikedQuery, GetIsCommentLikedQueryVariables>(GetIsCommentLikedDocument, options);
1067-
}
1068-
export type GetIsCommentLikedQueryHookResult = ReturnType<typeof useGetIsCommentLikedQuery>;
1069-
export type GetIsCommentLikedLazyQueryHookResult = ReturnType<typeof useGetIsCommentLikedLazyQuery>;
1070-
export type GetIsCommentLikedSuspenseQueryHookResult = ReturnType<typeof useGetIsCommentLikedSuspenseQuery>;
1071-
export type GetIsCommentLikedQueryResult = Apollo.QueryResult<GetIsCommentLikedQuery, GetIsCommentLikedQueryVariables>;
1072-
export const GetIsPostLikedDocument = gql`
1073-
query GetIsPostLiked($postId: String!) {
1074-
getIsPostLiked(postId: $postId)
1003+
export const GetIsLikedDocument = gql`
1004+
query GetIsLiked($targetId: String!) {
1005+
getIsLiked(targetId: $targetId)
10751006
}
10761007
`;
10771008

10781009
/**
1079-
* __useGetIsPostLikedQuery__
1010+
* __useGetIsLikedQuery__
10801011
*
1081-
* To run a query within a React component, call `useGetIsPostLikedQuery` and pass it any options that fit your needs.
1082-
* When your component renders, `useGetIsPostLikedQuery` returns an object from Apollo Client that contains loading, error, and data properties
1012+
* To run a query within a React component, call `useGetIsLikedQuery` and pass it any options that fit your needs.
1013+
* When your component renders, `useGetIsLikedQuery` returns an object from Apollo Client that contains loading, error, and data properties
10831014
* you can use to render your UI.
10841015
*
10851016
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
10861017
*
10871018
* @example
1088-
* const { data, loading, error } = useGetIsPostLikedQuery({
1019+
* const { data, loading, error } = useGetIsLikedQuery({
10891020
* variables: {
1090-
* postId: // value for 'postId'
1021+
* targetId: // value for 'targetId'
10911022
* },
10921023
* });
10931024
*/
1094-
export function useGetIsPostLikedQuery(baseOptions: Apollo.QueryHookOptions<GetIsPostLikedQuery, GetIsPostLikedQueryVariables> & ({ variables: GetIsPostLikedQueryVariables; skip?: boolean; } | { skip: boolean; }) ) {
1025+
export function useGetIsLikedQuery(baseOptions: Apollo.QueryHookOptions<GetIsLikedQuery, GetIsLikedQueryVariables> & ({ variables: GetIsLikedQueryVariables; skip?: boolean; } | { skip: boolean; }) ) {
10951026
const options = {...defaultOptions, ...baseOptions}
1096-
return Apollo.useQuery<GetIsPostLikedQuery, GetIsPostLikedQueryVariables>(GetIsPostLikedDocument, options);
1027+
return Apollo.useQuery<GetIsLikedQuery, GetIsLikedQueryVariables>(GetIsLikedDocument, options);
10971028
}
1098-
export function useGetIsPostLikedLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetIsPostLikedQuery, GetIsPostLikedQueryVariables>) {
1029+
export function useGetIsLikedLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<GetIsLikedQuery, GetIsLikedQueryVariables>) {
10991030
const options = {...defaultOptions, ...baseOptions}
1100-
return Apollo.useLazyQuery<GetIsPostLikedQuery, GetIsPostLikedQueryVariables>(GetIsPostLikedDocument, options);
1031+
return Apollo.useLazyQuery<GetIsLikedQuery, GetIsLikedQueryVariables>(GetIsLikedDocument, options);
11011032
}
1102-
export function useGetIsPostLikedSuspenseQuery(baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<GetIsPostLikedQuery, GetIsPostLikedQueryVariables>) {
1033+
export function useGetIsLikedSuspenseQuery(baseOptions?: Apollo.SkipToken | Apollo.SuspenseQueryHookOptions<GetIsLikedQuery, GetIsLikedQueryVariables>) {
11031034
const options = baseOptions === Apollo.skipToken ? baseOptions : {...defaultOptions, ...baseOptions}
1104-
return Apollo.useSuspenseQuery<GetIsPostLikedQuery, GetIsPostLikedQueryVariables>(GetIsPostLikedDocument, options);
1035+
return Apollo.useSuspenseQuery<GetIsLikedQuery, GetIsLikedQueryVariables>(GetIsLikedDocument, options);
11051036
}
1106-
export type GetIsPostLikedQueryHookResult = ReturnType<typeof useGetIsPostLikedQuery>;
1107-
export type GetIsPostLikedLazyQueryHookResult = ReturnType<typeof useGetIsPostLikedLazyQuery>;
1108-
export type GetIsPostLikedSuspenseQueryHookResult = ReturnType<typeof useGetIsPostLikedSuspenseQuery>;
1109-
export type GetIsPostLikedQueryResult = Apollo.QueryResult<GetIsPostLikedQuery, GetIsPostLikedQueryVariables>;
1037+
export type GetIsLikedQueryHookResult = ReturnType<typeof useGetIsLikedQuery>;
1038+
export type GetIsLikedLazyQueryHookResult = ReturnType<typeof useGetIsLikedLazyQuery>;
1039+
export type GetIsLikedSuspenseQueryHookResult = ReturnType<typeof useGetIsLikedSuspenseQuery>;
1040+
export type GetIsLikedQueryResult = Apollo.QueryResult<GetIsLikedQuery, GetIsLikedQueryVariables>;
11101041
export const GetPostDocument = gql`
11111042
query GetPost($getPostId: String!) {
11121043
getPost(id: $getPostId) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
mutation ToggleBookmark($input: BookmarkPostInput!) {
1+
mutation ToggleBookmark($input: BookmarkInput!) {
22
toggleBookmark(input: $input)
33
}

src/graphql/mutations/likes/toggleCommentLike.gql

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mutation ToggleLike($input: LikeInput!) {
2+
toggleLike(input: $input)
3+
}

src/graphql/mutations/likes/togglePostLike.gql

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/graphql/queries/likes/getIsCommentLiked.gql

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
query GetIsLiked($targetId: String!) {
2+
getIsLiked(targetId: $targetId)
3+
}

src/graphql/queries/likes/getIsPostLiked.gql

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)