@@ -19,6 +19,7 @@ export default function CreateRecipe() {
1919 const [ singleIngredient , setSingleIngredient ] = useState ( "" ) ;
2020 const [ ingredients , setIngredients ] = useState < Ingredients [ ] > ( [ ] ) ;
2121 const [ selectedPhoto , setSelectedPhoto ] = useState < File | null > ( null ) ;
22+ const [ loading , setLoading ] = useState ( true )
2223
2324 // تابع handlePhotoChange برای مدیریت تغییرات در ورودی عکس
2425 const handlePhotoChange = ( event : ChangeEvent < HTMLInputElement > ) => {
@@ -48,7 +49,7 @@ export default function CreateRecipe() {
4849 // تابع saveRecipe برای ارسال دادهها به سرور و ذخیره رسپی جدید
4950 const saveRecipe = async ( event : FormEvent ) => {
5051 event . preventDefault ( ) ;
51-
52+ setLoading ( true )
5253 if ( selectedPhoto ) {
5354 const formData = new FormData ( ) ;
5455 formData . append ( "photo" , selectedPhoto ) ;
@@ -63,11 +64,13 @@ export default function CreateRecipe() {
6364 } ;
6465 try {
6566 const saveRecip = await fetch ( "/api/recipes" , options ) ;
66- console . log ( saveRecip ) ;
67+ setLoading ( false )
68+ if ( saveRecip . status === 200 ) {
69+ console . log ( saveRecip ) ;
70+ }
6771 } catch ( error ) {
72+ setLoading ( false )
6873 console . log ( error ) ;
69-
70-
7174 }
7275 }
7376 } ;
@@ -82,11 +85,10 @@ export default function CreateRecipe() {
8285 < div className = "text-center w-full mx-auto py-12 px-4 sm:px-6 lg:py-16 lg:px-8 z-20" >
8386 < h2 className = "text-3xl font-extrabold text-black dark:text-white sm:text-4xl" >
8487 < span className = "text-gray-600" >
85- اون رسپی که میخوای نیست؟
86- </ span >
87- < span className = "block text-indigo-500" >
88- خودت اضافه اش کن
88+ اضافه کردن رسپی جدید
8989 </ span >
90+ { /* <span className="block text-indigo-500">
91+ </span> */ }
9092 </ h2 >
9193 </ div >
9294 </ div >
@@ -182,7 +184,7 @@ export default function CreateRecipe() {
182184 type = "submit"
183185 className = "w-96 py-3 px-4 inline-flex justify-center items-center gap-2 rounded-md border border-transparent font-semibold bg-cyan-700 text-white hover:bg-cyan-500 focus:outline-none focus:ring-2 focus:ring-cyan-500 focus:ring-offset-2 transition-all text-sm"
184186 >
185- < span > اضافه کن </ span >
187+ < span > ساخت رسپی </ span >
186188 </ Button >
187189 </ div >
188190 </ form >
0 commit comments