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

Commit

Permalink
app works fine.
Browse files Browse the repository at this point in the history
  • Loading branch information
marwan38 committed Mar 1, 2020
1 parent e3126f3 commit fb5f900
Show file tree
Hide file tree
Showing 16 changed files with 1,698 additions and 318 deletions.
188 changes: 1 addition & 187 deletions README.md

Large diffs are not rendered by default.

30 changes: 6 additions & 24 deletions app/app.global.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,14 @@ body {
);
font-family: Arial, Helvetica, Helvetica Neue, serif;
overflow-y: hidden;
}

h2 {
margin: 0;
font-size: 2.25rem;
font-weight: bold;
letter-spacing: -0.025em;
color: #fff;
}

p {
font-size: 24px;
}

li {
list-style: none;
}

a {
color: white;
opacity: 0.75;
text-decoration: none;
}
#root {
height: 100vh;
padding: 15px;
overflow: hidden;
display: flex;
flex-direction: column;

a:hover {
opacity: 1;
text-decoration: none;
cursor: pointer;
}
26 changes: 23 additions & 3 deletions app/components/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { ipcRenderer, remote } from 'electron';
import { Tabs, Tab, Card, InputGroup } from '@blueprintjs/core';

Expand All @@ -8,6 +8,7 @@ import FileUploader from './FileUploader';
import Progress from './Progress';
import Merge from './XLSX/Merge';
import Compare from './XLSX/Compare';
import Find from './XLSX/Find';
import Toaster from './Toaster';

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

// Auto set output path based on the files input
useEffect(() => {
if (files?.length > 0) {
const { path, name } = files[0];
setOutputPath(path.replace(`\\${name}`, ''));
}
}, [files]);

