Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit fb5f900

Browse files
committed
app works fine.
1 parent e3126f3 commit fb5f900

File tree

16 files changed

+1698
-318
lines changed

16 files changed

+1698
-318
lines changed

README.md

Lines changed: 1 addition & 187 deletions
Large diffs are not rendered by default.

app/app.global.css

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,14 @@ body {
1616
);
1717
font-family: Arial, Helvetica, Helvetica Neue, serif;
1818
overflow-y: hidden;
19-
}
20-
21-
h2 {
2219
margin: 0;
23-
font-size: 2.25rem;
24-
font-weight: bold;
25-
letter-spacing: -0.025em;
26-
color: #fff;
2720
}
2821

29-
p {
30-
font-size: 24px;
31-
}
32-
33-
li {
34-
list-style: none;
35-
}
36-
37-
a {
38-
color: white;
39-
opacity: 0.75;
40-
text-decoration: none;
41-
}
22+
#root {
23+
height: 100vh;
24+
padding: 15px;
25+
overflow: hidden;
26+
display: flex;
27+
flex-direction: column;
4228

43-
a:hover {
44-
opacity: 1;
45-
text-decoration: none;
46-
cursor: pointer;
4729
}

app/components/Home.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import { ipcRenderer, remote } from 'electron';
33
import { Tabs, Tab, Card, InputGroup } from '@blueprintjs/core';
44

@@ -8,6 +8,7 @@ import FileUploader from './FileUploader';
88
import Progress from './Progress';
99
import Merge from './XLSX/Merge';
1010
import Compare from './XLSX/Compare';
11+
import Find from './XLSX/Find';
1112
import Toaster from './Toaster';
1213

