Skip to content

Commit 80dd20b

Browse files
authored
feat: Migrate from redux to context & hooks (#463)
* chore: Remove redux and start migrating to context * chore: Display notifications successfully * chore: Fix a few tests * chore: Move more files * chore: Restore Settings on launch * chore: Use hook - useInterval * chore: Simpler logic for native notifiactions * chore: Store correct settings when updating settings * chore: Restore appearance on load * chore: Move files to src/ * fix: Correct imports * feat: Mark notification as read * feat: Unsubscribe from notification * feat: Mark repo notifications as read * chore: Rename Constants file to constants * feat: Implement Login with Enterprise & fix more tests * fix: Fix more tests * chore: Fix imports * chore: Test useNotifications hook * fix: Fix app context - callback dependencies * chore: Update dependencies * chore: Move auth hook to utils * chore: Tests for App context * chore: Clean Up * chore: Rename Notification component to NotificationRow
1 parent 924c5a7 commit 80dd20b

File tree

119 files changed

+3699
-5149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+3699
-5149
lines changed

.github/workflows/run-tests.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Run Tests
22

3-
on: [push, pull_request]
3+
on: [push]
44

55
jobs:
66
run-unit-tests:
@@ -26,7 +26,10 @@ jobs:
2626
- name: Run Prettier (Check)
2727
run: yarn prettier:check
2828

29+
- name: Run Typechecking
30+
run: yarn tsc --noEmit
31+
2932
- name: Run Jest
30-
run: yarn test --coverage --runInBand
33+
run: yarn test --coverage --runInBand --verbose
3134

3235
- uses: codecov/codecov-action@v1

package.json

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
"contributors": [
3838
{
3939
"name": "Emmanouil Konstantinidis",
40-
"url": "https://githib.com/manosim"
40+
"url": "https://github.com/manosim"
4141
},
4242
{
4343
"name": "Jake 'Sid' Smith",
44-
"url": "https://githib.com/JakeSidSmith"
44+
"url": "https://github.com/JakeSidSmith"
4545
}
4646
],
4747
"license": "MIT",
@@ -52,7 +52,7 @@
5252
"jest": {
5353
"preset": "ts-jest/presets/js-with-ts",
5454
"setupFiles": [
55-
"<rootDir>/src/js/__helpers__/setupEnvVars.js"
55+
"<rootDir>/src/__helpers__/setupEnvVars.js"
5656
],
5757
"testEnvironment": "jsdom",
5858
"coverageThreshold": {
@@ -106,12 +106,12 @@
106106
"afterSign": "scripts/notarize.js"
107107
},
108108
"dependencies": {
109-
"@primer/octicons-react": "^11.1.0",
109+
"@primer/octicons-react": "^11.2.0",
110110
"autoprefixer": "^10.1.0",
111-
"axios": "=0.21.0",
111+
"axios": "=0.21.1",
112112
"date-fns": "^2.16.1",
113113
"electron-updater": "^4.3.5",
114-
"final-form": "^4.19.1",
114+
"final-form": "^4.20.1",
115115
"lodash": "^4.17.20",
116116
"menubar": "^9.0.1",
117117
"nprogress": "=0.2.0",
@@ -120,43 +120,35 @@
120120
"react-dom": "=16.13.1",
121121
"react-emojione": "=5.0.1",
122122
"react-final-form": "^6.4.0",
123-
"react-is": "^16.13.1",
124-
"react-redux": "=7.2.0",
125-
"react-router-dom": "^5.1.2",
126-
"react-transition-group": "^4.3.0",
123+
"react-router-dom": "^5.2.0",
124+
"react-transition-group": "^4.4.1",
127125
"react-typist": "^2.0.5",
128-
"redux": "=4.0.5",
129-
"redux-storage": "=4.1.2",
130-
"redux-storage-decorator-filter": "=1.1.8",
131-
"redux-storage-engine-localstorage": "=1.1.4",
132-
"redux-thunk": "=2.3.0",
133126
"tailwindcss": "^2.0.2",
134-
"ts-loader": "^8.0.11",
135-
"typescript": "^4.1.2"
127+
"ts-loader": "^8.0.12",
128+
"typescript": "^4.1.3"
136129
},
137130
"devDependencies": {
138-
"@testing-library/react": "^10.0.2",
139-
"@types/jest": "^26.0.15",
131+
"@testing-library/react": "^11.2.2",
132+
"@testing-library/react-hooks": "^3.7.0",
133+
"@types/jest": "^26.0.19",
140134
"@types/lodash": "^4.14.165",
141-
"@types/node": "^14.14.9",
135+
"@types/node": "^14.14.14",
142136
"@types/react": "^16.9.32",
143-
"@types/react-redux": "^7.1.7",
144-
"@types/react-transition-group": "^4.2.4",
145-
"@types/styled-components": "^5.0.1",
137+
"@types/react-router-dom": "^5.1.6",
138+
"@types/react-transition-group": "^4.4.0",
146139
"css-loader": "^5.0.1",
147140
"electron": "^11.1.0",
148141
"electron-builder": "^22.9.1",
149142
"electron-notarize": "^1.0.0",
150143
"jest": "^26.6.3",
151-
"nock": "^12.0.3",
144+
"nock": "^13.0.5",
152145
"postcss-loader": "^4.1.0",
153-
"prettier": "=2.2.0",
146+
"prettier": "=2.2.1",
154147
"react-test-renderer": "=16.13.1",
155-
"redux-mock-store": "=1.5.4",
156148
"style-loader": "^2.0.0",
157149
"ts-jest": "^26.4.4",
158-
"webpack": "^5.6.0",
150+
"webpack": "^5.11.0",
159151
"webpack-cli": "^4.2.0",
160-
"webpack-merge": "^5.4.0"
152+
"webpack-merge": "^5.7.3"
161153
}
162154
}
File renamed without changes.
File renamed without changes.

src/__mocks__/mock-state.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Appearance, AuthState, SettingsState } from '../types';
2+
3+
export const mockAccounts: AuthState = {
4+
token: 'token-123-456',
5+
enterpriseAccounts: [
6+
{
7+
token: 'token-gitify-123-456',
8+
hostname: 'github.gitify.io',
9+
},
10+
],
11+
};
12+
13+
export const mockSettings: SettingsState = {
14+
participating: false,
15+
playSound: true,
16+
showNotifications: true,
17+
markOnClick: false,
18+
openAtStartup: false,
19+
appearance: Appearance.SYSTEM,
20+
};

