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

Commit

Permalink
🐛 fix view mode displaying an incorrect resume (#68)
Browse files Browse the repository at this point in the history
The app used to use the "path" of a resume in view mode to identify a resume (instead of the UUID in edit mode). However the path was not unique and for this reason the resume shown in view mode could not be the same as the one in edit mode. This changes the view mode to use the UUID.
  • Loading branch information
hgwood authored Aug 24, 2020
1 parent a233530 commit 9ffc85a
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 589 deletions.
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ COPY app/ app/
COPY lib lib/
COPY webpack.config.js .
COPY app.json .
COPY build-path.js .
COPY .babelrc .
RUN npm run build

Expand All @@ -30,7 +29,6 @@ COPY server/package.json .
COPY server/package-lock.json .
RUN npm ci
COPY server/server.js .
COPY server/build-path.js .


EXPOSE 3000
Expand Down
97 changes: 0 additions & 97 deletions app-resume.json

This file was deleted.

4 changes: 2 additions & 2 deletions app/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default class Controller {
this.events.emit(name, data);
}

onInit({ id, secret }) {
this.store.load(id, secret);
onInit({ id, versionDate }) {
this.store.load(id, versionDate);
}

onUpdate(document) {
Expand Down
100 changes: 40 additions & 60 deletions app/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,60 +57,52 @@ export default class Store {
* 2.2 Not found => Events.DOCUMENT_NOT_FOUND
*
*/
load(id, secret) {
load(id, versionDate) {
if (!id) {
this.events.emit(Events.NO_DOCUMENT_ID, this.state);
return Promise.resolve(this.state);
}

return this
.localforage
.getItem(id)
.then((document) => {
if (null === document) {
return Promise.reject(new Error('document not found'));
}
let url = `${this.endpoint}/documents/${id}`
if (versionDate) {
url += `?version_date=${versionDate}`
}

return Promise.resolve(Immutable.fromJS(document));
})
.catch(() => {
return request
.get(`${this.endpoint}/documents/${id}`)
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${auth.accessToken}`)
.then(this._handleRequestSuccess.bind(this))
.catch(this._handleRequestError.bind(this))
.then((res) => {
return Promise.resolve(new Document({
uuid: res.body.uuid,
content: res.body.content,
metadata: res.body.metadata,
path: res.body.path,
last_modified: res.body.last_modified
}));
});
return request
.get(url)
.set('Accept', 'application/json')
.set('Content-Type', 'application/json')
.set('Authorization', `Bearer ${auth.accessToken}`)
.then(this._handleRequestSuccess.bind(this))
.catch(this._handleRequestError.bind(this))
.then((res) => {
return Promise.resolve(new Document({
uuid: res.body.uuid,
content: res.body.content,
metadata: res.body.metadata,
path: res.body.path,
last_modified: res.body.last_modified
}));
})
.then((document) => {
let metadata = document.get('metadata');
try {
metadata = document.get('metadata').toJS();
} catch (err) {
}

this._setState({
document: new Document({
uuid: document.get('uuid'),
content: document.get('content'),
metadata: metadata,
path: document.get('path'),
last_modified: document.get('last_modified'),
last_modified_locally: document.get('last_modified_locally')
}),
secret: secret
});
return this._localPersist();
});
let metadata = document.get('metadata');
try {
metadata = document.get('metadata').toJS();
} catch (err) {
}

this._setState({
document: new Document({
uuid: document.get('uuid'),
content: document.get('content'),
metadata: metadata,
path: document.get('path'),
last_modified: document.get('last_modified'),
last_modified_locally: document.get('last_modified_locally')
})
});
return this._localPersist();
});

}

Expand Down Expand Up @@ -282,20 +274,8 @@ export default class Store {

// Impure / side-effect free method
_localPersist() {
const doc = this.state.document;

this.localforage.setItem(
doc.get('uuid'),
new Document({
uuid: doc.get('uuid'),
content: doc.get('content'),
metadata: doc.get('metadata'),
path: doc.get('path'),
last_modified: doc.get('last_modified'),
last_modified_locally: doc.get('last_modified_locally')
}).toJS()
);
return Promise.resolve(this.state);
// I've disabled local persistence, yolo!
return Promise.resolve(this.state);
}

// Impure / side-effect free method
Expand Down
16 changes: 10 additions & 6 deletions app/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,12 @@ class App extends Component {
);
});

this.props.controller.dispatch('action:init', {
id: window.location.hash.slice(6),
secret: ''
const isViewing = window.location.hash.includes("/view")
const versionDate = (window.location.hash.match(/version_date=(\d\d\d\d-\d\d-\d\d)/) || [])[1]

this.props.controller.dispatch('action:init', {
id: window.location.hash.match(/\/app\/([^\/]+)($|\/)/)[1],
versionDate: isViewing ? versionDate : undefined
});
}

Expand All @@ -136,7 +139,7 @@ class App extends Component {
doc.get('uuid') !== window.history.state.uuid)
) {
if (uri.indexOf('undefined') == -1) {
window.history.pushState({ uuid: doc.get('uuid') }, `Zenika Resume - ${doc.get('uuid')}`, uri);
window.history.pushState({ uuid: doc.get('uuid') }, `Zenika Resume - ${doc.get('uuid')}`);
}
}
}
Expand Down Expand Up @@ -198,7 +201,7 @@ class App extends Component {
const locale = this.state.userPref.locale;
const messages = Translations[locale];

if (!this.state.document.uuid) {
if (!this.state.document.uuid || window.location.hash.includes("/view")) {
viewMode = 'viewMode';
}

Expand Down Expand Up @@ -322,10 +325,11 @@ class App extends Component {
<Footer
version={this.props.version}
metadata={this.state.document.get('metadata')}
path={this.state.document.get('path')}
uuid={this.state.document.get('uuid')}
toggleLocale={this.toggleLocale}
changeTheme={this.changeTheme}
currentLocale={locale}
sync={!viewMode}
/>
</div>
</IntlProvider>
Expand Down
25 changes: 4 additions & 21 deletions app/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { Config } from './../Config';
import {
FormattedMessage,
} from 'react-intl';
const buildPath = require('../../build-path');


const { string, func } = PropTypes;

Expand Down Expand Up @@ -51,21 +49,6 @@ export default class Footer extends Component {
});
}

getPath() {
let path = '';
if (this.props.path) {
path = this.props.path;
}
else if (this.props.metadata) {
if (this.props.metadata.firstname) {
path = buildPath(`${this.props.metadata.firstname} ${this.props.metadata.name} ${this.props.metadata.agency} ${this.props.metadata.lang}`);
} else {
path = buildPath(this.props.metadata.name);
}
}
return path;
}

render() {
return (
<footer className="main">
Expand All @@ -76,10 +59,10 @@ export default class Footer extends Component {
<a href="https://github.com/TailorDev/monod">Monod</a>
</div>
<a className="btn" onClick={this.showHelp}><i className="fa fa-question-circle-o" aria-hidden="true"></i><FormattedMessage id="help" /></a>
<Sync />
<span className="viewLink"><FormattedMessage id="read" />
<Link to={`/app/${this.getPath()}`}>
{this.getPath()}
{this.props.sync ? <Sync /> : null}
<span className="viewLink">
<Link to={`/app/${this.props.uuid}/view`}>
<FormattedMessage id="read" />
</Link>
</span>
<span className="viewLink">
Expand Down
4 changes: 2 additions & 2 deletions app/components/List.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ class ListAll extends Component {
</Link>
</TableCell>
<TableCell>
<Link className={this.classes.link} to={`app/${resume.path}`}>
{resume.path}
<Link className={this.classes.link} to={`app/${resume.uuid}/view`}>
{resume.uuid}
</Link>
</TableCell>
<TableCell>
Expand Down
2 changes: 1 addition & 1 deletion app/components/ResumeCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function ResumeCard(props) {
</Typography>
</CardContent>
<CardActions className={classes.cardActions}>
<Link to={`app/${data.path}`}>
<Link to={`app/${data.uuid}/view`}>
<Button variant="contained" color="primary">
View
</Button>
Expand Down
7 changes: 3 additions & 4 deletions app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './scss/main.scss';

import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Redirect, HashRouter } from 'react-router-dom';
import { HashRouter as Router, Route } from 'react-router-dom';
import { EventEmitter } from 'events';
import localforage from 'localforage';
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';
Expand Down Expand Up @@ -42,9 +42,8 @@ const theme = createMuiTheme({

auth.handleAuthentication().then(authResult => {
if (authResult) {
window.location.hash = '';
ReactDOM.render(
<HashRouter>
<Router>
<MuiThemeProvider theme={theme}>
<Header />
<Route path="/app" component={() => <App key={Date.now()} version={appVersion} controller={controller} />} />
Expand All @@ -54,7 +53,7 @@ auth.handleAuthentication().then(authResult => {
<Route exact path="/404" component={Page404} />
<Route exact path="/bye" component={Bye} />
</MuiThemeProvider>
</HashRouter>,
</Router>,
appElement
);
} else {
Expand Down
Loading

0 comments on commit 9ffc85a

Please sign in to comment.