1314
// import { Link } from 'react-router-dom';
@@ -24,9 +25,17 @@ export default function Home() {
2425
const [outputName, setOutputName] = useState('output');
2526
const outputFullPath = `${outputPath}\\${outputName}.xlsx`;
2627

28+
// Auto set output path based on the files input
29+
useEffect(() => {
30+
if (files?.length > 0) {
31+
const { path, name } = files[0];
32+
setOutputPath(path.replace(`\\${name}`, ''));
33+
}
34+
}, [files]);
35+
2736
const filesAvailable = files && files.length > 0;
2837
return (
29-
<div>
38+
<>
3039
<FileUploader onUpload={setFiles} style={{ marginBottom: 20 }} />
3140
<InputGroup
3241
placeholder="Output path"
@@ -69,11 +78,22 @@ export default function Home() {
6978
disabled={!files || files.length !== 1}
7079
panel={<Compare files={files} output={outputFullPath} />}
7180
/>
81+
<Tab
82+
id="find-word"
83+
title="Find word"
84+
disabled={!files || files.length !== 1}
85+
panel={<Find files={files} output={outputFullPath} />}
86+
/>
7287
</Tabs>
7388
</Card>
7489

7590
<Progress style={{ marginTop: 20 }} />
7691
<Toaster />
77-
</div>
92+
93+
<div style={{ marginTop: 'auto' }}>
94+
<b>App version: </b>
95+
{remote.app.getVersion()}
96+
</div>
97+
</>
7898
);
7999
}

app/components/Toaster.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ function Toast() {
88
const ref = useRef();
99

1010
useEffect(() => {
11-
ipcRenderer.on(Events.Message, (_, { type, message }) => {
11+
ipcRenderer.on(Events.Message, (_, { intent, message }) => {
1212
const { current: toast } = ref;
13-
if (type === 'log' || type === 'error') {
14-
const intent = type === 'log' ? Intent.PRIMARY : Intent.DANGER;
15-
toast.show({ message, intent });
16-
}
13+
console.log(message, intent)
14+
toast.show({ message, intent });
1715
});
1816
}, []);
1917

app/components/XLSX/Compare.tsx

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import { ipcRenderer } from 'electron';
3-
import { Button, InputGroup } from '@blueprintjs/core';
3+
import { Button, InputGroup, Checkbox } from '@blueprintjs/core';
44

55
import { Events } from '../../events';
66

@@ -12,6 +12,8 @@ type Props = {
1212
function Compare({ files, output }: Props) {
1313
const [columnA, setColumnA] = useState('');
1414
const [columnB, setColumnB] = useState('');
15+
const [checked, setChecked] = useState(false);
16+
const [wordToFind, setWordToFind] = useState('');
1517

1618
return (
1719
<>
@@ -28,6 +30,24 @@ function Compare({ files, output }: Props) {
2830
value={columnB}
2931
onChange={e => setColumnB(e.target.value)}
3032
/>
33+
<Checkbox
34+
checked={checked}
35+
inline
36+
onChange={() => setChecked(c => !c)}
37+
style={{ marginTop: 10, display: 'flex', alignItems: 'center' }}
38+
>
39+
<div className="bp3-ui-text" style={{ color: 'black' }}>
40+
Find word in the compared columns?
41+
</div>
42+
</Checkbox>
43+
{checked && (
44+
<InputGroup
45+
placeholder="Column letter"
46+
small
47+
value={wordToFind}
48+
onChange={e => setWordToFind(e.target.value)}
49+
/>
50+
)}
3151
</div>
3252
<Button
3353
disabled={!files || !output || files.length > 1}
@@ -36,7 +56,10 @@ function Compare({ files, output }: Props) {
3656
ipcRenderer.send(Events.Compare, {
3757
file: files.length > 0 && files[0],
3858
output,
39-
values: [columnA, columnB]
59+
compare: {
60+
find: wordToFind,
61+
columns: [columnA, columnB]
62+
}
4063
});
4164
}}
4265
/>

app/components/XLSX/Find.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React, { useState } from 'react';
2+
import { ipcRenderer } from 'electron';
3+
import { Button, InputGroup } from '@blueprintjs/core';
4+
5+
import { Events } from '../../events';
6+
7+
type Props = {
8+
files: any[];
9+
output: string;
10+
};
11+
12+
function Find({ files, output }: Props) {
13+
const [columns, setColumns] = useState('');
14+
const [wordToFind, setWordToFind] = useState('');
15+
16+
return (
17+
<>
18+
<div style={{ marginBottom: 10 }}>
19+
<InputGroup
20+
placeholder="Column numbers seperated by a comma. Ex: j,r,c,d"
21+
small
22+
value={columns}
23+
onChange={e => setColumns(e.target.value)}
24+
/>
25+
<InputGroup
26+
placeholder="Column letter of word to find"
27+
small
28+
value={wordToFind}
29+
onChange={e => setWordToFind(e.target.value)}
30+
/>
31+
</div>
32+
<Button
33+
disabled={!files || !output || files.length > 1}
34+
text="Start"
35+
onClick={() => {
36+
ipcRenderer.send(Events.Find, {
37+
files: files.length > 0 && files[0],
38+
output,
39+
columns: columns.split(','),
40+
word: wordToFind
41+
});
42+
}}
43+
/>
44+
</>
45+
);
46+
}
47+
48+
export default Find;

app/events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export const Events = {
33
Merge: 'execute:merge',
44
Compare: 'execute:compare',
5+
Find: 'execute:find',
56
GetPath: 'get-path',
67
Message: 'deliver-message',
78
Progress: 'progress-log',

app/main.dev.ts

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
* `./app/main.prod.js` using webpack. This gives us some performance wins.
1010
*/
1111
import path from 'path';
12-
import { app, BrowserWindow, ipcMain } from 'electron';
12+
import { app, BrowserWindow, ipcMain, dialog } from 'electron';
1313
import { autoUpdater } from 'electron-updater';
1414
import log from 'electron-log';
15+
import { Intent } from '@blueprintjs/core';
1516
import MenuBuilder from './menu';
1617
import { Events } from './events';
1718
import { bus, init } from './message-bus';
@@ -101,6 +102,11 @@ const createWindow = async () => {
101102
// Remove this if your app does not use auto updates
102103
// eslint-disable-next-line
103104
new AppUpdater();
105+
106+
const x = await autoUpdater.checkForUpdatesAndNotify();
107+
console.log('UPDATE ----------------------');
108+
console.log(x);
109+
console.log('=========================');
104110
};
105111

106112
/**
@@ -128,14 +134,17 @@ app.on('activate', () => {
128134
*/
129135

130136
ipcMain.on(Events.Compare, async (event, args) => {
131-
const { file, values, output } = args;
137+
const { file, compare, output } = args;
132138
try {
133139
bus.message('Starting compare process');
134-
const result = await xlsxFunctions.doCompare(values, file);
140+
const result = await xlsxFunctions.doCompare(compare, file);
135141
await result.xlsx.writeFile(output);
136-
bus.message('Compare process done and file has been output');
142+
bus.message(
143+
'Compare process done and file has been output',
144+
Intent.SUCCESS
145+
);
137146
} catch (e) {
138-
bus.message(e.message || e, 'error');
147+
bus.message(e.message || e, Intent.ERROR);
139148
}
140149
});
141150

@@ -145,9 +154,21 @@ ipcMain.on(Events.Merge, async (event, args) => {
145154
bus.message('Starting merge process');
146155
const result = await xlsxFunctions.doMerge(files);
147156
await result.xlsx.writeFile(output);
148-
bus.message('Merge process done and file has been output');
157+
bus.message('Merge process done and file has been output', Intent.SUCCESS);
158+
} catch (e) {
159+
bus.message(e.message || e, Intent.ERROR);
160+
}
161+
});
162+
163+
ipcMain.on(Events.Find, async (event, args) => {
164+
const { files, output, columns, word } = args;
165+
try {
166+
bus.message('Starting find process');
167+
const result = await xlsxFunctions.doFind({ columns, word }, files);
168+
await result.xlsx.writeFile(output);
169+
bus.message('Find process complete', Intent.SUCCESS);
149170
} catch (e) {
150-
bus.message(e.message || e, 'error');
171+
bus.message(e.message || e, Intent.ERROR);
151172
}
152173
});
153174

app/message-bus.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable prefer-const */
2+
import { Intent } from '@blueprintjs/core';
23
import { Events } from './events';
34

45
// eslint-disable-next-line import/no-mutable-exports
56
export let bus = {};
67

78
export function init(mainWindow) {
8-
bus.message = (message, type = 'log') =>
9-
mainWindow.webContents.send(Events.Message, { type, message });
9+
bus.message = (message, intent: Intent = Intent.PRIMARY) =>
10+
mainWindow.webContents.send(Events.Message, { intent, message });
1011
bus.progress = (message, pct) =>
1112
mainWindow.webContents.send(Events.Progress, { message, pct });
1213
}

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "johns-xlsx-helper",
33
"productName": "johns-xlsx-helper",
4-
"version": "0.1.3",
4+
"version": "0.2.3",
55
"description": "Utility built for John to help with XLSX stuff.",
66
"main": "./main.prod.js",
77
"author": {

0 commit comments

Comments
 (0)