const filesAvailable = files && files.length > 0;
return (
<div>
<>
<FileUploader onUpload={setFiles} style={{ marginBottom: 20 }} />
<InputGroup
placeholder="Output path"
Expand Down Expand Up @@ -69,11 +78,22 @@ export default function Home() {
disabled={!files || files.length !== 1}
panel={<Compare files={files} output={outputFullPath} />}
/>
<Tab
id="find-word"
title="Find word"
disabled={!files || files.length !== 1}
panel={<Find files={files} output={outputFullPath} />}
/>
</Tabs>
</Card>

<Progress style={{ marginTop: 20 }} />
<Toaster />
</div>

<div style={{ marginTop: 'auto' }}>
<b>App version: </b>
{remote.app.getVersion()}
</div>
</>
);
}
8 changes: 3 additions & 5 deletions app/components/Toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ function Toast() {
const ref = useRef();

useEffect(() => {
ipcRenderer.on(Events.Message, (_, { type, message }) => {
ipcRenderer.on(Events.Message, (_, { intent, message }) => {
const { current: toast } = ref;
if (type === 'log' || type === 'error') {
const intent = type === 'log' ? Intent.PRIMARY : Intent.DANGER;
toast.show({ message, intent });
}
console.log(message, intent)
toast.show({ message, intent });
});
}, []);

Expand Down
27 changes: 25 additions & 2 deletions app/components/XLSX/Compare.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { ipcRenderer } from 'electron';
import { Button, InputGroup } from '@blueprintjs/core';
import { Button, InputGroup, Checkbox } from '@blueprintjs/core';

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

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

return (
<>
Expand All @@ -28,6 +30,24 @@ function Compare({ files, output }: Props) {
value={columnB}
onChange={e => setColumnB(e.target.value)}
/>
<Checkbox
checked={checked}
inline
onChange={() => setChecked(c => !c)}
style={{ marginTop: 10, display: 'flex', alignItems: 'center' }}
>
<div className="bp3-ui-text" style={{ color: 'black' }}>
Find word in the compared columns?
</div>
</Checkbox>
{checked && (
<InputGroup
placeholder="Column letter"
small
value={wordToFind}
onChange={e => setWordToFind(e.target.value)}
/>
)}
</div>
<Button
disabled={!files || !output || files.length > 1}
Expand All @@ -36,7 +56,10 @@ function Compare({ files, output }: Props) {
ipcRenderer.send(Events.Compare, {
file: files.length > 0 && files[0],
output,
values: [columnA, columnB]
compare: {
find: wordToFind,
columns: [columnA, columnB]
}
});
}}
/>
Expand Down
48 changes: 48 additions & 0 deletions app/components/XLSX/Find.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useState } from 'react';
import { ipcRenderer } from 'electron';
import { Button, InputGroup } from '@blueprintjs/core';

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

type Props = {
files: any[];
output: string;
};

function Find({ files, output }: Props) {
const [columns, setColumns] = useState('');
const [wordToFind, setWordToFind] = useState('');

return (
<>
<div style={{ marginBottom: 10 }}>
<InputGroup
placeholder="Column numbers seperated by a comma. Ex: j,r,c,d"
small
value={columns}
onChange={e => setColumns(e.target.value)}
/>
<InputGroup
placeholder="Column letter of word to find"
small
value={wordToFind}
onChange={e => setWordToFind(e.target.value)}
/>
</div>
<Button
disabled={!files || !output || files.length > 1}
text="Start"
onClick={() => {
ipcRenderer.send(Events.Find, {
files: files.length > 0 && files[0],
output,
columns: columns.split(','),
word: wordToFind
});
}}
/>
</>
);
}

export default Find;
1 change: 1 addition & 0 deletions app/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
export const Events = {
Merge: 'execute:merge',
Compare: 'execute:compare',
Find: 'execute:find',
GetPath: 'get-path',
Message: 'deliver-message',
Progress: 'progress-log',
Expand Down
35 changes: 28 additions & 7 deletions app/main.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* `./app/main.prod.js` using webpack. This gives us some performance wins.
*/
import path from 'path';
import { app, BrowserWindow, ipcMain } from 'electron';
import { app, BrowserWindow, ipcMain, dialog } from 'electron';
import { autoUpdater } from 'electron-updater';
import log from 'electron-log';
import { Intent } from '@blueprintjs/core';
import MenuBuilder from './menu';
import { Events } from './events';
import { bus, init } from './message-bus';
Expand Down Expand Up @@ -101,6 +102,11 @@ const createWindow = async () => {
// Remove this if your app does not use auto updates
// eslint-disable-next-line
new AppUpdater();

const x = await autoUpdater.checkForUpdatesAndNotify();
console.log('UPDATE ----------------------');
console.log(x);
console.log('=========================');
};

/**
Expand Down Expand Up @@ -128,14 +134,17 @@ app.on('activate', () => {
*/

ipcMain.on(Events.Compare, async (event, args) => {
const { file, values, output } = args;
const { file, compare, output } = args;
try {
bus.message('Starting compare process');
const result = await xlsxFunctions.doCompare(values, file);
const result = await xlsxFunctions.doCompare(compare, file);
await result.xlsx.writeFile(output);
bus.message('Compare process done and file has been output');
bus.message(
'Compare process done and file has been output',
Intent.SUCCESS
);
} catch (e) {
bus.message(e.message || e, 'error');
bus.message(e.message || e, Intent.ERROR);
}
});

Expand All @@ -145,9 +154,21 @@ ipcMain.on(Events.Merge, async (event, args) => {
bus.message('Starting merge process');
const result = await xlsxFunctions.doMerge(files);
await result.xlsx.writeFile(output);
bus.message('Merge process done and file has been output');
bus.message('Merge process done and file has been output', Intent.SUCCESS);
} catch (e) {
bus.message(e.message || e, Intent.ERROR);
}
});

ipcMain.on(Events.Find, async (event, args) => {
const { files, output, columns, word } = args;
try {
bus.message('Starting find process');
const result = await xlsxFunctions.doFind({ columns, word }, files);
await result.xlsx.writeFile(output);
bus.message('Find process complete', Intent.SUCCESS);
} catch (e) {
bus.message(e.message || e, 'error');
bus.message(e.message || e, Intent.ERROR);
}
});

Expand Down
5 changes: 3 additions & 2 deletions app/message-bus.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* eslint-disable prefer-const */
import { Intent } from '@blueprintjs/core';
import { Events } from './events';

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

export function init(mainWindow) {
bus.message = (message, type = 'log') =>
mainWindow.webContents.send(Events.Message, { type, message });
bus.message = (message, intent: Intent = Intent.PRIMARY) =>
mainWindow.webContents.send(Events.Message, { intent, message });
bus.progress = (message, pct) =>
mainWindow.webContents.send(Events.Progress, { message, pct });
}
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "johns-xlsx-helper",
"productName": "johns-xlsx-helper",
"version": "0.1.3",
"version": "0.2.3",
"description": "Utility built for John to help with XLSX stuff.",
"main": "./main.prod.js",
"author": {
Expand Down
Loading

0 comments on commit fb5f900

Please sign in to comment.