Skip to content

Commit 930bf20

Browse files
committed
Only one notifications will close at a time now, You can now use Find IN page on the Help Section (Some issues with leftover Search Results still)
1 parent 4b405aa commit 930bf20

File tree

14 files changed

+226
-10722
lines changed

14 files changed

+226
-10722
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"cron": "^1.7.1",
7777
"electron-compile": "^6.4.4",
7878
"electron-devtools-installer": "^2.2.4",
79+
"electron-find": "^1.0.6",
7980
"electron-is-dev": "^1.1.0",
8081
"electron-squirrel-startup": "^1.0.0",
8182
"formik": "^2.0.1-rc.13",

src/@types/global.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
declare module 'react-chartkick';
2+
declare module 'electron-find';

src/app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const App: React.FunctionComponent<Props> = () => {
1010
<MemoryRouter>
1111
<Layout>
1212
<Switch>
13-
<Route exact path="/" render={() => <Redirect to="/console" />} />
13+
<Route exact path="/" render={() => <Redirect to="/help" />} />
1414
{routes.map((route, idx) => (
1515
<Route key={idx} path={route.path} component={route.component} />
1616
))}

src/components/PopupSearchBar.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { TextField } from '@material-ui/core';
2+
import {remote} from 'electron';
3+
import searchInPage from 'electron-in-page-search';
4+
import * as mousetrap from 'mousetrap';
5+
import * as React from 'react';
6+
import styled from 'styled-components';
7+
8+
import { bg0 } from '../styles/colors';
9+
10+
const Wrapper = styled.div`
11+
position: absolute;
12+
top: 0;
13+
right: 0;
14+
display: flex;
15+
width: 250px;
16+
height: 45px;
17+
background: ${bg0};
18+
align-items: center;
19+
justify-content: center;
20+
padding: 5px;
21+
`;
22+
23+
interface Props {}
24+
const PopupSearchBar: React.FunctionComponent<Props> = () => {
25+
26+
27+
28+
29+
return searchOpen ? (
30+
<Wrapper>
31+
<TextField
32+
inputRef={inputRef}
33+
placeholder={'Find On Page'}
34+
fullWidth
35+
name={'search-term'}
36+
/>
37+
</Wrapper>
38+
) : (
39+
<></>
40+
);
41+
};
42+
43+
export default PopupSearchBar;

src/containers/Dialogs/SettingsDialog/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Dialog from '@material-ui/core/Dialog';
2-
// import Divider from '@material-ui/core/Divider';
32
import List from '@material-ui/core/List';
43
import ListItem from '@material-ui/core/ListItem';
54
import ListItemText from '@material-ui/core/ListItemText';

src/containers/Map.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ interface State {
5252
}
5353
const Map: React.FunctionComponent<Props> = ({}) => {
5454
// /////////////
55-
// Refs
55+
// * Refs
5656
// /////////////
5757
const mapRef = React.useRef<any>(null);
5858
const anchorDiv = React.useRef<any>(null);
@@ -65,7 +65,7 @@ const Map: React.FunctionComponent<Props> = ({}) => {
6565
const activeServer = useSelector(activeServerSelector);
6666

6767
// /////////////
68-
// Component State
68+
// * Component State
6969
// /////////////
7070
const [state, setState] = React.useState<State>({
7171
map: {
@@ -117,7 +117,7 @@ const Map: React.FunctionComponent<Props> = ({}) => {
117117
};
118118

119119
// /////////////
120-
// Redux Actions
120+
// * Redux Actions
121121
// /////////////
122122
const dispatch = useDispatch();
123123
const deleteMarker = (id: number) =>
@@ -143,7 +143,7 @@ const Map: React.FunctionComponent<Props> = ({}) => {
143143
};
144144

145145
// /////////////
146-
// Effects
146+
// * Effects
147147
// /////////////
148148
// componentDidMount
149149
React.useEffect(() => {

src/containers/Notifications.tsx

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,19 @@ import IconButton from '@material-ui/core/IconButton';
22
import Snackbar from '@material-ui/core/Snackbar';
33
import CloseIcon from '@material-ui/icons/Close';
44
import * as React from 'react';
5-
import { connect } from 'react-redux';
5+
import { useDispatch, useSelector } from 'react-redux';
66

77
import { closeNotification } from '../redux/notifications/actions';
8-
import { notificationsSelector } from '../redux/notifications/selectors';
9-
import { NotificationsState } from '../redux/notifications/types';
10-
import { Dispatch, RootState } from '../redux/redux-types';
8+
import { showingNotificationsSelectors } from '../redux/notifications/selectors';
119
import { bg5 } from '../styles/colors';
1210

1311
interface Props {}
14-
interface ReduxProps {
15-
notifications: NotificationsState;
16-
handleCloseNotification: (id: number) => void;
17-
}
18-
const Notifications: React.FunctionComponent<Props & ReduxProps> = ({
19-
notifications,
20-
handleCloseNotification
21-
}) => {
12+
const Notifications: React.FunctionComponent<Props> = () => {
13+
const dispatch = useDispatch();
14+
const notifications = useSelector(showingNotificationsSelectors);
15+
const handleCloseNotification = (id: number) =>
16+
dispatch(closeNotification(id));
17+
2218
const colors = {
2319
error: '#ff5544',
2420
info: bg5,
@@ -67,10 +63,4 @@ const Notifications: React.FunctionComponent<Props & ReduxProps> = ({
6763
);
6864
};
6965

70-
const mapStateToProps = (state: RootState) => ({
71-
notifications: notificationsSelector(state)
72-
});
73-
const mapDispatchToProps = (dispatch: Dispatch) => ({
74-
handleCloseNotification: (id: number) => dispatch(closeNotification(id))
75-
});
76-
export default connect(mapStateToProps, mapDispatchToProps)(Notifications);
66+
export default Notifications;

src/containers/ServerHelp.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { remote } from 'electron';
2+
import { FindInPage } from 'electron-find';
3+
import * as mousetrap from 'mousetrap';
14
import * as React from 'react';
25
import * as ReactMarkdown from 'react-markdown';
36
import { useSelector } from 'react-redux';
@@ -7,6 +10,7 @@ import { serverHelpMarkdownSelector } from '../redux/app/selectors';
710
import { bg3, text } from '../styles/colors';
811

912
const Wrapper = styled.div`
13+
position: relative;
1014
padding: 10px;
1115
display: flex;
1216
color: ${text.primary};
@@ -22,7 +26,24 @@ interface Props {}
2226

2327
const ServerHelp: React.FunctionComponent<Props> = ({}) => {
2428
const markdown = useSelector(serverHelpMarkdownSelector);
25-
29+
React.useEffect(() => {
30+
const inPageSearch = new FindInPage(remote.getCurrentWebContents(), {
31+
preload: true,
32+
offsetTop: 85,
33+
offsetRight: 270
34+
});
35+
mousetrap.bind('ctrl+f', async () => {
36+
inPageSearch.openFindWindow();
37+
});
38+
mousetrap.bind('esc', () => {
39+
inPageSearch.closeFindWindow();
40+
});
41+
return () => {
42+
inPageSearch.destroy();
43+
mousetrap.unbind('ctrl+f');
44+
mousetrap.unbind('esc');
45+
};
46+
});
2647
return (
2748
<Wrapper>
2849
<ReactMarkdown className={'markdown-body'} source={markdown} />

src/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (isDev) {
2727
const createWindow = async () => {
2828
logger.info('MisRCON Starting');
2929

30-
// ! This is here to deal with Server Avatars not showing up in production
30+
// ! This is here to deal with The Default Server Avatars not showing up in production
3131
const { addBypassChecker } = require('electron-compile');
3232
addBypassChecker(
3333
(filePath: string) =>
@@ -113,11 +113,14 @@ app.on('activate', () => {
113113
}
114114
});
115115

116-
process.on('uncaughtException', err => {
117-
logger.info('uncaughtException', err);
118-
app.quit();
119-
});
116+
if (isDev){
117+
process.on('uncaughtException', err => {
118+
logger.info('uncaughtException', err);
119+
// app.quit();
120+
});
121+
122+
process.on('unhandledRejection', err => {
123+
logger.info('unhandledRejection', err);
124+
});
125+
}
120126

121-
process.on('unhandledRejection', err => {
122-
logger.info('unhandledRejection', err);
123-
});

src/redux/notifications/reducer.ts

Lines changed: 37 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
1-
import { getType } from 'typesafe-actions';
1+
import { createReducer } from 'typesafe-actions';
22

3-
import { actions, defaultNotificationsState, Types } from './index';
4-
import { defaultNotification } from './state';
3+
import { actions } from './index';
4+
import { defaultNotification, defaultNotificationsState } from './state';
55

6-
export default (
7-
state: Types.NotificationsState = defaultNotificationsState,
8-
action: Types.NotificationsActions
9-
): Types.NotificationsState => {
10-
switch (action.type) {
11-
// Info
12-
case getType(actions.addInfo):
13-
return [
14-
...state,
15-
{
16-
...defaultNotification,
17-
content: action.payload,
18-
variant: 'info',
19-
id: Date.now()
20-
}
21-
];
22-
23-
// Error
24-
case getType(actions.addError):
25-
return [
26-
...state,
27-
{
28-
...defaultNotification,
29-
content: action.payload,
30-
variant: 'error',
31-
id: Date.now()
32-
}
33-
];
34-
35-
// Success
36-
case getType(actions.addSuccess):
37-
return [
38-
...state,
39-
{
40-
...defaultNotification,
41-
content: action.payload,
42-
variant: 'success',
43-
id: Date.now()
44-
}
45-
];
46-
47-
case getType(actions.closeNotification):
48-
return state.map(notification => ({ ...notification, open: false }));
49-
50-
default:
51-
return state;
52-
}
53-
};
6+
export default createReducer(defaultNotificationsState)
7+
.handleAction(actions.addInfo, (state, action) => [
8+
...state,
9+
{
10+
...defaultNotification,
11+
content: action.payload,
12+
variant: 'info',
13+
id: Date.now()
14+
}
15+
])
16+
.handleAction(actions.addError, (state, action) => [
17+
...state,
18+
{
19+
...defaultNotification,
20+
content: action.payload,
21+
variant: 'error',
22+
id: Date.now()
23+
}
24+
])
25+
.handleAction(actions.addSuccess, (state, action) => [
26+
...state,
27+
{
28+
...defaultNotification,
29+
content: action.payload,
30+
variant: 'success',
31+
id: Date.now()
32+
}
33+
])
34+
.handleAction(actions.closeNotification, (state, action) =>
35+
state.map(notification => ({
36+
...notification,
37+
open: action.payload === notification.id ? false : notification.open
38+
}))
39+
);

0 commit comments

Comments
 (0)