From ce85662f4b7253824fda0aee621ffa0681339fde Mon Sep 17 00:00:00 2001 From: jadapema Date: Fri, 8 Aug 2025 09:16:00 -0600 Subject: [PATCH] feat: added views count to the videos --- src/components/video-player/video-player.tsx | 9 +++++++-- src/graphql/generated/graphql.ts | 4 ++-- src/graphql/generated/hooks.tsx | 1 + src/graphql/mutations/posts/incrementPostView.gql | 1 + src/layouts/dashboard/header.tsx | 2 +- .../publication/components/publication-description.tsx | 8 ++++++++ 6 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/video-player/video-player.tsx b/src/components/video-player/video-player.tsx index 3ba66475a..a968b9dcd 100644 --- a/src/components/video-player/video-player.tsx +++ b/src/components/video-player/video-player.tsx @@ -21,7 +21,7 @@ import useGetSubtitles from '@src/hooks/protocol/use-get-subtitles.ts'; import { useResponsive } from '@src/hooks/use-responsive'; import Label from '../label'; import {ErrorData} from "hls.js" -import { useLogEventMutation } from '@src/graphql/generated/hooks.tsx'; +import { useIncrementPostViewMutation, useLogEventMutation } from '@src/graphql/generated/hooks.tsx'; import { useAuth } from '@src/hooks/use-auth.ts'; export interface VideoPlayerProps { @@ -41,6 +41,7 @@ export const VideoPlayer: FC = ({ src, cid, titleMovie, postId const controlsVisible = useMediaState('controlsVisible', player); const { tracks, getSubtitles } = useGetSubtitles(); const [logEvent] = useLogEventMutation(); + const [incrementView] = useIncrementPostViewMutation(); const { session } = useAuth(); const watchedSeconds = useRef>(new Set()) // distinct seconds already counted @@ -69,7 +70,11 @@ export const VideoPlayer: FC = ({ src, cid, titleMovie, postId } }; - const handlePlay = () => emit('VIDEO_START'); + const handlePlay = () => { + emit('VIDEO_START'); + incrementView({ variables: { postId } }); + }; + const handleEnded = () => emit('VIDEO_WATCH_FULL'); const handleTimeUpdate = () => { diff --git a/src/graphql/generated/graphql.ts b/src/graphql/generated/graphql.ts index d706fdebe..59a63151c 100644 --- a/src/graphql/generated/graphql.ts +++ b/src/graphql/generated/graphql.ts @@ -871,7 +871,7 @@ export type IncrementPostViewMutationVariables = Exact<{ }>; -export type IncrementPostViewMutation = { __typename?: 'Mutation', incrementPostView: { __typename?: 'Post', id: string } }; +export type IncrementPostViewMutation = { __typename?: 'Mutation', incrementPostView: { __typename?: 'Post', id: string, viewCount: number } }; export type UpdatePostMutationVariables = Exact<{ input: UpdatePostInput; @@ -1151,7 +1151,7 @@ export const LogAnonymousEventDocument = {"kind":"Document","definitions":[{"kin export const LogEventDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"LogEvent"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"LogEventInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"logEvent"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}]}]}}]} as unknown as DocumentNode; export const CreatePostDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreatePost"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreatePostInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createPost"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}}]}}]}}]} as unknown as DocumentNode; export const HidePostDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"HidePost"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"postId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"hidePost"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"postId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"postId"}}}]}]}}]} as unknown as DocumentNode; -export const IncrementPostViewDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"IncrementPostView"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"postId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"incrementPostView"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"postId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"postId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode; +export const IncrementPostViewDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"IncrementPostView"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"postId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"incrementPostView"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"postId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"postId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"viewCount"}}]}}]}}]} as unknown as DocumentNode; export const UpdatePostDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdatePost"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdatePostInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updatePost"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"title"}}]}}]}}]} as unknown as DocumentNode; export const CreateTipDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateTip"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateTipInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createTip"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"amount"}},{"kind":"Field","name":{"kind":"Name","value":"baker"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"creator"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"message"}},{"kind":"Field","name":{"kind":"Name","value":"postId"}},{"kind":"Field","name":{"kind":"Name","value":"txHash"}}]}}]}}]} as unknown as DocumentNode; export const CreateUserDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateUser"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UserInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createUser"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"address"}},{"kind":"Field","name":{"kind":"Name","value":"username"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"xpBalance"}}]}}]}}]} as unknown as DocumentNode; diff --git a/src/graphql/generated/hooks.tsx b/src/graphql/generated/hooks.tsx index 06098758c..18b968ac4 100644 --- a/src/graphql/generated/hooks.tsx +++ b/src/graphql/generated/hooks.tsx @@ -375,6 +375,7 @@ export const IncrementPostViewDocument = gql` mutation IncrementPostView($postId: String!) { incrementPostView(postId: $postId) { id + viewCount } } `; diff --git a/src/graphql/mutations/posts/incrementPostView.gql b/src/graphql/mutations/posts/incrementPostView.gql index 08b186c6f..d5dec698f 100644 --- a/src/graphql/mutations/posts/incrementPostView.gql +++ b/src/graphql/mutations/posts/incrementPostView.gql @@ -1,5 +1,6 @@ mutation IncrementPostView($postId: String!) { incrementPostView(postId: $postId) { id + viewCount } } diff --git a/src/layouts/dashboard/header.tsx b/src/layouts/dashboard/header.tsx index 9090c9427..99434d293 100644 --- a/src/layouts/dashboard/header.tsx +++ b/src/layouts/dashboard/header.tsx @@ -64,7 +64,7 @@ export default function Header({ children }: PropsWithChildren) { > {sessionData?.authenticated && ( <> - + {/**/} diff --git a/src/sections/publication/components/publication-description.tsx b/src/sections/publication/components/publication-description.tsx index e2c61b57f..d4eb35512 100644 --- a/src/sections/publication/components/publication-description.tsx +++ b/src/sections/publication/components/publication-description.tsx @@ -46,6 +46,14 @@ export const PublicationTitleDescription: FC = {publication?.title} + + + {publication?.viewCount} views + +