src/js/__mocks__/mockedData.ts renamed to src/__mocks__/mockedData.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Notification, Repository } from '../../types/github';
2-
import { EnterpriseAccount } from '../../types/reducers';
1+
import { AccountNotifications, EnterpriseAccount } from '../types';
2+
import { Notification, Repository } from '../typesGithub';
33

44
export const mockedEnterpriseAccounts: EnterpriseAccount[] = [
55
{
@@ -251,7 +251,7 @@ export const mockedEnterpriseNotifications = [
251251
} as Notification,
252252
];
253253

254-
export const mockedNotificationsReducerData = [
254+
export const mockedAccountNotifications: AccountNotifications[] = [
255255
{
256256
hostname: 'github.com',
257257
notifications: mockedGithubNotifications,
@@ -261,3 +261,10 @@ export const mockedNotificationsReducerData = [
261261
notifications: mockedEnterpriseNotifications,
262262
},
263263
];
264+
265+
export const mockedSingleAccountNotifications: AccountNotifications[] = [
266+
{
267+
hostname: 'github.com',
268+
notifications: [mockedSingleNotification],
269+
},
270+
];
Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,27 @@
1-
import * as React from 'react';
1+
import React, { useContext } from 'react';
22
import {
33
Redirect,
44
HashRouter as Router,
55
Route,
66
Switch,
77
} from 'react-router-dom';
8-
import { Provider } from 'react-redux';
98

10-
import configureStore from './store/configureStore';
11-
import Loading from './components/loading';
12-
import Sidebar from './components/sidebar';
13-
14-
import EnterpriseLoginRoute from './routes/enterprise-login';
15-
import LoginRoute from './routes/login';
16-
import NotificationsRoute from './routes/notifications';
17-
import SettingsRoute from './routes/settings';
18-
19-
// Store
20-
export const store = configureStore();
9+
import { AppContext, AppProvider } from './context/App';
10+
import { Loading } from './components/Loading';
11+
import { LoginEnterpriseRoute } from './routes/LoginEnterprise';
12+
import { LoginRoute } from './routes/Login';
13+
import { NotificationsRoute } from './routes/Notifications';
14+
import { SettingsRoute } from './routes/Settings';
15+
import { Sidebar } from './components/Sidebar';
2116

2217
export const PrivateRoute = ({ component: Component, ...rest }) => {
23-
// @ts-ignore
24-
const authReducer = store.getState().auth;
25-
const isAuthenticated =
26-
authReducer.token !== null || authReducer.enterpriseAccounts.length > 0;
18+
const { isLoggedIn } = useContext(AppContext);
2719

2820
return (
2921
<Route
3022
{...rest}
3123
render={(props) =>
32-
isAuthenticated ? (
24+
isLoggedIn ? (
3325
<Component {...props} />
3426
) : (
3527
<Redirect
@@ -43,7 +35,7 @@ export const PrivateRoute = ({ component: Component, ...rest }) => {
4335

4436
export const App = () => {
4537
return (
46-
<Provider store={store}>
38+
<AppProvider>
4739
<Router>
4840
<div className="flex flex-col pl-14 h-full">
4941
<Loading />
@@ -53,10 +45,10 @@ export const App = () => {
5345
<PrivateRoute path="/" exact component={NotificationsRoute} />
5446
<PrivateRoute path="/settings" exact component={SettingsRoute} />
5547
<Route path="/login" component={LoginRoute} />
56-
<Route path="/enterpriselogin" component={EnterpriseLoginRoute} />
48+
<Route path="/enterpriselogin" component={LoginEnterpriseRoute} />
5749
</Switch>
5850
</div>
5951
</Router>
60-
</Provider>
52+
</AppProvider>
6153
);
6254
};

src/js/components/account-notifications.test.tsx renamed to src/components/AccountNotifications.test.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import * as React from 'react';
2-
import * as TestRendener from 'react-test-renderer';
1+
import React from 'react';
2+
import TestRendener from 'react-test-renderer';
33

4-
import { AccountNotifications } from './account-notifications';
4+
import { AccountNotifications } from './AccountNotifications';
55
import { mockedGithubNotifications } from '../__mocks__/mockedData';
66

7-
jest.mock('./repository');
7+
jest.mock('./Repository', () => ({
8+
RepositoryNotifications: () => <div>Repository</div>,
9+
}));
810

9-
describe('components/account-notifications.tsx', () => {
11+
describe('components/AccountNotifications.tsx', () => {
1012
it('should render itself (github.com with notifications)', () => {
1113
const props = {
1214
hostname: 'github.com',

src/js/components/account-notifications.tsx renamed to src/components/AccountNotifications.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as React from 'react';
2-
import * as _ from 'lodash';
1+
import React from 'react';
2+
import _ from 'lodash';
33
import { ChevronDownIcon, ChevronLeftIcon } from '@primer/octicons-react';
44

5-
import { Notification } from '../../types/github';
6-
import RepositoryNotifications from './repository';
5+
import { Notification } from '../typesGithub';
6+
import { RepositoryNotifications } from './Repository';
77

88
interface IProps {
99
hostname: string;

src/js/components/all-read.test.tsx renamed to src/components/AllRead.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as React from 'react';
22
import * as TestRenderer from 'react-test-renderer';
3+
import { Constants } from '../utils/constants';
34

4-
import Constants from '../utils/constants';
5-
import { AllRead } from './all-read';
5+
import { AllRead } from './AllRead';
66

77
jest.mock('react-typist');
88

0 commit comments

Comments
 (0)