Squash merge feat/expo-app: app-expo, .cursor, workflows, package.json, .husky; remove app-android, app-ios, react-app
This commit is contained in:
31
app-expo/src/features/memoir/mappers.ts
Normal file
31
app-expo/src/features/memoir/mappers.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import type { Chapter, ChapterViewModel, ImageAsset } from './types';
|
||||
|
||||
function countByStatus(images: ImageAsset[], status: string): number {
|
||||
return images.filter((img) => img.status === status).length;
|
||||
}
|
||||
|
||||
export function toChapterViewModel(chapter: Chapter): ChapterViewModel {
|
||||
const images = chapter.images ?? [];
|
||||
const completedCount = countByStatus(images, 'completed');
|
||||
|
||||
return {
|
||||
id: chapter.id,
|
||||
title: chapter.title,
|
||||
category: chapter.category,
|
||||
orderIndex: chapter.order_index,
|
||||
isEmpty: chapter.status === 'empty' || !chapter.content,
|
||||
isNew: chapter.is_new,
|
||||
hasImages: images.length > 0,
|
||||
allImagesReady: images.length > 0 && completedCount === images.length,
|
||||
pendingImageCount:
|
||||
countByStatus(images, 'pending') + countByStatus(images, 'processing'),
|
||||
failedImageCount: countByStatus(images, 'failed'),
|
||||
sections: chapter.sections ?? [],
|
||||
coverImageUrl: chapter.cover_image?.url ?? null,
|
||||
updatedAt: chapter.updated_at,
|
||||
};
|
||||
}
|
||||
|
||||
export function toChapterViewModels(chapters: Chapter[]): ChapterViewModel[] {
|
||||
return chapters.map(toChapterViewModel);
|
||||
}
|
||||
Reference in New Issue
Block a user