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
|
import * as React from 'react';
import { View, StyleSheet, Text, FlatList, TouchableOpacity, Alert, TextInput } from 'react-native';
import * as SecureStore from 'expo-secure-store';
import { getFont } from "./Options"
export default class NotesList extends React.Component {
constructor(props) {
super(props)
this.state = {
notes: [],
search: '',
font: 0,
sortOrder: true,
}
this.setNotes = this.setNotes.bind(this)
this.setSearch = this.setSearch.bind(this)
this.setFont = this.setFont.bind(this)
this.setSortOrder = this.setSortOrder.bind(this)
this.funkcja = () => null;
}
setNotes(s) { this.setState({ notes: s }) }
setSearch(s) { this.setState({ search: s }) }
setFont(s) { this.setState({ font: s }) }
setSortOrder(s) { this.setState({ sortOrder: s }) }
componentDidMount() {
getNotes(this.setNotes); getFont(this.setFont);
this.props.navigation.addListener('focus', () => { getNotes(this.setNotes); getFont(this.setFont); })
}
componentWillUnmount() {
this.funkcja();
}
render() {
const filterNotes = (n) => {
return n.title.includes(this.state.search) ||
n.body.includes(this.state.search) ||
n.category.includes(this.state.search)
}
const sortNotes = (a, b) => {
return this.state.sortOrder ? a.date - b.date : b.date - a.date;
}
return (
<View style={styles.cont} >
<View>
<TextInput
placeholder="SEARCH IN NOTES..."
placeholderTextColor="#FFFFFF"
onChangeText={this.setSearch}
style={styles.input}
defaultValue={this.state.search}
// ref={ti}
/>
</View>
<TouchableOpacity style={styles.btn} onPress={() => this.setSortOrder(!this.state.sortOrder)}><Text style={[styles.txt, { textAlign: "center" }]}>Change sort order</Text></TouchableOpacity>
<View>
<FlatList
data={this.state.notes.filter(filterNotes).sort(sortNotes)}
renderItem={item => {
const note = item.item
let date = new Date(note.date)
const ms = ["Sty", "Lut", "Mar", "Kwi", "Maj", "Cze", "Lip", "Sie", "Wrz", "Paz", "Lis", "Gru"]
date = `${date.toISOString().substr(8, 2)} ${ms[date.getMonth()]}`
return (
<TouchableOpacity onLongPress={() =>
Alert.alert("Delete?", "There's no way back", [
{
text: "Cancel",
style: "cancel"
},
{
text: "OK",
onPress: () => deleteItem(note, this.setNotes)
}
])
}
onPress={() => this.props.navigation.navigate("editNote", { note })
}
>
<View key={item.index} style={[styles.note, { backgroundColor: note.color }]}>
<View><Text style={[styles.category, { color: note.color, fontSize: this.state.font }]}>{note.category}</Text></View>
<View><Text style={[styles.date, { fontSize: this.state.font }]}>{date}</Text></View>
<View style={{ flex: 1 }}><Text style={[styles.title, { fontSize: this.state.font }]}>{note.title}</Text></View>
<View style={{ flex: 1 }}><Text style={[styles.body, { flexWrap: "wrap", fontSize: this.state.font }]}>{note.body}</Text></View>
</View>
</TouchableOpacity>
)
}}
keyExtractor={(_, i) => i.toString()}
contentContainerStyle={styles.list}
style={styles.list}
numColumns={2}
/>
</View>
</View>
)
}
}
async function deleteItem(note, setNotes) {
let keyList = JSON.parse(await SecureStore.getItemAsync('notesKeys'))
await SecureStore.deleteItemAsync(note.key.toString())
keyList = keyList.filter(n => n !== note.key)
await SecureStore.setItemAsync('notesKeys', JSON.stringify(keyList))
getNotes(setNotes)
}
async function getNotes(setNotes) {
let notesKeys = await SecureStore.getItemAsync('notesKeys')
if (!notesKeys) notesKeys = []; else notesKeys = JSON.parse(notesKeys);
const notes = [];
for (const key of notesKeys) {
notes.push(JSON.parse(await SecureStore.getItemAsync(key.toString())))
}
setNotes(notes);
}
const styles = StyleSheet.create({
cont: {
flex: 1,
flexDirection: "column",
backgroundColor: "black",
},
note: {
width: 160,
height: 160,
backgroundColor: "red",
borderRadius: 10,
padding: 10,
marginTop: 30,
marginLeft: 30,
},
list: {
// height: 680,
},
btn: {
// borderColor: "red",
borderWidth: 3,
textAlign: "center",
flex: 0,
},
ico: {
width: 200,
height: 200,
},
input: {
fontSize: 25,
alignSelf: "center",
textAlign: "center",
width: "80%",
backgroundColor: "darkgrey",
borderRadius: 8,
margin: 10,
height: 60,
},
category: {
backgroundColor: "black",
// width: "fit-content",
margin: 10,
padding: 5,
borderRadius: 8,
alignSelf: "flex-start",
},
date: {
fontSize: 18,
color: "#FFFFFF",
textAlign: "right",
},
title: {
fontSize: 25,
fontWeight: "bold",
color: "#FFFFFF"
},
body: {
fontSize: 25,
color: "#FFFFFF"
},
txt: {
fontSize: 25,
fontWeight: "bold",
color: "#FFFFFF"
},
})
|