generated from google-gemini/aistudio-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
62 lines (55 loc) · 1.83 KB
/
App.tsx
File metadata and controls
62 lines (55 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { useState, useCallback } from 'react';
import { Routes, Route, useNavigate } from 'react-router-dom';
import { List } from './types';
import { useLocalStorage } from './hooks/useLocalStorage';
import HomeView from './components/HomeView';
import ListView from './components/ListView';
import CreateListView from './components/CreateListView';
import Header from './components/Header';
import Footer from './components/Footer';
function App() {
const [lists, setLists] = useLocalStorage<List[]>('lists', []);
const navigate = useNavigate();
const addList = (title: string, description: string, isPublic: boolean) => {
const newList: List = {
id: crypto.randomUUID(),
title,
description,
isPublic,
items: [],
createdAt: new Date().toISOString(),
};
setLists(prevLists => [...prevLists, newList]);
navigate(`/list/${newList.id}`);
};
const updateList = useCallback((updatedList: List) => {
setLists(prevLists => prevLists.map(list => list.id === updatedList.id ? updatedList : list));
}, [setLists]);
const deleteList = (listId: string) => {
setLists(prevLists => prevLists.filter(list => list.id !== listId));
navigate('/');
};
return (
<div className="flex flex-col min-h-screen">
<Header />
<main className="flex-grow container mx-auto px-4 py-8">
<Routes>
<Route path="/" element={<HomeView lists={lists} />} />
<Route path="/create" element={<CreateListView addList={addList} />} />
<Route
path="/list/:id"
element={
<ListView
lists={lists}
updateList={updateList}
deleteList={deleteList}
/>
}
/>
</Routes>
</main>
<Footer />
</div>
);
}
export default App;