diff --git a/go-server/handlers/youtube.go b/go-server/handlers/youtube.go index 6ff84ec..01b6a70 100644 --- a/go-server/handlers/youtube.go +++ b/go-server/handlers/youtube.go @@ -263,16 +263,15 @@ func YoutubeAnalysisHandler(c *fiber.Ctx) error { } //////////////////////////////////////////////// - fmt.Printf("[YoutubeAnalysisHandler] Number of comments success Bert: %d\n", + log.Printf("[YoutubeAnalysisHandler] Number of comments success Bert: %d\n", analysis.Results.BertResults.SuccessCount) - fmt.Printf("[YoutubeAnalysisHandler] Number of comments failed Bert: %d\n", + log.Printf("[YoutubeAnalysisHandler] Number of comments failed Bert: %d\n", analysis.Results.BertResults.ErrorsCount) - fmt.Printf("[YoutubeAnalysisHandler] Number of comments success Roberta: %d\n", + log.Printf("[YoutubeAnalysisHandler] Number of comments success Roberta: %d\n", analysis.Results.RobertaResults.SuccessCount) - fmt.Printf("[YoutubeAnalysisHandler] Number of comments failed Roberta: %d\n", + log.Printf("[YoutubeAnalysisHandler] Number of comments failed Roberta: %d\n", analysis.Results.RobertaResults.ErrorsCount) - c.JSON(successResp) - return c.SendStatus(http.StatusOK) + return c.Status(http.StatusOK).JSON(successResp) } // This means we have received email hence this video is large so we do all @@ -350,7 +349,7 @@ func YoutubeAnalysisHandler(c *fiber.Ctx) error { analysis.Results.RobertaResults.ErrorsCount) }(videoData) - return c.SendStatus(http.StatusOK) + return c.Status(http.StatusOK).JSON(fiber.Map{}) } // @Summary Simple analysis with BERT model for the landing page @@ -409,9 +408,8 @@ func YoutubeAnalysisLandingHandler(c *fiber.Ctx) error { CreatedAt: time.Now().UTC(), } - fmt.Printf("[YoutubeAnalysisLandingHandler] Number of comments success Bert: %d\n", results.BertResults.SuccessCount) - fmt.Printf("[YoutubeAnalysisLandingHandler] Number of comments failed Bert: %d\n", results.BertResults.ErrorsCount) - c.JSON(successResp) + log.Printf("[YoutubeAnalysisLandingHandler] Number of comments success Bert: %d\n", results.BertResults.SuccessCount) + log.Printf("[YoutubeAnalysisLandingHandler] Number of comments failed Bert: %d\n", results.BertResults.ErrorsCount) - return c.SendStatus(http.StatusOK) + return c.Status(http.StatusOK).JSON(successResp) } diff --git a/gptube/components/dashboard/button-new-analysis.tsx b/gptube/components/dashboard/button-new-analysis.tsx index 2dcd6c4..1688d5d 100644 --- a/gptube/components/dashboard/button-new-analysis.tsx +++ b/gptube/components/dashboard/button-new-analysis.tsx @@ -15,6 +15,8 @@ import { useVideoPreview } from '@/hooks/use-video-preview' import { isValidEmail, isValidYoutubeUrl } from '@/utils/validations.utils' import { useForm } from '@/hooks/use-form' import { useAuth } from '@/hooks/use-auth' +import { extractYTVideoID } from '@/utils' +import { useDashboardAnalysis } from '@/hooks/use-dashboard-analysis' import { Button } from '../Common/button' @@ -22,18 +24,23 @@ import { VideoPreview } from './video-preview' export function ButtonNewAnalysis() { const { user } = useAuth() - const { handleChange, email, showEmail, url } = useForm({ + // eslint-disable-next-line prefer-const + let { handleChange, email, showEmail, url } = useForm({ url: '', email: user?.email || '', - showEmail: true, + showEmail: false, }) + const { handleAnalysis, isLoading } = useDashboardAnalysis() + const [debouncedUrl] = useDebounce(url, 500) const modalAnalysis = useDisclosure() const videoPreviewQuery = useVideoPreview(debouncedUrl) const isInvalidUrl = !isValidYoutubeUrl(url) const isInvalidEmail = email === '' || !isValidEmail(email) + const isInvalid = isInvalidUrl || (showEmail && isInvalidEmail) + const videoId = extractYTVideoID(debouncedUrl) || '' return ( <> @@ -122,9 +129,20 @@ export function ButtonNewAnalysis() { videoPreviewQuery.isSuccess ? 'hover:!bg-opacity-60' : '' } font-medium text-white disabled:cursor-not-allowed transition-opacity`} color="success" - disabled={isInvalidUrl || isInvalidEmail || url.length === 0} + isDisabled={isInvalid} + isLoading={isLoading} radius="sm" - onPress={onClose} + onPress={async () => { + if (!showEmail) { + email = '' + await handleAnalysis('1', videoId, email) + onClose() + + return + } + handleAnalysis('1', videoId, email) + onClose() + }} > Start analysis diff --git a/gptube/components/dashboard/card-video.tsx b/gptube/components/dashboard/card-video.tsx index adde19d..fff8126 100644 --- a/gptube/components/dashboard/card-video.tsx +++ b/gptube/components/dashboard/card-video.tsx @@ -15,7 +15,7 @@ export function CardVideo({ snippet, createdAt, videoId }: ModelsYoutubeVideoDas const imgCard = thumbnails?._default?.url return ( -
+
{imgCard ? ( {title} @@ -29,7 +29,9 @@ export function CardVideo({ snippet, createdAt, videoId }: ModelsYoutubeVideoDas {createdAt ? ( <> - {formatDate(createdAt, 'MMM/DD')} + + {formatDate(createdAt, 'MMM/DD')} + ) : null} diff --git a/gptube/components/dashboard/dashboard-ui.tsx b/gptube/components/dashboard/dashboard-ui.tsx index 1be07cd..362fe17 100644 --- a/gptube/components/dashboard/dashboard-ui.tsx +++ b/gptube/components/dashboard/dashboard-ui.tsx @@ -2,6 +2,7 @@ import { Card, CardBody } from '@nextui-org/card' import { Pagination, Spinner } from '@nextui-org/react' import { useVideosAnalyzed } from '@/hooks/use-videos-analyzed' +import { DEFAULT_PAGE_PAGINATION } from '@/constants/general.constants' import { FilterVideoAnalysis } from './filter-video-analysis' import { ButtonNewAnalysis } from './button-new-analysis' @@ -10,50 +11,58 @@ import { CardVideo } from './card-video' export function DashboardUI() { const { + count, videos, isLoading: isLoadingVideos, isError: isErrorVideos, handleChangePage, - page, totalPages, isFetching, } = useVideosAnalyzed() return ( -
+