Código - Planner App
Código - Planner App
App.js:
import React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { StyleSheet, Text, View, TouchableOpacity, ImageBackground } from
'react-native';
import TarefasScreen from './TarefasScreen';
import ProjetosScreen from './ProjetosScreen'; // Certifique-se de que você
tem essa tela criada
import 'react-native-gesture-handler';
<View style={styles.buttonContainer}>
<TouchableOpacity
style={styles.button}
onPress={() => navigation.navigate('Tarefas')}
>
<Text style={styles.buttonText}>TAREFAS</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => navigation.navigate('Projetos')} // Botão que leva à
tela de Projetos
>
<Text style={styles.buttonText}>PROJETOS</Text>
</TouchableOpacity>
</View>
</ImageBackground>
);
}
export default function App() {
return (
<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen} options={{ title:
'PLANNER APP' }} />
<Stack.Screen name="Tarefas" component={TarefasScreen} options={{
title: 'TAREFAS' }} />
<Stack.Screen name="Projetos" component={ProjetosScreen} options={{
title: 'PROJETOS' }} />
</Stack.Navigator>
</NavigationContainer>
);
}
useEffect(() => {
const loadTasks = async () => {
const savedTasks = await AsyncStorage.getItem('tasks');
if (savedTasks) {
setTasks(JSON.parse(savedTasks));
}
};
loadTasks();
}, []);
useEffect(() => {
const saveTasks = async () => {
await AsyncStorage.setItem('tasks', JSON.stringify(tasks));
};
saveTasks();
}, [tasks]);
return (
<View style={styles.container}>
<Text style={styles.title}>Lista de Tarefas</Text>
<View style={styles.inputContainer}>
<TextInput
style={styles.input}
placeholder="Nova tarefa"
value={task}
onChangeText={setTask}
/>
<TouchableOpacity style={styles.addButton} onPress={addTask}>
<Text style={styles.addButtonText}>+</Text>
</TouchableOpacity>
</View>
<FlatList
data={tasks}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<View style={styles.taskItem}>
<View style={styles.actionButtons}>
<TouchableOpacity onPress={() => toggleTaskCompletion(item.id)}>
<Text style={item.completed ? styles.taskCompleted :
styles.taskPending}>
{item.completed ? "☑️" : "⬜"}
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => deleteTask(item.id)}>
<Text style={styles.deleteButton}>🗑️</Text>
</TouchableOpacity>
</View>
{item.isEditing ? (
<TextInput
style={styles.taskTextInput}
value={item.text}
onChangeText={(text) => editTask(item.id, text)}
onBlur={() => finishEditingTask(item.id)}
/>
) : (
<TouchableOpacity onPress={() => startEditingTask(item.id)}>
<Text style={item.completed ? styles.taskTextCompleted :
styles.taskText}>
{item.text}
</Text>
</TouchableOpacity>
)}
</View>
)}
/>
</View>
);
}
ProjetosScreen.js:
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, TouchableOpacity, TextInput, FlatList } from
'react-native';
import { TextInputMask } from 'react-native-masked-text';
import AsyncStorage from '@react-native-async-storage/async-storage';
useEffect(() => {
// Load projects from AsyncStorage when the screen is loaded
const loadProjects = async () => {
const storedProjects = await AsyncStorage.getItem('projects');
if (storedProjects) {
setProjects(JSON.parse(storedProjects));
}
};
loadProjects();
}, []);
useEffect(() => {
// Save projects to AsyncStorage whenever they change
const saveProjects = async () => {
await AsyncStorage.setItem('projects', JSON.stringify(projects));
};
saveProjects();
}, [projects]);
const addProject = () => {
setProjects([
...projects,
{
id: Date.now().toString(),
title: '',
startDate: '',
endDate: '',
description: '',
notes: '',
isCompleted: false, // Novo campo para indicar se o projeto foi
concluído
},
]);
};
return (
<View style={styles.container}>
<FlatList
data={projects}
keyExtractor={(item) => item.id}
renderItem={({ item }) => (
<View style={styles.card}>
<View style={styles.cardHeader}>
<View style={styles.buttonContainer}>
<TouchableOpacity
onPress={() => toggleCompletion(item.id)}
style={[styles.completionCheckbox, item.isCompleted &&
styles.checked]}
>
{item.isCompleted && <Text
style={styles.checkedText}>✔</Text>}
</TouchableOpacity>
<TextInput
style={styles.titleInput}
placeholder="Título do Projeto"
value={item.title}
onChangeText={(text) =>
setProjects(projects.map((proj) =>
proj.id === item.id ? { ...proj, title: text } : proj
))
}
/>
</View>
<TouchableOpacity onPress={() => deleteProject(item.id)}
style={styles.deleteButton}>
<Text style={styles.deleteButtonText}>X</Text>
</TouchableOpacity>
</View>
<View style={styles.dateContainer}>
<TextInputMask
style={styles.dateInput}
placeholder="Data de Início"
type={'datetime'}
options={{
format: 'DD/MM/YYYY',
}}
value={item.startDate}
onChangeText={(text) =>
setProjects(projects.map((proj) =>
proj.id === item.id ? { ...proj, startDate: text } : proj
))
}
/>
<TextInputMask
style={styles.dateInput}
placeholder="Data de Fim"
type={'datetime'}
options={{
format: 'DD/MM/YYYY',
}}
value={item.endDate}
onChangeText={(text) =>
setProjects(projects.map((proj) =>
proj.id === item.id ? { ...proj, endDate: text } : proj
))
}
/>
</View>
<TextInput
style={styles.descriptionInput}
placeholder="Descrição"
value={item.description}
multiline
onChangeText={(text) =>
setProjects(projects.map((proj) =>
proj.id === item.id ? { ...proj, description: text } : proj
))
}
/>
<TextInput
style={styles.notesInput}
placeholder="Anotações"
value={item.notes}
multiline
onChangeText={(text) =>
setProjects(projects.map((proj) =>
proj.id === item.id ? { ...proj, notes: text } : proj
))
}
/>
</View>
)}
/>