11import { Button } from "@/components/ui/button" ;
2- import { CONTENT_TYPE } from "@/constants/content" ;
32import { useReplaceNavigate } from "@/hooks/use-replace-navigate" ;
43import { useTabStore } from "@/lib/zustand/tab" ;
54import { useUserStore } from "@/lib/zustand/user" ;
@@ -17,7 +16,12 @@ import {
1716import { LogOut , Save , Sparkles } from "lucide-react" ;
1817import { useNavigate } from "react-router-dom" ;
1918
20- import { useDetailSaveContent , useQuickSaveContent } from "../lib/tanstack/mutation/content" ;
19+ import {
20+ useDetailSaveContent ,
21+ useDetailSaveYoutubeContent ,
22+ useQuickSaveContent ,
23+ useQuickSaveYoutubeContent ,
24+ } from "../lib/tanstack/mutation/content" ;
2125
2226const getHtmlContent = async ( ) => {
2327 const html = await getHtmlText ( ) ;
@@ -79,61 +83,84 @@ export default function SearchContent() {
7983 useQuickSaveContent ( ) ;
8084 const { mutateAsync : mutateDetailSaveContent , isPending : isPendingDetailSaveContent } =
8185 useDetailSaveContent ( ) ;
86+ const {
87+ mutateAsync : mutateQuickSaveYoutubeContent ,
88+ isPending : isPendingQuickSaveYoutubeContent ,
89+ } = useQuickSaveYoutubeContent ( ) ;
90+ const {
91+ mutateAsync : mutateDetailSaveYoutubeContent ,
92+ isPending : isPendingDetailSaveYoutubeContent ,
93+ } = useDetailSaveYoutubeContent ( ) ;
8294
8395 const saveDisabledd =
84- isFindingExistPath || isPendingQuickSaveContent || isPendingDetailSaveContent ;
96+ isFindingExistPath ||
97+ isPendingQuickSaveContent ||
98+ isPendingDetailSaveContent ||
99+ isPendingQuickSaveYoutubeContent ||
100+ isPendingDetailSaveYoutubeContent ;
85101
86- const currentContentType = currentTab . url . includes ( "youtube.com" )
87- ? CONTENT_TYPE . YOUTUBE
88- : CONTENT_TYPE . WEB ;
102+ const isYoutubeUrl = currentTab . url . includes ( "youtube.com" ) ;
89103
90104 const onSaveOnly = async ( ) => {
91- const { htmlContent, thumbnail } = await getHtmlContent ( ) ;
92- if ( ! htmlContent || ! thumbnail ) return ;
105+ if ( isYoutubeUrl ) {
106+ await mutateQuickSaveYoutubeContent ( {
107+ title : currentTab . title ,
108+ url : currentTab . url ,
109+ } ) ;
110+ } else {
111+ const { htmlContent, thumbnail } = await getHtmlContent ( ) ;
112+ if ( ! htmlContent || ! thumbnail ) return ;
93113
94- const htmlBlob = new Blob ( [ htmlContent ] , { type : "text/html" } ) ;
95- const htmlFile = new File ( [ htmlBlob ] , "content.html" , { type : "text/html" } ) ;
114+ const htmlBlob = new Blob ( [ htmlContent ] , { type : "text/html" } ) ;
115+ const htmlFile = new File ( [ htmlBlob ] , "content.html" , { type : "text/html" } ) ;
96116
97- const formData = new FormData ( ) ;
117+ const formData = new FormData ( ) ;
98118
99- formData . append ( "htmlFile" , htmlFile ) ;
100- formData . append ( "title" , currentTab . title ) ;
101- formData . append ( "url" , currentTab . url ) ;
102- formData . append ( "thumbnail" , thumbnail ) ;
119+ formData . append ( "htmlFile" , htmlFile ) ;
120+ formData . append ( "title" , currentTab . title ) ;
121+ formData . append ( "url" , currentTab . url ) ;
122+ formData . append ( "thumbnail" , thumbnail ) ;
103123
104- await mutateQuickSaveContent ( formData ) ;
124+ await mutateQuickSaveContent ( formData ) ;
125+ }
105126 } ;
106127
107128 const onSaveWithSummary = async ( ) => {
108- const { htmlContent, thumbnail } = await getHtmlContent ( ) ;
109- if ( ! htmlContent || ! thumbnail ) return ;
129+ if ( isYoutubeUrl ) {
130+ const res = await mutateDetailSaveYoutubeContent ( {
131+ url : currentTab . url ,
132+ } ) ;
133+ navigate ( "/create-content" , {
134+ state : {
135+ ...res . result ,
136+ ...currentTab ,
137+ thumbnail : "" ,
138+ transcript : "" ,
139+ } ,
140+ } ) ;
141+ } else {
142+ const { htmlContent, thumbnail } = await getHtmlContent ( ) ;
143+ if ( ! htmlContent || ! thumbnail ) return ;
110144
111- const htmlBlob = new Blob ( [ htmlContent ] , { type : "text/html" } ) ;
112- const htmlFile = new File ( [ htmlBlob ] , "content.html" , { type : "text/html" } ) ;
145+ const htmlBlob = new Blob ( [ htmlContent ] , { type : "text/html" } ) ;
146+ const htmlFile = new File ( [ htmlBlob ] , "content.html" , { type : "text/html" } ) ;
113147
114- const formData = new FormData ( ) ;
115- formData . append ( "htmlFile" , htmlFile ) ;
116- formData . append ( "type" , currentContentType ) ;
148+ const formData = new FormData ( ) ;
149+ formData . append ( "htmlFile" , htmlFile ) ;
117150
118- await mutateDetailSaveContent (
119- {
151+ const res = await mutateDetailSaveContent ( {
120152 url : currentTab . url ,
121153 formData,
122- } ,
123- {
124- onSuccess : ( data ) => {
125- navigate ( "/create-content" , {
126- state : {
127- ...data . result ,
128- ...currentTab ,
129- thumbnail,
130- htmlFile,
131- type : currentContentType ,
132- } ,
133- } ) ;
154+ } ) ;
155+ navigate ( "/create-content" , {
156+ state : {
157+ ...res . result ,
158+ ...currentTab ,
159+ thumbnail,
160+ htmlFile,
134161 } ,
135- }
136- ) ;
162+ } ) ;
163+ }
137164 } ;
138165
139166 return (
0 commit comments