-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.ts
42 lines (38 loc) · 1.01 KB
/
storage.ts
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
import { Storage } from "@plasmohq/storage";
export const storage = new Storage({
area: "local",
});
export const storage_key = "place-data";
export interface PlaceData {
id: String
name: String
addr: String
phone: String
}
export async function set_place(data: PlaceData) {
if (data === null) {
return
}
var place_ss = await storage.get(storage_key);
console.log("set place all data", place_ss);
var place = [].concat(place_ss);
place.push(data);
place = place.filter(Boolean);
place = place.filter((item, index, self) =>
index === self.findIndex((t) => (
t.name === item.name
))
);
place = place.filter(p => p.phone !== '');
await storage.set(storage_key, place);
}
export async function get_all_data(): Promise<Array<PlaceData>> {
var place_ss = await storage.get(storage_key);
if (place_ss) {
var place: Array<PlaceData> = [].concat(place_ss).filter(p => p !== null);
} else {
var place: Array<PlaceData> = [];
}
console.log("all data: ", place)
return place
}