-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
109 lines (101 loc) · 2.66 KB
/
index.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
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
import React, { Component } from "react";
import vCard from "vcard-json";
import jsonexport from "jsonexport";
import fs from "fs";
import {
render,
Window,
Spinbox,
App,
Dialog,
Button,
ProgressBar,
Menu,
Grid,
Group,
Form,
TextInput,
Box,
Text,
StyledText,
Area
} from "proton-native";
class CSVApp extends Component {
state = { loading: false };
// save() {
// const filename = Dialog("Save");
// if (filename) {
// fs.writeFileSync(filename, this.state.text);
// }
// }
open() {
var data;
const filename = Dialog("Open");
console.log(filename);
if (filename) {
/* Use readFile() if the file is on disk. */
vCard.parseVcardFile(filename, function(err, json) {
jsonexport(json, function(err, csv) {
if (err) return console.log(err);
// write to a new file named 2pac.txt
fs.writeFile(`${filename}.csv`, csv, err => {
// throws an error, you could also catch it here
if (err) throw err;
data = csv;
// success case, the file was saved
Dialog("Message", {
title: "Success",
description: "Your file has been converted!"
});
require("child_process").exec(`start "" "${filename}.csv"`);
});
});
});
this.setState({ text: data });
}
}
shouldComponentUpdate(nextProps, nextState) {
if (typeof nextState.text === "string") return false;
// nextState is set from input
else return true; // nextState is set from file
}
render() {
return (
<App onShouldQuit={() => console.log("Quitting")}>
<Menu label="File">
<Menu.Item type="Item" onClick={() => this.open()}>
Open
</Menu.Item>
<Menu.Item type="Quit" />
</Menu>
<Window
onClose={() => console.log("Closing")}
title="VCF to CSV Converter"
size={{ w: 500, h: 500 }}
margined
>
<Group>
<Box>
<Area stroke="red" strokeWidth="10">
<Area.Text style={{ fontSize: 20 }}>
Welcome to VCF to Excel{" "}
<Area.Text
style={{
color: "red",
fontSize: 10,
fontWeight: "bold"
}}
>
FREE!
</Area.Text>
</Area.Text>
</Area>
<Button onClick={() => this.open()}>Select VCF File</Button>
</Box>
</Group>
</Window>
</App>
);
}
}
render(<CSVApp />);