-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivationData.js
More file actions
58 lines (43 loc) · 1.39 KB
/
Copy pathActivationData.js
File metadata and controls
58 lines (43 loc) · 1.39 KB
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
'use strict';
import Papa from 'papaparse'
// use Papaparse to parse the activated_parks.csv file from pota.app user's
// stats page... it can also do the same for the hunter_parks.csv file if they
// upload that.
export default async function handleActxUpload(file) {
const r = new FileReader();
r.onload = async (e) => {
try {
const parsedResult = Papa.parse(e.target.result, {
header: true,
skipEmptyLines: true,
dynamicTyping: true
});
if (parsedResult.errors.length > 0) {
console.error('Errors parsing CSV:', parsedResult.errors);
throw new Error('Error parsing CSV data.');
}
let parsed = parsedResult.data;
let activated = []
parsed.forEach(ad => {
const r = ad['Reference'];
activated.push(r);
});
setActxData(JSON.stringify(activated));
}
catch {
setActxData("[]");
}
};
r.readAsText(file);
}
function getActxData() {
if (localStorage.getItem('locActxData') !== undefined) {
const data = localStorage.getItem('locActxData');
return JSON.parse(data);
}
return null;
}
async function setActxData(arr) {
localStorage.setItem('locActxData', arr);
}
export { handleActxUpload, getActxData };