-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
114 lines (104 loc) · 3.39 KB
/
App.tsx
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* Generated with the TypeScript template
* https://github.com/react-native-community/react-native-template-typescript
*
* @format
*/
import DatabaseProvider from "@nozbe/watermelondb/DatabaseProvider";
import React, {useMemo} from "react";
import {
Pressable,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
useColorScheme,
View,
} from "react-native";
import {Colors, Header} from "react-native/Libraries/NewAppScreen";
import {createDatabase} from "./src/watermelondb/database/database";
import {syncDB} from "./src/watermelondb/sync/syncDB";
import {createWorkingDayWDB} from "./src/watermelondb/service/workingDayWDBService";
import {createVisit} from "./src/watermelondb/service/visitService";
import {Database} from "@nozbe/watermelondb";
const clearDatabase = (database: Database) => () => {
database.write(() => database.unsafeResetDatabase());
};
const createRecords = (database: Database) => async () => {
const workingDay = await createWorkingDayWDB(database);
await createVisit(database, workingDay);
console.log("Records created !")
};
const App = () => {
const database = useMemo(() => createDatabase(), []);
const isDarkMode = useColorScheme() === "dark";
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
return (
<DatabaseProvider database={database}>
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? "light-content" : "dark-content"} />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<Text>
Here is how to reproduce the following issue
(https://github.com/Nozbe/WatermelonDB/issues/1126):
</Text>
<Text>Press on "Create records" button</Text>
<Text>Press on "Synchronize" button</Text>
<Text>
Press a second time on "Synchronize" button --> bug occurs -->
activity or visit record previously created is pushed again for
creation. Excepted behaviour: The second press on "Synchronize"
should push nothing.
</Text>
<Pressable onPress={createRecords(database)} style={styles.button}>
<Text style={styles.text}>Create records</Text>
</Pressable>
<Pressable
style={styles.button}
onPress={() => {
syncDB(database);
}}>
<Text style={styles.text}>Synchronize</Text>
</Pressable>
<Pressable onPress={clearDatabase(database)} style={styles.button}>
<Text style={styles.text}>Clear Database</Text>
</Pressable>
</View>
</ScrollView>
</SafeAreaView>
</DatabaseProvider>
);
};
const styles = StyleSheet.create({
button: {
alignItems: "center",
justifyContent: "center",
paddingVertical: 12,
paddingHorizontal: 32,
margin: 10,
borderRadius: 4,
elevation: 3,
backgroundColor: "#2588FF",
},
text: {
fontSize: 16,
lineHeight: 21,
fontWeight: "bold",
letterSpacing: 0.25,
color: "white",
},
});
export default App;