@umituz/react-native-ai-creations 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +92 -0
- package/package.json +55 -0
- package/src/domain/entities/Creation.ts +43 -0
- package/src/domain/entities/index.ts +6 -0
- package/src/domain/repositories/ICreationsRepository.ts +16 -0
- package/src/domain/repositories/index.ts +5 -0
- package/src/domain/value-objects/CreationsConfig.ts +48 -0
- package/src/domain/value-objects/index.ts +10 -0
- package/src/index.ts +68 -0
- package/src/infrastructure/adapters/createRepository.ts +15 -0
- package/src/infrastructure/adapters/index.ts +5 -0
- package/src/infrastructure/repositories/CreationsRepository.ts +100 -0
- package/src/infrastructure/repositories/index.ts +5 -0
- package/src/presentation/components/CreationCard.tsx +127 -0
- package/src/presentation/components/CreationThumbnail.tsx +41 -0
- package/src/presentation/components/CreationsHomeCard.tsx +176 -0
- package/src/presentation/components/EmptyState.tsx +58 -0
- package/src/presentation/components/FilterChips.tsx +103 -0
- package/src/presentation/components/index.ts +9 -0
- package/src/presentation/hooks/index.ts +7 -0
- package/src/presentation/hooks/useCreations.ts +44 -0
- package/src/presentation/hooks/useCreationsFilter.ts +46 -0
- package/src/presentation/hooks/useDeleteCreation.ts +51 -0
- package/src/presentation/screens/CreationsGalleryScreen.tsx +154 -0
- package/src/presentation/screens/index.ts +5 -0
- package/src/types.d.ts +72 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Ümit UZ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @umituz/react-native-ai-creations
|
|
2
|
+
|
|
3
|
+
AI-generated creations gallery with filtering, sharing, and management for React Native apps.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Gallery screen with grid/list view
|
|
8
|
+
- Filtering by creation type
|
|
9
|
+
- Share functionality
|
|
10
|
+
- Delete with confirmation
|
|
11
|
+
- Pull-to-refresh support
|
|
12
|
+
- Home card component for quick access
|
|
13
|
+
- Design system integration
|
|
14
|
+
- Firestore integration
|
|
15
|
+
- TanStack Query for data fetching
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @umituz/react-native-ai-creations
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Peer Dependencies
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install @umituz/react-native-design-system @umituz/react-native-firestore @umituz/react-native-localization @umituz/react-native-sharing @tanstack/react-query firebase
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
### Gallery Screen
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { CreationsGalleryScreen } from '@umituz/react-native-ai-creations';
|
|
35
|
+
|
|
36
|
+
// In your navigation
|
|
37
|
+
<Stack.Screen
|
|
38
|
+
name="CreationsGallery"
|
|
39
|
+
component={CreationsGalleryScreen}
|
|
40
|
+
/>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Home Card
|
|
44
|
+
|
|
45
|
+
```tsx
|
|
46
|
+
import { CreationsHomeCard } from '@umituz/react-native-ai-creations';
|
|
47
|
+
|
|
48
|
+
// In your home screen
|
|
49
|
+
<CreationsHomeCard
|
|
50
|
+
onPress={() => navigation.navigate('CreationsGallery')}
|
|
51
|
+
/>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Custom Hook
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
import { useCreations, useDeleteCreation } from '@umituz/react-native-ai-creations';
|
|
58
|
+
|
|
59
|
+
function MyComponent() {
|
|
60
|
+
const { data, isLoading, refetch } = useCreations();
|
|
61
|
+
const deleteMutation = useDeleteCreation();
|
|
62
|
+
|
|
63
|
+
// Use data...
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Configuration
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import { CreationsProvider, CreationsConfig } from '@umituz/react-native-ai-creations';
|
|
71
|
+
|
|
72
|
+
const config: CreationsConfig = {
|
|
73
|
+
collectionPath: 'users/{userId}/creations',
|
|
74
|
+
types: [
|
|
75
|
+
{ id: 'santa', label: 'santa.types.santa', icon: '🎅' },
|
|
76
|
+
{ id: 'elf', label: 'santa.types.elf', icon: '🧝' },
|
|
77
|
+
],
|
|
78
|
+
translations: {
|
|
79
|
+
title: 'creations.title',
|
|
80
|
+
empty: 'creations.empty',
|
|
81
|
+
delete: 'creations.delete',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
<CreationsProvider config={config}>
|
|
86
|
+
<App />
|
|
87
|
+
</CreationsProvider>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umituz/react-native-ai-creations",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "AI-generated creations gallery with filtering, sharing, and management for React Native apps",
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
|
+
"types": "./src/index.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"typecheck": "tsc --noEmit",
|
|
9
|
+
"lint": "tsc --noEmit",
|
|
10
|
+
"version:minor": "npm version minor -m 'chore: release v%s'",
|
|
11
|
+
"version:major": "npm version major -m 'chore: release v%s'"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react-native",
|
|
15
|
+
"ai",
|
|
16
|
+
"creations",
|
|
17
|
+
"gallery",
|
|
18
|
+
"firestore",
|
|
19
|
+
"tanstack-query",
|
|
20
|
+
"ddd",
|
|
21
|
+
"domain-driven-design"
|
|
22
|
+
],
|
|
23
|
+
"author": "Ümit UZ <umit@umituz.com>",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/umituz/react-native-ai-creations"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
31
|
+
"@umituz/react-native-design-system": "latest",
|
|
32
|
+
"@umituz/react-native-sharing": "latest",
|
|
33
|
+
"firebase": ">=11.0.0",
|
|
34
|
+
"react": ">=18.2.0",
|
|
35
|
+
"react-native": ">=0.74.0",
|
|
36
|
+
"react-native-safe-area-context": ">=4.0.0"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@tanstack/react-query": "^5.62.16",
|
|
40
|
+
"@types/react": "^19.0.0",
|
|
41
|
+
"firebase": "^11.0.0",
|
|
42
|
+
"react": "^19.0.0",
|
|
43
|
+
"react-native": "^0.76.0",
|
|
44
|
+
"react-native-safe-area-context": "^4.14.0",
|
|
45
|
+
"typescript": "^5.3.3"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"files": [
|
|
51
|
+
"src",
|
|
52
|
+
"README.md",
|
|
53
|
+
"LICENSE"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creation Entity
|
|
3
|
+
* Represents an AI-generated creation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface Creation {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly uri: string;
|
|
9
|
+
readonly type: string;
|
|
10
|
+
readonly originalUri?: string;
|
|
11
|
+
readonly createdAt: Date;
|
|
12
|
+
readonly isShared: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface CreationDocument {
|
|
16
|
+
readonly uri: string;
|
|
17
|
+
readonly originalImage?: string;
|
|
18
|
+
readonly transformedImage?: string;
|
|
19
|
+
readonly transformationType?: string;
|
|
20
|
+
readonly type?: string;
|
|
21
|
+
readonly status?: string;
|
|
22
|
+
readonly isShared: boolean;
|
|
23
|
+
readonly createdAt: FirebaseTimestamp;
|
|
24
|
+
readonly completedAt?: FirebaseTimestamp;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface FirebaseTimestamp {
|
|
28
|
+
toDate: () => Date;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function mapDocumentToCreation(
|
|
32
|
+
id: string,
|
|
33
|
+
data: CreationDocument,
|
|
34
|
+
): Creation {
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
uri: data.transformedImage || data.uri,
|
|
38
|
+
type: data.transformationType || data.type || "unknown",
|
|
39
|
+
originalUri: data.originalImage,
|
|
40
|
+
createdAt: data.createdAt?.toDate?.() || new Date(),
|
|
41
|
+
isShared: data.isShared ?? false,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creations Repository Interface
|
|
3
|
+
* Defines the contract for creations data access
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Creation } from "../entities/Creation";
|
|
7
|
+
|
|
8
|
+
export interface ICreationsRepository {
|
|
9
|
+
getAll(userId: string): Promise<Creation[]>;
|
|
10
|
+
delete(userId: string, creationId: string): Promise<boolean>;
|
|
11
|
+
updateShared(
|
|
12
|
+
userId: string,
|
|
13
|
+
creationId: string,
|
|
14
|
+
isShared: boolean,
|
|
15
|
+
): Promise<boolean>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creations Configuration Value Object
|
|
3
|
+
* Defines the configuration for creations feature
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export interface CreationType {
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly labelKey: string;
|
|
9
|
+
readonly icon: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CreationsTranslations {
|
|
13
|
+
readonly title: string;
|
|
14
|
+
readonly subtitle: string;
|
|
15
|
+
readonly empty: string;
|
|
16
|
+
readonly emptyDescription: string;
|
|
17
|
+
readonly deleteTitle: string;
|
|
18
|
+
readonly deleteMessage: string;
|
|
19
|
+
readonly photoCount: string;
|
|
20
|
+
readonly filterAll: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface CreationsConfig {
|
|
24
|
+
readonly collectionName: string;
|
|
25
|
+
readonly types: readonly CreationType[];
|
|
26
|
+
readonly translations: CreationsTranslations;
|
|
27
|
+
readonly maxThumbnails?: number;
|
|
28
|
+
readonly gridColumns?: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const DEFAULT_TRANSLATIONS: CreationsTranslations = {
|
|
32
|
+
title: "creations.title",
|
|
33
|
+
subtitle: "creations.subtitle",
|
|
34
|
+
empty: "creations.empty",
|
|
35
|
+
emptyDescription: "creations.emptyDescription",
|
|
36
|
+
deleteTitle: "creations.deleteTitle",
|
|
37
|
+
deleteMessage: "creations.deleteMessage",
|
|
38
|
+
photoCount: "creations.photoCount",
|
|
39
|
+
filterAll: "creations.filterAll",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const DEFAULT_CONFIG: CreationsConfig = {
|
|
43
|
+
collectionName: "creations",
|
|
44
|
+
types: [],
|
|
45
|
+
translations: DEFAULT_TRANSLATIONS,
|
|
46
|
+
maxThumbnails: 4,
|
|
47
|
+
gridColumns: 2,
|
|
48
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @umituz/react-native-ai-creations
|
|
3
|
+
*
|
|
4
|
+
* AI-generated creations gallery with filtering, sharing, and management
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import {
|
|
8
|
+
* CreationsGalleryScreen,
|
|
9
|
+
* CreationsHomeCard,
|
|
10
|
+
* useCreations,
|
|
11
|
+
* createCreationsRepository,
|
|
12
|
+
* } from '@umituz/react-native-ai-creations';
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// DOMAIN LAYER - Entities
|
|
17
|
+
// =============================================================================
|
|
18
|
+
|
|
19
|
+
export type { Creation, CreationDocument } from "./domain/entities";
|
|
20
|
+
export { mapDocumentToCreation } from "./domain/entities";
|
|
21
|
+
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// DOMAIN LAYER - Value Objects
|
|
24
|
+
// =============================================================================
|
|
25
|
+
|
|
26
|
+
export type {
|
|
27
|
+
CreationType,
|
|
28
|
+
CreationsTranslations,
|
|
29
|
+
CreationsConfig,
|
|
30
|
+
} from "./domain/value-objects";
|
|
31
|
+
export { DEFAULT_TRANSLATIONS, DEFAULT_CONFIG } from "./domain/value-objects";
|
|
32
|
+
|
|
33
|
+
// =============================================================================
|
|
34
|
+
// DOMAIN LAYER - Repository Interface
|
|
35
|
+
// =============================================================================
|
|
36
|
+
|
|
37
|
+
export type { ICreationsRepository } from "./domain/repositories";
|
|
38
|
+
|
|
39
|
+
// =============================================================================
|
|
40
|
+
// INFRASTRUCTURE LAYER
|
|
41
|
+
// =============================================================================
|
|
42
|
+
|
|
43
|
+
export { CreationsRepository } from "./infrastructure/repositories";
|
|
44
|
+
export { createCreationsRepository } from "./infrastructure/adapters";
|
|
45
|
+
|
|
46
|
+
// =============================================================================
|
|
47
|
+
// PRESENTATION LAYER - Hooks
|
|
48
|
+
// =============================================================================
|
|
49
|
+
|
|
50
|
+
export { useCreations } from "./presentation/hooks/useCreations";
|
|
51
|
+
export { useDeleteCreation } from "./presentation/hooks/useDeleteCreation";
|
|
52
|
+
export { useCreationsFilter } from "./presentation/hooks/useCreationsFilter";
|
|
53
|
+
|
|
54
|
+
// =============================================================================
|
|
55
|
+
// PRESENTATION LAYER - Components
|
|
56
|
+
// =============================================================================
|
|
57
|
+
|
|
58
|
+
export { CreationThumbnail } from "./presentation/components/CreationThumbnail";
|
|
59
|
+
export { CreationCard } from "./presentation/components/CreationCard";
|
|
60
|
+
export { CreationsHomeCard } from "./presentation/components/CreationsHomeCard";
|
|
61
|
+
export { FilterChips } from "./presentation/components/FilterChips";
|
|
62
|
+
export { EmptyState } from "./presentation/components/EmptyState";
|
|
63
|
+
|
|
64
|
+
// =============================================================================
|
|
65
|
+
// PRESENTATION LAYER - Screens
|
|
66
|
+
// =============================================================================
|
|
67
|
+
|
|
68
|
+
export { CreationsGalleryScreen } from "./presentation/screens/CreationsGalleryScreen";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repository Factory
|
|
3
|
+
* Creates repository instance with given configuration
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Firestore } from "firebase/firestore";
|
|
7
|
+
import { CreationsRepository } from "../repositories/CreationsRepository";
|
|
8
|
+
import type { ICreationsRepository } from "../../domain/repositories/ICreationsRepository";
|
|
9
|
+
|
|
10
|
+
export function createCreationsRepository(
|
|
11
|
+
db: Firestore | null,
|
|
12
|
+
collectionName: string,
|
|
13
|
+
): ICreationsRepository {
|
|
14
|
+
return new CreationsRepository(db, collectionName);
|
|
15
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creations Repository Implementation
|
|
3
|
+
* Firestore operations for user creations
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
declare const __DEV__: boolean;
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
collection,
|
|
10
|
+
doc,
|
|
11
|
+
getDocs,
|
|
12
|
+
deleteDoc,
|
|
13
|
+
updateDoc,
|
|
14
|
+
query,
|
|
15
|
+
orderBy,
|
|
16
|
+
type Firestore,
|
|
17
|
+
} from "firebase/firestore";
|
|
18
|
+
import type { ICreationsRepository } from "../../domain/repositories/ICreationsRepository";
|
|
19
|
+
import type { Creation, CreationDocument } from "../../domain/entities/Creation";
|
|
20
|
+
import { mapDocumentToCreation } from "../../domain/entities/Creation";
|
|
21
|
+
|
|
22
|
+
export class CreationsRepository implements ICreationsRepository {
|
|
23
|
+
constructor(
|
|
24
|
+
private readonly db: Firestore | null,
|
|
25
|
+
private readonly collectionName: string,
|
|
26
|
+
) {}
|
|
27
|
+
|
|
28
|
+
private getUserCollection(userId: string) {
|
|
29
|
+
if (!this.db) return null;
|
|
30
|
+
return collection(this.db, "users", userId, this.collectionName);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async getAll(userId: string): Promise<Creation[]> {
|
|
34
|
+
if (__DEV__) {
|
|
35
|
+
console.log("[CreationsRepository] getAll()", { userId });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const userCollection = this.getUserCollection(userId);
|
|
39
|
+
if (!userCollection) return [];
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const q = query(userCollection, orderBy("createdAt", "desc"));
|
|
43
|
+
const snapshot = await getDocs(q);
|
|
44
|
+
|
|
45
|
+
if (__DEV__) {
|
|
46
|
+
console.log("[CreationsRepository] Fetched:", snapshot.docs.length);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return snapshot.docs.map((docSnap) => {
|
|
50
|
+
const data = docSnap.data() as CreationDocument;
|
|
51
|
+
return mapDocumentToCreation(docSnap.id, data);
|
|
52
|
+
});
|
|
53
|
+
} catch (error) {
|
|
54
|
+
if (__DEV__) {
|
|
55
|
+
console.error("[CreationsRepository] getAll() ERROR", error);
|
|
56
|
+
}
|
|
57
|
+
return [];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async delete(userId: string, creationId: string): Promise<boolean> {
|
|
62
|
+
if (!this.db) return false;
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const docRef = doc(
|
|
66
|
+
this.db,
|
|
67
|
+
"users",
|
|
68
|
+
userId,
|
|
69
|
+
this.collectionName,
|
|
70
|
+
creationId,
|
|
71
|
+
);
|
|
72
|
+
await deleteDoc(docRef);
|
|
73
|
+
return true;
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async updateShared(
|
|
80
|
+
userId: string,
|
|
81
|
+
creationId: string,
|
|
82
|
+
isShared: boolean,
|
|
83
|
+
): Promise<boolean> {
|
|
84
|
+
if (!this.db) return false;
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
const docRef = doc(
|
|
88
|
+
this.db,
|
|
89
|
+
"users",
|
|
90
|
+
userId,
|
|
91
|
+
this.collectionName,
|
|
92
|
+
creationId,
|
|
93
|
+
);
|
|
94
|
+
await updateDoc(docRef, { isShared });
|
|
95
|
+
return true;
|
|
96
|
+
} catch {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CreationCard Component
|
|
3
|
+
* Displays a creation item with actions
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useMemo, useCallback } from "react";
|
|
7
|
+
import { View, Image, TouchableOpacity, StyleSheet } from "react-native";
|
|
8
|
+
import {
|
|
9
|
+
AtomicText,
|
|
10
|
+
AtomicIcon,
|
|
11
|
+
useAppDesignTokens,
|
|
12
|
+
} from "@umituz/react-native-design-system";
|
|
13
|
+
import type { Creation } from "../../domain/entities/Creation";
|
|
14
|
+
import type { CreationType } from "../../domain/value-objects/CreationsConfig";
|
|
15
|
+
|
|
16
|
+
interface CreationCardProps {
|
|
17
|
+
readonly creation: Creation;
|
|
18
|
+
readonly types: readonly CreationType[];
|
|
19
|
+
readonly onShare: (creation: Creation) => void;
|
|
20
|
+
readonly onDelete: (creation: Creation) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function CreationCard({
|
|
24
|
+
creation,
|
|
25
|
+
types,
|
|
26
|
+
onShare,
|
|
27
|
+
onDelete,
|
|
28
|
+
}: CreationCardProps) {
|
|
29
|
+
const tokens = useAppDesignTokens();
|
|
30
|
+
|
|
31
|
+
const typeConfig = types.find((t) => t.id === creation.type);
|
|
32
|
+
const icon = typeConfig?.icon || "🎨";
|
|
33
|
+
const label = typeConfig?.labelKey || creation.type;
|
|
34
|
+
|
|
35
|
+
const handleShare = useCallback(() => onShare(creation), [creation, onShare]);
|
|
36
|
+
const handleDelete = useCallback(
|
|
37
|
+
() => onDelete(creation),
|
|
38
|
+
[creation, onDelete],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const formattedDate = useMemo(() => {
|
|
42
|
+
const date =
|
|
43
|
+
creation.createdAt instanceof Date
|
|
44
|
+
? creation.createdAt
|
|
45
|
+
: new Date(creation.createdAt);
|
|
46
|
+
return date.toLocaleDateString(undefined, {
|
|
47
|
+
day: "numeric",
|
|
48
|
+
month: "short",
|
|
49
|
+
hour: "2-digit",
|
|
50
|
+
minute: "2-digit",
|
|
51
|
+
});
|
|
52
|
+
}, [creation.createdAt]);
|
|
53
|
+
|
|
54
|
+
const styles = useMemo(
|
|
55
|
+
() =>
|
|
56
|
+
StyleSheet.create({
|
|
57
|
+
container: {
|
|
58
|
+
flexDirection: "row",
|
|
59
|
+
backgroundColor: tokens.colors.surface,
|
|
60
|
+
borderRadius: tokens.spacing.md,
|
|
61
|
+
overflow: "hidden",
|
|
62
|
+
},
|
|
63
|
+
thumbnail: {
|
|
64
|
+
width: 100,
|
|
65
|
+
height: 100,
|
|
66
|
+
},
|
|
67
|
+
content: {
|
|
68
|
+
flex: 1,
|
|
69
|
+
padding: tokens.spacing.md,
|
|
70
|
+
justifyContent: "space-between",
|
|
71
|
+
},
|
|
72
|
+
typeRow: {
|
|
73
|
+
flexDirection: "row",
|
|
74
|
+
alignItems: "center",
|
|
75
|
+
gap: tokens.spacing.sm,
|
|
76
|
+
},
|
|
77
|
+
icon: {
|
|
78
|
+
fontSize: 20,
|
|
79
|
+
},
|
|
80
|
+
typeText: {
|
|
81
|
+
...tokens.typography.bodyMedium,
|
|
82
|
+
fontWeight: "600",
|
|
83
|
+
color: tokens.colors.textPrimary,
|
|
84
|
+
},
|
|
85
|
+
dateText: {
|
|
86
|
+
...tokens.typography.bodySmall,
|
|
87
|
+
color: tokens.colors.textSecondary,
|
|
88
|
+
},
|
|
89
|
+
actions: {
|
|
90
|
+
flexDirection: "row",
|
|
91
|
+
gap: tokens.spacing.sm,
|
|
92
|
+
},
|
|
93
|
+
actionBtn: {
|
|
94
|
+
width: 36,
|
|
95
|
+
height: 36,
|
|
96
|
+
borderRadius: 18,
|
|
97
|
+
backgroundColor: tokens.colors.backgroundSecondary,
|
|
98
|
+
justifyContent: "center",
|
|
99
|
+
alignItems: "center",
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
[tokens],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
<View style={styles.container}>
|
|
107
|
+
<Image source={{ uri: creation.uri }} style={styles.thumbnail} />
|
|
108
|
+
<View style={styles.content}>
|
|
109
|
+
<View>
|
|
110
|
+
<View style={styles.typeRow}>
|
|
111
|
+
<AtomicText style={styles.icon}>{icon}</AtomicText>
|
|
112
|
+
<AtomicText style={styles.typeText}>{label}</AtomicText>
|
|
113
|
+
</View>
|
|
114
|
+
<AtomicText style={styles.dateText}>{formattedDate}</AtomicText>
|
|
115
|
+
</View>
|
|
116
|
+
<View style={styles.actions}>
|
|
117
|
+
<TouchableOpacity style={styles.actionBtn} onPress={handleShare}>
|
|
118
|
+
<AtomicIcon name="share-social" size="sm" color="primary" />
|
|
119
|
+
</TouchableOpacity>
|
|
120
|
+
<TouchableOpacity style={styles.actionBtn} onPress={handleDelete}>
|
|
121
|
+
<AtomicIcon name="trash" size="sm" color="error" />
|
|
122
|
+
</TouchableOpacity>
|
|
123
|
+
</View>
|
|
124
|
+
</View>
|
|
125
|
+
</View>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CreationThumbnail Component
|
|
3
|
+
* Displays a single creation thumbnail
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import React, { useMemo } from "react";
|
|
7
|
+
import { Image, TouchableOpacity, StyleSheet } from "react-native";
|
|
8
|
+
import { useAppDesignTokens } from "@umituz/react-native-design-system";
|
|
9
|
+
|
|
10
|
+
interface CreationThumbnailProps {
|
|
11
|
+
readonly uri: string;
|
|
12
|
+
readonly size?: number;
|
|
13
|
+
readonly onPress?: () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function CreationThumbnail({
|
|
17
|
+
uri,
|
|
18
|
+
size = 72,
|
|
19
|
+
onPress,
|
|
20
|
+
}: CreationThumbnailProps) {
|
|
21
|
+
const tokens = useAppDesignTokens();
|
|
22
|
+
|
|
23
|
+
const styles = useMemo(
|
|
24
|
+
() =>
|
|
25
|
+
StyleSheet.create({
|
|
26
|
+
thumbnail: {
|
|
27
|
+
width: size,
|
|
28
|
+
height: size,
|
|
29
|
+
borderRadius: tokens.spacing.sm,
|
|
30
|
+
backgroundColor: tokens.colors.backgroundSecondary,
|
|
31
|
+
},
|
|
32
|
+
}),
|
|
33
|
+
[tokens, size],
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<TouchableOpacity onPress={onPress} disabled={!onPress}>
|
|
38
|
+
<Image source={{ uri }} style={styles.thumbnail} />
|
|
39
|
+
</TouchableOpacity>
|
|
40
|
+
);
|
|
41
|
+
}
|