Skip to content

Commit 7e6a22f

Browse files
committed
Push to auto everytime hotkey trigger
1 parent 79d1ccb commit 7e6a22f

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

src/components/Main.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { useEffect, useState } from 'react';
2-
import { NavLink, Route } from 'react-router-dom';
2+
import { NavLink, Route, useHistory } from 'react-router-dom';
33
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
44
import { Helmet } from 'react-helmet';
55

6+
import { ipcRenderer } from 'electron';
67
import MarkdownToHtml from './markdown/MarkdownToHtml';
78
import UnixTimestamp from './timestamp/UnixTimestamp';
89
import HtmlPreview from './html/HtmlPreview';
@@ -87,11 +88,16 @@ const defaultRoutes = [
8788
const Main = () => {
8889
const [routes, setRoutes] = useState(defaultRoutes);
8990
const [search, setSearch] = useState('');
91+
const history = useHistory();
9092

9193
const handleSearch = (e: { target: { value: string } }) => {
9294
setSearch(e.target.value);
9395
};
9496

97+
ipcRenderer.on('hot-key-called', () => {
98+
history.push('/auto');
99+
});
100+
95101
useEffect(() => {
96102
if (search.trim()) {
97103
setRoutes(

src/components/auto/Auto.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { clipboard, ipcRenderer } from 'electron';
22
import path from 'path';
33
import React, { useEffect, useState } from 'react';
4-
import { useHistory } from 'react-router-dom';
4+
import { useHistory, useLocation } from 'react-router-dom';
55

66
const detectRouteData = (value: string) => {
77
const intVal = parseInt(value, 10);
@@ -26,14 +26,11 @@ const Auto = () => {
2626
const [value, setValue] = useState('');
2727
const [hotkey, setHotkey] = useState('');
2828
const history = useHistory();
29-
30-
ipcRenderer.on('hot-key-called', () => {
31-
setValue(clipboard.readText());
32-
});
29+
const location = useLocation();
3330

3431
useEffect(() => {
3532
setValue(clipboard.readText());
36-
}, []);
33+
}, [location]);
3734

3835
useEffect(() => {
3936
ipcRenderer

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "plainbelt",
33
"productName": "plainbelt",
4-
"version": "0.0.6",
4+
"version": "0.0.7",
55
"description": "A toolbelt for all your plain text",
66
"main": "./main.prod.js",
77
"author": {

0 commit comments

Comments
 (0)