modify the code to optimize for all screens (mobile and desktop) // src/App.js import…
- User
modify the code to optimize for all screens (mobile and desktop)
// src/App.js import React, { useState, useEffect } from 'react'; import { db } from './db';
// Import Icons import { AiFillHome } from 'react-icons/ai'; import { FaUsers, FaEdit, FaTrash, FaCheck, FaUndo, FaSave } from 'react-icons/fa';
function App() { const [customers, setCustomers] = useState([]); const [selectedCustomer, setSelectedCustomer] = useState(null); const [input, setInput] = useState(''); const [newCustomer, setNewCustomer] = useState(''); const [editingCustomer, setEditingCustomer] = useState(null); const [editName, setEditName] = useState(''); const [editingTodoIndex, setEditingTodoIndex] = useState(null); const [editTodoText, setEditTodoText] = useState('');
// New state variables for search, filter, theme, and tabs const [customerSearchTerm, setCustomerSearchTerm] = useState(''); const [todoFilter, setTodoFilter] = useState('all'); const [isDarkMode, setIsDarkMode] = useState(() => { const storedThemePreference = localStorage.getItem('isDarkMode'); return storedThemePreference ? JSON.parse(storedThemePreference) : false; });
// New state variable for active tab const [activeTab, setActiveTab] = useState('home'); // 'home' or 'customers'
// New state variable for expanded customers const [expandedCustomerIds, setExpandedCustomerIds] = useState([]);
useEffect(() => { loadCustomers(); }, []);
useEffect(() => { // Save theme preference localStorage.setItem('isDarkMode', JSON.stringify(isDarkMode)); }, [isDarkMode]);
const toggleDarkMode = () => { setIsDarkMode((prevMode) => !prevMode); };
const loadCustomers = async () => { try { const allCustomers = await db.customers.toArray(); setCustomers(allCustomers); if (allCustomers.length > 0) { // Preserve the selected customer if possible const currentCustomer = allCustomers.find( (c) => c.id === selectedCustomer?.id ); setSelectedCustomer(currentCustomer || null); // Do not automatically select the first customer } else { setSelectedCustomer(null); } } catch (error) { console.error('Error loading customers:', error); } };
const addCustomer = async () => { if (newCustomer.trim()) { try { await db.customers.add({ name: newCustomer, todos: [] }); await loadCustomers(); setNewCustomer(''); } catch (error) { console.error('Error adding customer:', error); } } };
const startEditingCustomer = (customer) => { setEditingCustomer(customer); setEditName(customer.name); };
const saveCustomerEdit = async () => { if (editName.trim() && editingCustomer) { try { await db.customers.update(editingCustomer.id, { name: editName }); const updatedCustomer = { ...editingCustomer, name: editName };
if (selectedCustomer && selectedCustomer.id === updatedCustomer.id) { setSelectedCustomer(updatedCustomer); } setCustomers((prevCustomers) => prevCustomers.map((customer) => customer.id === updatedCustomer.id ? updatedCustomer : customer ) ); setEditingCustomer(null); setEditName(''); } catch (error) { console.error('Error updating customer:', error); } } - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.