-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
249 lines (219 loc) · 7.34 KB
/
App.js
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
import React, { Component } from "react";
import {
View,
Text,
TouchableOpacity,
StyleSheet,
TextInput,
SafeAreaView,
ScrollView,
Button,
Pressable,
FlatList,
} from "react-native";
import AsyncStorage, { useAsyncStorage } from "@react-native-async-storage/async-storage";
import datas from "./datas";
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import {useEffect, useState} from "react";
import { keys, values } from "@babel/runtime/helpers/regeneratorRuntime";
import db from './db.json';
import customData from "./db.json";
import App from "react-native/template/App";
import asyncStorage from "@react-native-async-storage/async-storage/src/AsyncStorage";
const Stack = createNativeStackNavigator();
function MyStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name={"StorageScreen"} component={StorageScreen} />
</Stack.Navigator>
);
}
function StorageScreen({ navigation }) {
const fonks = ({item}) => {
// let color = 'red';
// if (clicked.includes (item)) {
// color = 'blue';
// }
return (
<View style={{height:100,backgroundColor: '#6495ed'}}>
<View style={{width:450,height:100,}}>
<View style={{borderWidth:2,backgroundColor: '#f5f5f5',marginTop:25,marginLeft:10, marginRight:10, flexDirection: "row", alignItems: 'center'}}>
<TouchableOpacity style={{backgroundColor: 'orange', borderWidth:2, height:20, width:20,borderRadius:10, marginLeft:5}}>
</TouchableOpacity>
<Text style={{color: '#8b4513', fontWeight:'bold', fontSize:20, marginLeft:30}}>{item.text}</Text>
</View>
</View>
</View>
);}
const [wstorage,setWstorage] = useState([]);
const [dstorage,setDstorage] = useState([]);
const [activeIndex, setActiveIndex] = useState(0);
console.warn(wstorage);
return (
<View style={{ alignItems: 'center', justifyContent: 'center' }}>
<Button title="Geri Dön" onPress={() => navigation.goBack()} />
<View style={{flexDirection:'row'}}>
<Button title={'work'} onPress={() => {
setActiveIndex(0)
asyncStorage.getItem('key').then(ASRes => {
let list = [];
list = JSON.parse(ASRes);
setWstorage(list);
})}}></Button>
<Button title={'done'} onPress={() =>{
setActiveIndex(1);
asyncStorage.getItem('key2').then(ASRes => {
let list = [];
list = JSON.parse(ASRes);
setDstorage(list);
})}} ></Button>
</View>
<FlatList data={activeIndex == 0 ? wstorage : dstorage} renderItem={fonks}></FlatList>
</View>
);
}
function HomeScreen({navigation}){
const [activeIndex, setActiveIndex] = useState(0);
const [works,setWorks] = useState();
const [done,setDone] = useState();
const [wList,setWList] = useState([]);
const [dList,setDList] = useState([]);
const [clicked, setClicked] = useState([]);
const [dizi, setDizi] = useState([]);
const fonk = ({item}) => {
// let color = 'red';
// if (clicked.includes (item)) {
// color = 'blue';
// }
return (
<View style={{flex : 1}}>
<View style={{borderWidth:2,backgroundColor: '#f5f5f5',marginTop:25,marginLeft:10, marginRight:10, flexDirection: "row", alignItems: 'center'}}>
<TouchableOpacity style={{backgroundColor: 'orange', borderWidth:2, height:20, width:20,borderRadius:10, marginLeft:5}} onPress={() => {
// let tarray = [];
// tarray=tarray.concat(clicked);
//
// if ( !tarray.includes(item)){
// tarray.push(item);
// }
// setClicked(tarray);
// console.warn(clicked);
if (activeIndex == 0) {
let workArrayTemp = [];
let doneArrayTemp = [];
doneArrayTemp = doneArrayTemp.concat(dList);
doneArrayTemp.push(item);
setDList(doneArrayTemp);
if (dizi.length > 0) {
for (let it of dizi) {
if (!doneArrayTemp.includes(it)) {
console.warn("aaaaaaaaa")
workArrayTemp.push(it)
}
// workArrayTemp.push(it)
}
setWList(workArrayTemp);
}
}
if (activeIndex == 1) {
let wworkArrayTemp = [];
let ddoneArrayTemp = [];
ddoneArrayTemp=ddoneArrayTemp.concat(wList);
ddoneArrayTemp.push(item);
setWList(ddoneArrayTemp);
if (dizi.length > 0){
for (let it of dizi) {
if (!ddoneArrayTemp.includes(it)){
console.warn("bbb")
wworkArrayTemp.push(it)
}
// workArrayTemp.push(it)
}
setDList(wworkArrayTemp);
} }
}
}>
</TouchableOpacity>
<Text style={{color: '#8b4513', fontWeight:'bold', fontSize:20, marginLeft:30}}>{item.text}</Text>
</View>
</View>
);}
useEffect(() => {
setWList(db?.data?.doList);
setDizi(db?.data?.doList);
}, []);
if (dizi.length <= 0) {
return (
<View></View>
)
}
// console.warn(dizi.data.doList);
return (
<View style={{flex: 1, backgroundColor: '#b0c4de'}}>
<View
style={{
backgroundColor: '#008b8b',
alignItems: 'center',
width: '100%',
height: 40,
}}>
<Text
style={{
color: '#ffefd5',
marginTop: 10,
fontSize: 15,
fontWeight: 'bold',
}}>
TO-DO LİST
</Text>
</View>
<View style={{alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Depolama"
onPress={() => navigation.navigate('Profile')} />
</View>
<View style={{flexDirection: 'row', width:'100%', alignItems: 'center', justifyContent: 'center' }}>
<Button
title={'Works'}
onPress={() => {
setWorks(works);
setActiveIndex(0)
console.warn('works ekranındasınız');
}}></Button>
<Button
title={'Done'}
onPress={() => {
setDone(setDone, done);
setActiveIndex(1);
console.warn('Done ekranındasınız');
}}></Button>
</View>
<View style={{flex: 1 }}>
<FlatList
style={{}}
data={activeIndex == 0 ? wList : dList }
renderItem={fonk} />
</View>
<TouchableOpacity onPress={() => {
if (activeIndex == 0) {
asyncStorage.setItem('key', JSON.stringify(wList));
}else {
asyncStorage.setItem('key2', JSON.stringify(dList));
}
// console.warn(wList);
}}>
<View style={{ alignItems:'center', justifyContent:'center' ,marginBottom:10 }}>
<Text style={{color:'orange',borderRadius:20,backgroundColor:'black',fontWeight: 'bold', fontSize: 22, padding:12}}>STORAGE</Text>
</View>
</TouchableOpacity>
</View>
);
}
export default function Mystack() {
return (
<NavigationContainer>
<MyStack />
</NavigationContainer>
);
}