-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIs.js
70 lines (60 loc) · 1.48 KB
/
APIs.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
import AsyncStorage from '@react-native-async-storage/async-storage';
export const settingsType = {
name: 'Status Saver',
setThemeLight : { theme: 'LIGHT' },
setThemeDark : { theme : 'DARK' },
emojiId : "emojiId",
validFilePath: "validFilePath",
autoSave: 'autoSave',
themeModeCustom: 'themeModeCustom'
}
export const initialSettings = {
name:'Status Saver',
theme: 'LIGHT',
emojiId: 0,
autoSave: true,
themeModeCustom: true
}
export const getObjectSettings = async () => {
try {
const jsonValue = await AsyncStorage.getItem(settingsType.name)
return jsonValue != null ? JSON.parse(jsonValue) : null
} catch(e) {
// read error
}
}
export const setObjectSettings = async (value) => {
try {
const jsonValue = JSON.stringify(value)
await AsyncStorage.setItem(settingsType.name, jsonValue)
} catch(e) {
// save error
}
finally {
}
}
export const mergeToObjectSettings = async (obj) => {
try {
await AsyncStorage.mergeItem(settingsType.name, JSON.stringify(obj))
const settings = await AsyncStorage.getItem(settingsType.name)
console.log(settings)
} catch(e) {
} finally {
}
}
export const clearObjectSettings = async () => {
try {
await AsyncStorage.clear()
} catch(e) {
// clear error
}
}
export const getAllObjectKeys = async () => {
let keys = []
try {
keys = await AsyncStorage.getAllKeys()
} catch(e) {
// read key error
}
console.log(keys)
}