Initial commit
This commit is contained in:
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files
|
||||
|
||||
# dependencies
|
||||
node_modules/
|
||||
|
||||
# Expo
|
||||
.expo/
|
||||
dist/
|
||||
web-build/
|
||||
expo-env.d.ts
|
||||
|
||||
# Native
|
||||
.kotlin/
|
||||
*.orig.*
|
||||
*.jks
|
||||
*.p8
|
||||
*.p12
|
||||
*.key
|
||||
*.mobileprovision
|
||||
|
||||
# Metro
|
||||
.metro-health-check*
|
||||
|
||||
# debug
|
||||
npm-debug.*
|
||||
yarn-debug.*
|
||||
yarn-error.*
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# local env files
|
||||
.env*.local
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
|
||||
# generated native folders
|
||||
/ios
|
||||
/android
|
||||
88
App.tsx
Normal file
88
App.tsx
Normal file
@@ -0,0 +1,88 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { View, Text, TextInput, Button, FlatList, TouchableOpacity, StyleSheet } from 'react-native';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
|
||||
interface Product {
|
||||
id: string;
|
||||
name: string;
|
||||
price: number;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [products, setProducts] = useState<Product[]>([]);
|
||||
const [name, setName] = useState('');
|
||||
const [price, setPrice] = useState('');
|
||||
const [editId, setEditId] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
loadProducts();
|
||||
}, []);
|
||||
|
||||
const loadProducts = async () => {
|
||||
const data = await AsyncStorage.getItem('products');
|
||||
if (data) setProducts(JSON.parse(data));
|
||||
};
|
||||
|
||||
const saveProducts = async (newProducts: Product[]) => {
|
||||
await AsyncStorage.setItem('products', JSON.stringify(newProducts));
|
||||
setProducts(newProducts);
|
||||
};
|
||||
|
||||
const addProduct = () => {
|
||||
const newProduct = { id: Date.now().toString(), name, price: parseFloat(price) };
|
||||
saveProducts([...products, newProduct]);
|
||||
setName('');
|
||||
setPrice('');
|
||||
};
|
||||
|
||||
const updateProduct = () => {
|
||||
const updated = products.map(p => p.id === editId ? { ...p, name, price: parseFloat(price) } : p);
|
||||
saveProducts(updated);
|
||||
setEditId(null);
|
||||
setName('');
|
||||
setPrice('');
|
||||
};
|
||||
|
||||
const deleteProduct = (id: string) => {
|
||||
saveProducts(products.filter(p => p.id !== id));
|
||||
};
|
||||
|
||||
const sortByPrice = () => {
|
||||
saveProducts([...products].sort((a, b) => a.price - b.price));
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<TextInput style={styles.input} placeholder="Név" value={name} onChangeText={setName} />
|
||||
<TextInput style={styles.input} placeholder="Ár" value={price} onChangeText={setPrice} keyboardType="numeric" />
|
||||
<Button title={editId ? 'Frissítés' : 'Hozzáadás'} onPress={editId ? updateProduct : addProduct} color="#ff00ff" />
|
||||
<Button title="Rendezés ár szerint" onPress={sortByPrice} color="#ff00ff" />
|
||||
<FlatList
|
||||
data={products}
|
||||
keyExtractor={item => item.id}
|
||||
renderItem={({ item }) => (
|
||||
<View style={styles.item}>
|
||||
<Text style={{ color: '#ffffff' }}>{item.name} - {item.price} Ft</Text>
|
||||
<View style={styles.buttons}>
|
||||
<TouchableOpacity onPress={() => { setEditId(item.id); setName(item.name); setPrice(item.price.toString()); }}>
|
||||
<Text style={styles.edit}>✏️</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={() => deleteProduct(item.id)}>
|
||||
<Text style={styles.delete}>🗑️</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
)}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: { flex: 1, padding: 16, backgroundColor: '#000000' },
|
||||
input: { borderWidth: 1, borderColor: '#333333', padding: 8, marginBottom: 8, borderRadius: 4, backgroundColor: '#1a1a1a', color: '#ffffff' },
|
||||
item: { padding: 16, borderBottomWidth: 1, borderBottomColor: '#333333', flexDirection: 'row', justifyContent: 'space-between' },
|
||||
buttons: { flexDirection: 'row', gap: 8 },
|
||||
edit: { fontSize: 18 },
|
||||
delete: { fontSize: 18 },
|
||||
});
|
||||
28
app.json
Normal file
28
app.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"expo": {
|
||||
"name": "feladat3-termekkezelo",
|
||||
"slug": "feladat3-termekkezelo",
|
||||
"version": "1.0.0",
|
||||
"orientation": "portrait",
|
||||
"icon": "./assets/icon.png",
|
||||
"userInterfaceStyle": "light",
|
||||
"newArchEnabled": true,
|
||||
"splash": {
|
||||
"image": "./assets/splash-icon.png",
|
||||
"resizeMode": "contain",
|
||||
"backgroundColor": "#ffffff"
|
||||
},
|
||||
"ios": {
|
||||
"supportsTablet": true
|
||||
},
|
||||
"android": {
|
||||
"adaptiveIcon": {
|
||||
"foregroundImage": "./assets/adaptive-icon.png",
|
||||
"backgroundColor": "#ffffff"
|
||||
}
|
||||
},
|
||||
"web": {
|
||||
"favicon": "./assets/favicon.png"
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
assets/adaptive-icon.png
Normal file
BIN
assets/adaptive-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
BIN
assets/favicon.png
Normal file
BIN
assets/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
assets/icon.png
Normal file
BIN
assets/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 22 KiB |
BIN
assets/splash-icon.png
Normal file
BIN
assets/splash-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 17 KiB |
8
index.ts
Normal file
8
index.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { registerRootComponent } from 'expo';
|
||||
|
||||
import App from './App';
|
||||
|
||||
// registerRootComponent calls AppRegistry.registerComponent('main', () => App);
|
||||
// It also ensures that whether you load the app in Expo Go or in a native build,
|
||||
// the environment is set up appropriately
|
||||
registerRootComponent(App);
|
||||
9659
package-lock.json
generated
Normal file
9659
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
package.json
Normal file
24
package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "feladat3-termekkezelo",
|
||||
"version": "1.0.0",
|
||||
"main": "index.ts",
|
||||
"scripts": {
|
||||
"start": "expo start",
|
||||
"android": "expo start --android",
|
||||
"ios": "expo start --ios",
|
||||
"web": "expo start --web"
|
||||
},
|
||||
"dependencies": {
|
||||
"@react-native-async-storage/async-storage": "^2.2.0",
|
||||
"expo": "~54.0.33",
|
||||
"expo-status-bar": "~3.0.9",
|
||||
"firebase": "^12.9.0",
|
||||
"react": "19.1.0",
|
||||
"react-native": "0.81.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "~19.1.0",
|
||||
"typescript": "~5.9.2"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
6
tsconfig.json
Normal file
6
tsconfig.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "expo/tsconfig.base",
|
||||
"compilerOptions": {
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user