11import { useState , useCallback } from 'react' ;
22import { useTranslation } from 'react-i18next' ;
33import { Button } from '@/components/ui/button' ;
4- import { Card , CardContent , CardDescription , CardHeader , CardTitle } from '@/components/ui/card' ;
4+ import {
5+ Card ,
6+ CardContent ,
7+ CardDescription ,
8+ CardHeader ,
9+ CardTitle ,
10+ } from '@/components/ui/card' ;
511import { Input } from '@/components/ui/input' ;
612import { Label } from '@/components/ui/label' ;
713import { Textarea } from '@/components/ui/textarea' ;
@@ -68,7 +74,7 @@ function SortableItem({ id, index, preview, onRemove }: SortableItemProps) {
6874 className = "w-full h-full object-cover"
6975 />
7076 </ div >
71-
77+
7278 { /* Drag handle */ }
7379 < div
7480 { ...attributes }
@@ -77,12 +83,12 @@ function SortableItem({ id, index, preview, onRemove }: SortableItemProps) {
7783 >
7884 < GripVertical className = "h-3 w-3" />
7985 </ div >
80-
86+
8187 { /* Sequence number */ }
8288 < div className = "absolute top-1 right-6 bg-primary text-primary-foreground w-5 h-5 rounded-full flex items-center justify-center text-xs font-bold" >
8389 { index + 1 }
8490 </ div >
85-
91+
8692 { /* Remove button */ }
8793 < Button
8894 type = "button"
@@ -102,7 +108,10 @@ interface WorldKidsNewsSectionProps {
102108 onChange : ( data : WorldKidsNewsData ) => void ;
103109}
104110
105- export default function WorldKidsNewsSection ( { data, onChange } : WorldKidsNewsSectionProps ) {
111+ export default function WorldKidsNewsSection ( {
112+ data,
113+ onChange,
114+ } : WorldKidsNewsSectionProps ) {
106115 const { t } = useTranslation ( ) ;
107116 const [ compressing , setCompressing ] = useState ( false ) ;
108117
@@ -117,11 +126,18 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
117126 const { active, over } = event ;
118127
119128 if ( over && active . id !== over . id ) {
120- const oldIndex = data . imagePreviews . findIndex ( ( _ , index ) => index . toString ( ) === active . id ) ;
121- const newIndex = data . imagePreviews . findIndex ( ( _ , index ) => index . toString ( ) === over . id ) ;
129+ const oldIndex = data . imagePreviews . findIndex (
130+ ( _ , index ) => index . toString ( ) === active . id
131+ ) ;
132+ const newIndex = data . imagePreviews . findIndex (
133+ ( _ , index ) => index . toString ( ) === over . id
134+ ) ;
122135
123136 // Only reorder images array if it has items, otherwise keep it as is
124- const newImages = data . images . length > 0 ? arrayMove ( data . images , oldIndex , newIndex ) : data . images ;
137+ const newImages =
138+ data . images . length > 0
139+ ? arrayMove ( data . images , oldIndex , newIndex )
140+ : data . images ;
125141 const newPreviews = arrayMove ( data . imagePreviews , oldIndex , newIndex ) ;
126142
127143 onChange ( {
@@ -139,7 +155,7 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
139155
140156 // Limit to 3 images
141157 const selectedFiles = files . slice ( 0 , 3 - data . images . length ) ;
142-
158+
143159 if ( selectedFiles . length + data . images . length > 3 ) {
144160 toast . error ( '最多只能上傳 3 張圖片' ) ;
145161 return ;
@@ -183,10 +199,10 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
183199 const removeImage = ( index : number ) => {
184200 const newImages = [ ...data . images ] ;
185201 const newPreviews = [ ...data . imagePreviews ] ;
186-
202+
187203 // Revoke object URL to prevent memory leaks
188204 URL . revokeObjectURL ( newPreviews [ index ] ) ;
189-
205+
190206 newImages . splice ( index , 1 ) ;
191207 newPreviews . splice ( index , 1 ) ;
192208
@@ -197,7 +213,11 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
197213 } ) ;
198214 } ;
199215
200- const updateTranslation = ( language : 'en' | 'zh-TW' , field : 'title' | 'content' , value : string ) => {
216+ const updateTranslation = (
217+ language : 'en' | 'zh-TW' ,
218+ field : 'title' | 'content' ,
219+ value : string
220+ ) => {
201221 onChange ( {
202222 ...data ,
203223 translations : {
@@ -222,15 +242,17 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
222242 { /* Image Upload Section */ }
223243 < div className = "space-y-4" >
224244 < Label > 圖片 (最多 3 張)</ Label >
225-
245+
226246 { /* Upload Button */ }
227247 { data . images . length < 3 && (
228248 < div className = "flex items-center gap-4" >
229249 < Button
230250 type = "button"
231251 variant = "outline"
232252 disabled = { compressing }
233- onClick = { ( ) => document . getElementById ( 'worldKidsNewsImages' ) ?. click ( ) }
253+ onClick = { ( ) =>
254+ document . getElementById ( 'worldKidsNewsImages' ) ?. click ( )
255+ }
234256 >
235257 < Upload className = "h-4 w-4 mr-2" />
236258 { compressing ? '處理中...' : '選擇圖片' }
@@ -290,14 +312,16 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
290312 < TabsTrigger value = "zh-TW" > 中文</ TabsTrigger >
291313 < TabsTrigger value = "en" > English</ TabsTrigger >
292314 </ TabsList >
293-
315+
294316 < TabsContent value = "zh-TW" className = "space-y-4" >
295317 < div className = "space-y-2" >
296318 < Label htmlFor = "worldKidsNews-title-zh" > 標題</ Label >
297319 < Input
298320 id = "worldKidsNews-title-zh"
299321 value = { data . translations [ 'zh-TW' ] . title }
300- onChange = { ( e ) => updateTranslation ( 'zh-TW' , 'title' , e . target . value ) }
322+ onChange = { ( e ) =>
323+ updateTranslation ( 'zh-TW' , 'title' , e . target . value )
324+ }
301325 placeholder = "輸入萬國小新聞標題..."
302326 />
303327 </ div >
@@ -306,20 +330,24 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
306330 < Textarea
307331 id = "worldKidsNews-content-zh"
308332 value = { data . translations [ 'zh-TW' ] . content }
309- onChange = { ( e ) => updateTranslation ( 'zh-TW' , 'content' , e . target . value ) }
333+ onChange = { ( e ) =>
334+ updateTranslation ( 'zh-TW' , 'content' , e . target . value )
335+ }
310336 placeholder = "輸入萬國小新聞內容..."
311337 className = "min-h-[120px]"
312338 />
313339 </ div >
314340 </ TabsContent >
315-
341+
316342 < TabsContent value = "en" className = "space-y-4" >
317343 < div className = "space-y-2" >
318344 < Label htmlFor = "worldKidsNews-title-en" > Title</ Label >
319345 < Input
320346 id = "worldKidsNews-title-en"
321347 value = { data . translations . en . title }
322- onChange = { ( e ) => updateTranslation ( 'en' , 'title' , e . target . value ) }
348+ onChange = { ( e ) =>
349+ updateTranslation ( 'en' , 'title' , e . target . value )
350+ }
323351 placeholder = "Enter World Kids News title..."
324352 />
325353 </ div >
@@ -328,7 +356,9 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
328356 < Textarea
329357 id = "worldKidsNews-content-en"
330358 value = { data . translations . en . content }
331- onChange = { ( e ) => updateTranslation ( 'en' , 'content' , e . target . value ) }
359+ onChange = { ( e ) =>
360+ updateTranslation ( 'en' , 'content' , e . target . value )
361+ }
332362 placeholder = "Enter World Kids News content..."
333363 className = "min-h-[120px]"
334364 />
@@ -339,4 +369,4 @@ export default function WorldKidsNewsSection({ data, onChange }: WorldKidsNewsSe
339369 </ CardContent >
340370 </ Card >
341371 ) ;
342- }
372+ }
0 commit comments