import { toast } from '@backpackapp-io/react-native-toast'; import Ionicons from '@expo/vector-icons/Ionicons'; import { Stack, useLocalSearchParams, useRouter } from 'expo-router'; import React, { useState } from 'react'; import { Pressable, ScrollView, StyleSheet, TextInput, View } from 'react-native'; import { EmojiPopup } from 'react-native-emoji-popup'; import { ThemedView } from '../..//components/ThemedView'; import { Category, CategoryQuery } from '../..//models/category'; import { CategoryRepository } from '../..//repositories/CategoryRepository'; import { ThemedText } from '../../components/ThemedText'; import { SQLiteDataService } from '../../services/data/sqliteDataService'; const categoryRepository = new CategoryRepository(new SQLiteDataService(CategoryQuery)); export default function CategoryForm() { const { category: categoryJson } = useLocalSearchParams(); const category: Category = categoryJson ? JSON.parse(categoryJson as string) : null; const router = useRouter(); const [newCategory, setNewCategory] = useState({ title: category?.title || '', icon: category?.icon || '', }); return ( null }} /> Taskeep! < Pressable onPress={() => { router.back(); } }> < ScrollView style={styles.scrollView} > Add a new category setNewCategory({ ...newCategory, icon: emoji })} > {newCategory.icon != "" ? {newCategory.icon} : } {newCategory.icon != "" ? "Change" : "Select"} icon setNewCategory({ ...newCategory, title: e.nativeEvent.text })} /> { if (newCategory.title!.length > 0 && newCategory.icon!.length != 1) { if (category && category.id) { // Update existing task categoryRepository.update(category.id, { ...category, ...newCategory }).then(() => { toast.success("Category updated successfully!"); router.back(); }); } else { // Create new task categoryRepository.create(new Category(newCategory.title, newCategory.icon)).then(() => { toast.success("Category added successfully!"); router.back(); }); } } else { toast.error("Please select an icon and enter a title for the category."); } }}> {category?.id ? "Update" : "Add"} Category < View style={{ height: 50 }} /> ); } const styles = StyleSheet.create({ mainContainer: { flex: 1, }, headerContainer: { flexDirection: 'row', alignItems: 'center', justifyContent: 'space-between', gap: 8, paddingHorizontal: 24, paddingTop: 50, paddingBottom: 18, backgroundColor: '#6a254fff', }, scrollView: { padding: 24, flex: 1, }, stepContainer: { gap: 8, marginBottom: 8, marginTop: 16, flexDirection: 'row', alignItems: 'center' }, reactLogo: { height: 178, width: 290, bottom: 0, left: 0, position: 'absolute', }, inputText: { backgroundColor: '#fff', height: 50, color: '#333333', borderRadius: 8, padding: 10, lineHeight: 30, alignItems: 'center', justifyContent: 'center', paddingHorizontal: 32, flex: 1, borderWidth: 2, borderColor: '#ccc', }, textArea: { backgroundColor: '#fff', color: '#333333', borderRadius: 8, padding: 10, paddingHorizontal: 32, minHeight: 100, textAlignVertical: 'top' }, addButton: { flexDirection: 'row', gap: 8, backgroundColor: '#b91f7eff', color: '#fff', borderRadius: 8, padding: 20, alignItems: 'center', justifyContent: 'center', }, addButtonText: { color: '#fff', fontSize: 16, fontWeight: 'bold', }, addIconView: { flexDirection: 'row', color: '#fff', gap: 4, backgroundColor: '#transparent', borderWidth: 2, borderColor: '#ccc', padding: 12, borderRadius: 10, alignItems: 'center', justifyContent: 'center', }, });