Skip to content

Commit faa0cf7

Browse files
committed
chore: fix format
1 parent 75a7a90 commit faa0cf7

10 files changed

Lines changed: 543 additions & 447 deletions

File tree

src/components/FamilyPrayerCard.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ interface FamilyPrayerCardProps {
1717
isPreview?: boolean;
1818
}
1919

20-
const FamilyPrayerCard = ({ familyPrayer, isPreview = false }: FamilyPrayerCardProps) => {
20+
const FamilyPrayerCard = ({
21+
familyPrayer,
22+
isPreview = false,
23+
}: FamilyPrayerCardProps) => {
2124
const { t } = useTranslation();
2225

2326
const formatDate = (dateString: string) => {

src/components/Navigation.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const Navigation = () => {
3838
to="/family-prayers"
3939
className={cn(
4040
'text-sm font-medium transition-colors hover:text-primary',
41-
isActive('/family-prayers') ? 'text-primary' : 'text-muted-foreground'
41+
isActive('/family-prayers')
42+
? 'text-primary'
43+
: 'text-muted-foreground'
4244
)}
4345
>
4446
{t('nav.familyPrayers')}

src/components/PrayerDialog.tsx

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -127,23 +127,31 @@ export default function PrayerDialog({
127127
const existingWorldKidsNews = prayer?.world_kids_news?.[0];
128128
if (existingWorldKidsNews) {
129129
// Convert existing URLs to previews for display
130-
const imagePreviews = existingWorldKidsNews.image_urls.map(url => url);
131-
130+
const imagePreviews = existingWorldKidsNews.image_urls.map(
131+
(url) => url
132+
);
133+
132134
// Extract translations
133-
const enTranslation = existingWorldKidsNews.world_kids_news_translations?.find(t => t.language === 'en');
134-
const zhTranslation = existingWorldKidsNews.world_kids_news_translations?.find(t => t.language === 'zh-TW');
135-
135+
const enTranslation =
136+
existingWorldKidsNews.world_kids_news_translations?.find(
137+
(t) => t.language === 'en'
138+
);
139+
const zhTranslation =
140+
existingWorldKidsNews.world_kids_news_translations?.find(
141+
(t) => t.language === 'zh-TW'
142+
);
143+
136144
setWorldKidsNewsData({
137145
images: [], // No file objects for existing images
138146
imagePreviews: imagePreviews,
139147
translations: {
140-
en: {
141-
title: enTranslation?.title || '',
142-
content: enTranslation?.content || ''
148+
en: {
149+
title: enTranslation?.title || '',
150+
content: enTranslation?.content || '',
143151
},
144-
'zh-TW': {
145-
title: zhTranslation?.title || '',
146-
content: zhTranslation?.content || ''
152+
'zh-TW': {
153+
title: zhTranslation?.title || '',
154+
content: zhTranslation?.content || '',
147155
},
148156
},
149157
});
@@ -332,7 +340,9 @@ export default function PrayerDialog({
332340
}
333341
};
334342

335-
const uploadWorldKidsNewsImages = async (images: File[]): Promise<string[]> => {
343+
const uploadWorldKidsNewsImages = async (
344+
images: File[]
345+
): Promise<string[]> => {
336346
const uploadPromises = images.map(async (file) => {
337347
const fileExt = file.name.split('.').pop();
338348
const fileName = `${Date.now()}-${Math.random().toString(36).substring(2)}.${fileExt}`;
@@ -343,7 +353,9 @@ export default function PrayerDialog({
343353
.upload(filePath, file);
344354

345355
if (uploadError) {
346-
throw new Error(`Failed to upload ${file.name}: ${uploadError.message}`);
356+
throw new Error(
357+
`Failed to upload ${file.name}: ${uploadError.message}`
358+
);
347359
}
348360

349361
const { data } = supabase.storage
@@ -437,14 +449,19 @@ export default function PrayerDialog({
437449
if (translationsError) throw translationsError;
438450

439451
// Handle World Kids News if there are images (new or existing)
440-
if (worldKidsNewsData.images.length > 0 || worldKidsNewsData.imagePreviews.length > 0) {
452+
if (
453+
worldKidsNewsData.images.length > 0 ||
454+
worldKidsNewsData.imagePreviews.length > 0
455+
) {
441456
try {
442457
// Prepare image URLs - mix of new uploads and existing URLs
443458
let worldKidsNewsImageUrls: string[] = [];
444-
459+
445460
if (worldKidsNewsData.images.length > 0) {
446461
// Upload new images
447-
worldKidsNewsImageUrls = await uploadWorldKidsNewsImages(worldKidsNewsData.images);
462+
worldKidsNewsImageUrls = await uploadWorldKidsNewsImages(
463+
worldKidsNewsData.images
464+
);
448465
} else {
449466
// Use existing image URLs in their current order
450467
worldKidsNewsImageUrls = worldKidsNewsData.imagePreviews;
@@ -459,23 +476,27 @@ export default function PrayerDialog({
459476
}
460477

461478
// Create world kids news entry
462-
const { data: worldKidsNews, error: worldKidsNewsError } = await supabase
463-
.from('world_kids_news')
464-
.insert({
465-
prayer_id: prayerId,
466-
week_date: data.week_date,
467-
image_urls: worldKidsNewsImageUrls,
468-
})
469-
.select()
470-
.single();
479+
const { data: worldKidsNews, error: worldKidsNewsError } =
480+
await supabase
481+
.from('world_kids_news')
482+
.insert({
483+
prayer_id: prayerId,
484+
week_date: data.week_date,
485+
image_urls: worldKidsNewsImageUrls,
486+
})
487+
.select()
488+
.single();
471489

472490
if (worldKidsNewsError) throw worldKidsNewsError;
473491

474492
// Insert world kids news translations (only if there's content)
475493
const worldKidsNewsTranslations = [];
476-
494+
477495
// Add English translation if there's content
478-
if (worldKidsNewsData.translations.en.title || worldKidsNewsData.translations.en.content) {
496+
if (
497+
worldKidsNewsData.translations.en.title ||
498+
worldKidsNewsData.translations.en.content
499+
) {
479500
worldKidsNewsTranslations.push({
480501
world_kids_news_id: worldKidsNews.id,
481502
language: 'en',
@@ -485,7 +506,10 @@ export default function PrayerDialog({
485506
}
486507

487508
// Add Chinese translation if there's content
488-
if (worldKidsNewsData.translations['zh-TW'].title || worldKidsNewsData.translations['zh-TW'].content) {
509+
if (
510+
worldKidsNewsData.translations['zh-TW'].title ||
511+
worldKidsNewsData.translations['zh-TW'].content
512+
) {
489513
worldKidsNewsTranslations.push({
490514
world_kids_news_id: worldKidsNews.id,
491515
language: 'zh-TW',
@@ -500,7 +524,8 @@ export default function PrayerDialog({
500524
.from('world_kids_news_translations')
501525
.insert(worldKidsNewsTranslations);
502526

503-
if (worldKidsNewsTranslationsError) throw worldKidsNewsTranslationsError;
527+
if (worldKidsNewsTranslationsError)
528+
throw worldKidsNewsTranslationsError;
504529
}
505530
} catch (worldKidsNewsError) {
506531
console.error('Error saving world kids news:', worldKidsNewsError);

src/components/WorldKidsNewsSection.tsx

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { useState, useCallback } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { 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';
511
import { Input } from '@/components/ui/input';
612
import { Label } from '@/components/ui/label';
713
import { 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

Comments
 (0)