Skip to content

Commit 83ec520

Browse files
committed
Dev login and memory
1 parent 85ada67 commit 83ec520

7 files changed

Lines changed: 51 additions & 24 deletions

File tree

electron.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ function createWindow() {
2525
nodeIntegration: true
2626
}
2727
});
28-
2928

3029
const startUrl =
3130
process.env.ELECTRON_START_URL ||
@@ -43,7 +42,7 @@ function createWindow() {
4342
win.on('closed', () => {
4443
windows.delete(win);
4544
});
46-
45+
4746
windows.add(win);
4847
}
4948

src/client.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ export default class Client extends React.Component {
2121
this.history = createHistory();
2222

2323
const credentials = getCredentials();
24-
this.store = createReduxStore(
25-
this.history,
26-
credentials ? Map().setIn(['data', 'credentials'], fromJS(credentials)) : undefined
27-
);
24+
25+
let state: Map<String, any> = Map();
26+
if (credentials) {
27+
state = state.setIn(['data', 'credentials'], fromJS(credentials.credentials));
28+
state = state.setIn(['data', 'auth'], fromJS(credentials.auth));
29+
}
30+
31+
this.store = createReduxStore(this.history, state);
2832
}
2933

3034
render() {

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ ReactDOM.render(<Client />, document.getElementById('root'));
88
// If you want your app to work offline and load faster, you can change
99
// unregister() to register() below. Note this comes with some pitfalls.
1010
// Learn more about service workers: http://bit.ly/CRA-PWA
11-
serviceWorker.unregister();
11+
serviceWorker.register();

src/modules/List/component.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ class ListView extends React.Component<ListViewProps> {
120120
}
121121
}
122122

123+
componentDidMount() {
124+
if (this.props.data.length === 0) {
125+
this.props.list({});
126+
}
127+
}
128+
123129
private applyFilters(data: any[]) {
124130
if (!this.state.search) {
125131
return data;
@@ -153,11 +159,6 @@ class ListView extends React.Component<ListViewProps> {
153159
<div className={classes.root}>
154160
<Grid container spacing={3} justify="center">
155161
<Grid item xs={12}>
156-
{error && (
157-
<Typography variant="body1" color="error">
158-
{error.message}
159-
</Typography>
160-
)}
161162
{data && (
162163
<Paper>
163164
<Table className={classes.table}>
@@ -171,7 +172,7 @@ class ListView extends React.Component<ListViewProps> {
171172
</TableRow>
172173
</TableHead>
173174
<TableBody>
174-
{filteredData.length === 0 && (
175+
{filteredData.length === 0 && !error && (
175176
<TableRow>
176177
<TableCell colSpan={5}>
177178
<Typography align="center" color="primary">
@@ -180,6 +181,15 @@ class ListView extends React.Component<ListViewProps> {
180181
</TableCell>
181182
</TableRow>
182183
)}
184+
{error && (
185+
<TableRow>
186+
<TableCell colSpan={5}>
187+
<Typography align="center" color="error">
188+
{error.message}
189+
</Typography>
190+
</TableCell>
191+
</TableRow>
192+
)}
183193
{filteredData
184194
.slice(page * countPerPage, page * countPerPage + countPerPage)
185195
.map((file: any) => {

src/modules/List/saga.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ function* listSaga(action: any) {
2323

2424
export default function* saga() {
2525
yield takeLatest((action: any) => action.type === 'LOAD_DATA' && action.meta === 'list', listSaga);
26-
yield takeLatest(
26+
27+
/*yield takeLatest(
2728
(action: any) => action.type === 'SET_STATE' && action.meta === 'auth' && !action.error,
2829
function*() {
2930
yield put(loadData({}, 'list'));
3031
}
31-
);
32+
);*/
33+
3234
yield takeLatest(selectFile, function*(action) {
3335
// get all files from state
3436
let files: Map<String, any> = yield select(s => selectDataAtPath(s, ['selectedFiles'], Map<String, any>()));

src/modules/Login/saga.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { setState, deleteState } from '../Data';
44
import { stopSubmit } from 'redux-form/immutable';
55
import { ValidationError } from 'joi';
66
import { push } from 'connected-react-router';
7-
import { setCredentials } from './storage';
7+
import { setCredentials, clearCredentials } from './storage';
88
import { login } from './actions';
99
import { login as loginApi } from '../../api';
1010

@@ -14,7 +14,7 @@ function* loginSaga(action: any) {
1414
yield put(setState(action.payload.credentials, 'credentials'));
1515
yield put(loadDataDone(data, action.meta));
1616
yield put(setState(data, 'auth'));
17-
setCredentials({ ...action.payload.credentials });
17+
setCredentials({ credentials: action.payload.credentials, auth: data });
1818
if (action.payload.redirectAfter) {
1919
yield put(push(action.payload.redirectAfter));
2020
}
@@ -45,7 +45,7 @@ function* loginSaga(action: any) {
4545

4646
function* logoutSaga() {
4747
if (typeof window !== 'undefined') {
48-
window.localStorage.removeItem('credentials');
48+
clearCredentials();
4949
}
5050
yield all([put(resetData()), put(deleteState('auth')), put(deleteState('credentials'))]);
5151
}
@@ -56,8 +56,12 @@ export default function* saga() {
5656
// init
5757
const location = yield select(state => state.get('router').location);
5858
const credentials = yield select(state => state.getIn(['data', 'credentials']));
59-
if (credentials && !/^\/login/g.test(location.pathname)) {
60-
yield put(login({ credentials: credentials.toJS() }));
59+
const auth = yield select(state => state.getIn(['data', 'auth']));
60+
61+
if (credentials && auth && !/^\/list/g.test(location.pathname)) {
62+
yield put(push('/list'));
63+
} else if ((!credentials || !auth) && !/^\/login/g.test(location.pathname)) {
64+
yield put(push('/login'));
6165
}
6266

6367
yield takeLatest((action: any) => action.type === 'LOGOUT', logoutSaga);

src/modules/Login/storage.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
export function getCredentials() {
22
try {
3-
const credentials = window.localStorage.getItem('credentials');
3+
const credentials = window.localStorage.getItem('simples3:credentials');
44
if (credentials) {
55
return JSON.parse(credentials);
66
}
77
} catch (e) {
8-
return null;
8+
console.log('Storage', e);
99
}
1010
}
1111

1212
export function setCredentials(credentials: any) {
1313
try {
14-
window.localStorage.setItem('credentials', JSON.stringify(credentials));
14+
window.localStorage.setItem('simples3:credentials', JSON.stringify(credentials));
1515
} catch (e) {
16-
return null;
16+
console.log('Storage', e);
17+
}
18+
}
19+
20+
export function clearCredentials() {
21+
try {
22+
window.localStorage.removeItem('simples3:credentials');
23+
} catch (e) {
24+
console.log('Storage', e);
1725
}
1826
}

0 commit comments

Comments
 (0)