import React, { useEffect, useState } from 'react'; import { View, Text, StyleSheet, TouchableOpacity, FlatList, TextInput, Modal, Alert, } from 'react-native'; import AsyncStorage from '@react-native-async-storage/async-storage'; import { AntDesign } from '@expo/vector-icons'; import { Song } from '@/types/song'; import {loadFavoriteFolders, saveFavoriteFolders} from "@/service/async-storage"; interface Folder { id: string; name: string; songs: Song[]; expanded: boolean; } export default function FavoriteScreen() { const [folders, setFolders] = useState([]); const [modalVisible, setModalVisible] = useState(false); const [newFolderName, setNewFolderName] = useState(''); useEffect(() => { loadFavoriteFolders().then((folders) => setFolders(folders)) }, []); const toggleFolder = (id: string) => { const updated = folders.map((f) => f.id === id ? { ...f, expanded: !f.expanded } : f ); setFolders(updated); saveFavoriteFolders(updated); }; const addFolder = () => { if (!newFolderName.trim()) return; const newFolder: Folder = { id: Date.now().toString(), name: newFolderName.trim(), songs: [], expanded: false, }; const updated = [...folders, newFolder]; setFolders(updated); saveFavoriteFolders(updated); setNewFolderName(''); setModalVisible(false); }; const deleteFolder = (id: string) => { Alert.alert('삭제 확인', '이 폴더를 삭제하시겠습니까?', [ { text: '취소', style: 'cancel' }, { text: '삭제', style: 'destructive', onPress: () => { const updated = folders.filter((f) => f.id !== id); setFolders(updated); saveFavoriteFolders(updated); }, }, ]); }; const renderFolder = ({ item }: { item: Folder }) => ( toggleFolder(item.id)} style={styles.folderHeader} > {item.name} deleteFolder(item.id)}> {item.expanded && item.songs.map((song) => ( 🎵 {song.title} - {song.singer} ))} ); return ( ⭐ 즐겨찾기 item.id} contentContainerStyle={{ paddingBottom: 80 }} /> setModalVisible(true)} > + 새 폴더 추가 {/* 폴더 추가 모달 */} 폴더 이름 입력 setModalVisible(false)} > 취소 확인 ); } const styles = StyleSheet.create({ container: { flex: 1, padding: 16 }, title: { fontSize: 20, fontWeight: 'bold', marginBottom: 12 }, folderContainer: { marginBottom: 12, borderBottomWidth: 1, borderColor: '#ddd' }, folderHeader: { flexDirection: 'row', justifyContent: 'space-between', paddingVertical: 8, alignItems: 'center', }, folderTitle: { fontSize: 16, fontWeight: 'bold' }, songItem: { paddingLeft: 16, paddingVertical: 4 }, songText: { fontSize: 14 }, addButton: { position: 'absolute', bottom: 20, left: 20, right: 20, backgroundColor: '#007AFF', padding: 16, borderRadius: 10, alignItems: 'center', }, addButtonText: { color: 'white', fontWeight: 'bold' }, modalOverlay: { flex: 1, backgroundColor: '#00000099', justifyContent: 'center', alignItems: 'center', }, modalContent: { width: 300, backgroundColor: 'white', borderRadius: 10, padding: 16, }, input: { borderWidth: 1, borderColor: '#ddd', borderRadius: 6, padding: 8, }, modalButton: { flex: 1, padding: 10, marginHorizontal: 5, borderRadius: 6, alignItems: 'center', }, });