Initial commit
This commit is contained in:
48
screens/LoginScreen.tsx
Normal file
48
screens/LoginScreen.tsx
Normal file
@@ -0,0 +1,48 @@
|
||||
import React, { useState } from 'react';
|
||||
import { View, TextInput, Button, StyleSheet } from 'react-native';
|
||||
import { signInWithEmailAndPassword, createUserWithEmailAndPassword } from 'firebase/auth';
|
||||
import { auth } from '../config/firebase';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { setUser } from '../store/authSlice';
|
||||
|
||||
function LoginScreen({ navigation }: any) {
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const handleLogin = async () => {
|
||||
try {
|
||||
const userCredential = await signInWithEmailAndPassword(auth, email, password);
|
||||
dispatch(setUser({ uid: userCredential.user.uid, email: userCredential.user.email! }));
|
||||
navigation.replace('Projects');
|
||||
} catch (error: any) {
|
||||
alert(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRegister = async () => {
|
||||
try {
|
||||
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
|
||||
dispatch(setUser({ uid: userCredential.user.uid, email: userCredential.user.email! }));
|
||||
navigation.replace('Projects');
|
||||
} catch (error: any) {
|
||||
alert(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<TextInput style={styles.input} placeholder="Email" value={email} onChangeText={setEmail} />
|
||||
<TextInput style={styles.input} placeholder="Jelszó" value={password} onChangeText={setPassword} secureTextEntry />
|
||||
<Button title="Bejelentkezés" onPress={handleLogin} color="#ff00ff" />
|
||||
<Button title="Regisztráció" onPress={handleRegister} color="#ff00ff" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, padding: 16, justifyContent: 'center', backgroundColor: '#000000' },
|
||||
input: { borderWidth: 1, borderColor: '#333333', padding: 8, marginBottom: 16, borderRadius: 4, backgroundColor: '#1a1a1a', color: '#ffffff' },
|
||||
});
|
||||
|
||||
export default LoginScreen;
|
||||
36
screens/ProjectDetailsScreen.tsx
Normal file
36
screens/ProjectDetailsScreen.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React, { useState } from 'react';
|
||||
import { View, Text, Button, TextInput, StyleSheet } from 'react-native';
|
||||
import { doc, updateDoc } from 'firebase/firestore';
|
||||
import { db } from '../config/firebase';
|
||||
|
||||
function ProjectDetailsScreen({ route, navigation }: any) {
|
||||
const { project } = route.params;
|
||||
const [name, setName] = useState(project.name);
|
||||
const [status, setStatus] = useState(project.status);
|
||||
|
||||
const updateProject = async () => {
|
||||
await updateDoc(doc(db, 'projects', project.id), { name, status });
|
||||
alert('Projekt frissítve');
|
||||
navigation.goBack();
|
||||
};
|
||||
|
||||
const toggleStatus = () => {
|
||||
setStatus(status === 'aktív' ? 'lezárt' : 'aktív');
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<TextInput style={styles.input} value={name} onChangeText={setName} />
|
||||
<Text>Státusz: {status}</Text>
|
||||
<Button title="Státusz váltás" onPress={toggleStatus} />
|
||||
<Button title="Mentés" onPress={updateProject} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, padding: 16 },
|
||||
input: { borderWidth: 1, padding: 8, marginBottom: 16, borderRadius: 4 },
|
||||
});
|
||||
|
||||
export default ProjectDetailsScreen;
|
||||
64
screens/ProjectsScreen.tsx
Normal file
64
screens/ProjectsScreen.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { View, Text, FlatList, TouchableOpacity, Button, TextInput, StyleSheet } from 'react-native';
|
||||
import { collection, addDoc, query, where, getDocs, deleteDoc, doc } from 'firebase/firestore';
|
||||
import { db, auth } from '../config/firebase';
|
||||
|
||||
function ProjectsScreen({ navigation }: any) {
|
||||
const [projects, setProjects] = useState<any[]>([]);
|
||||
const [name, setName] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
loadProjects();
|
||||
}, []);
|
||||
|
||||
const loadProjects = async () => {
|
||||
const q = query(collection(db, 'projects'), where('userId', '==', auth.currentUser!.uid));
|
||||
const snapshot = await getDocs(q);
|
||||
setProjects(snapshot.docs.map(doc => ({ id: doc.id, ...doc.data() })));
|
||||
};
|
||||
|
||||
const addProject = async () => {
|
||||
await addDoc(collection(db, 'projects'), {
|
||||
name,
|
||||
userId: auth.currentUser!.uid,
|
||||
status: 'aktív',
|
||||
});
|
||||
setName('');
|
||||
loadProjects();
|
||||
};
|
||||
|
||||
const deleteProject = async (id: string) => {
|
||||
await deleteDoc(doc(db, 'projects', id));
|
||||
loadProjects();
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<TextInput style={styles.input} placeholder="Projekt név" value={name} onChangeText={setName} />
|
||||
<Button title="Hozzáadás" onPress={addProject} />
|
||||
<FlatList
|
||||
data={projects}
|
||||
keyExtractor={item => item.id}
|
||||
renderItem={({ item }) => (
|
||||
<TouchableOpacity
|
||||
style={styles.item}
|
||||
onPress={() => navigation.navigate('Details', { project: item })}
|
||||
>
|
||||
<Text>{item.name} - {item.status}</Text>
|
||||
<TouchableOpacity onPress={() => deleteProject(item.id)}>
|
||||
<Text>🗑️</Text>
|
||||
</TouchableOpacity>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, padding: 16 },
|
||||
input: { borderWidth: 1, padding: 8, marginBottom: 8, borderRadius: 4 },
|
||||
item: { padding: 16, borderBottomWidth: 1, flexDirection: 'row', justifyContent: 'space-between' },
|
||||
});
|
||||
|
||||
export default ProjectsScreen;
|
||||
Reference in New Issue
Block a user