Skip to content

Commit 1973d53

Browse files
committed
fix: linterror
1 parent 7ec27ab commit 1973d53

File tree

7 files changed

+158
-97
lines changed

7 files changed

+158
-97
lines changed

src/containers/Activity.js

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -66,35 +66,35 @@ class Activity extends Component {
6666
};
6767
}
6868

69-
componentWillMount() {
69+
async componentWillMount() {
70+
const { userId, history, match } = this.props;
7071
// 認証していないユーザーとメンバー以外をルートに返す
71-
const worksheetId = encodeURI(this.props.match.params.id);
72-
if (this.props.userId && worksheetId) {
73-
database.ref(`/${constants.API_VERSION}/worksheets/${worksheetId}/members/`).once('value').then((memberIds) => {
74-
if (memberIds.exists() && Array.isArray(memberIds.val()) && memberIds.val().includes(this.props.userId)) {
75-
this.setState({ worksheetId });
76-
// メンバーを取得する処理
77-
Promise.all(memberIds.val().map(uid => database.ref(`/${constants.API_VERSION}/users/${uid}/settings/`).once('value'))).then((members) => {
78-
const memberDatas = members.filter(member => member.exists()).map(member => member.val());
79-
if (this.hot) {
80-
this.hot.updateSettings({ members: memberDatas });
81-
// データの取得処理
82-
this.setActivityData();
83-
} else {
84-
this.props.history.push('/');
85-
}
86-
});
87-
} else {
88-
this.props.history.push('/');
89-
}
90-
});
72+
const worksheetId = encodeURI(match.params.id);
73+
if (!userId || !worksheetId) {
74+
history.push('/');
75+
return;
76+
}
77+
const memberIds = await database.ref(`/${constants.API_VERSION}/worksheets/${worksheetId}/members/`).once('value');
78+
if (memberIds.exists() && Array.isArray(memberIds.val()) && memberIds.val().includes(userId)) {
79+
this.setState({ worksheetId });
80+
// メンバーを取得する処理
81+
const members = await Promise.all(memberIds.val().map(uid => database.ref(`/${constants.API_VERSION}/users/${uid}/settings/`).once('value')));
82+
const memberDatas = members.filter(member => member.exists()).map(member => member.val());
83+
if (this.hot) {
84+
this.hot.updateSettings({ members: memberDatas });
85+
// データの取得処理
86+
this.setActivityData();
87+
} else {
88+
history.push('/');
89+
}
9190
} else {
92-
this.props.history.push('/');
91+
history.push('/');
9392
}
9493
}
9594

9695
componentDidMount() {
97-
if (!this.props.userId) return;
96+
const { userId } = this.props;
97+
if (!userId) return;
9898
const self = this;
9999
// この画面だけで使う日付のカラムを追加
100100
hotConf.columns.unshift({
@@ -105,7 +105,7 @@ class Activity extends Component {
105105
colWidths: 70,
106106
});
107107
this.hot = new Handsontable(this.hotDom, Object.assign({}, hotConf, {
108-
userId: this.props.userId,
108+
userId,
109109
isActiveNotifi: false,
110110
renderAllRows: true,
111111
height: 300,
@@ -125,9 +125,8 @@ class Activity extends Component {
125125
}
126126

127127
setActivityData() {
128-
const startDate = moment(this.state.startDate);
129-
const endDate = moment(this.state.endDate);
130-
const diff = endDate.diff(startDate, 'days');
128+
const { worksheetId, startDate, endDate } = this.state;
129+
const diff = moment(endDate).diff(moment(startDate), 'days');
131130
if (!util.isNaturalNumber(diff)) {
132131
this.hot.updateSettings({ data: [] });
133132
return;
@@ -138,8 +137,8 @@ class Activity extends Component {
138137
return;
139138
}
140139
const promises = [];
141-
promises.push(database.ref(`/${constants.API_VERSION}/worksheets/${this.state.worksheetId}/tableTasks/${startDate.format(constants.DATEFMT)}`).once('value'));
142-
promises.push(...Array(diff).fill('dummy').map(() => database.ref(`/${constants.API_VERSION}/worksheets/${this.state.worksheetId}/tableTasks/${startDate.add(1, 'days').format(constants.DATEFMT)}`).once('value')));
140+
promises.push(database.ref(`/${constants.API_VERSION}/worksheets/${worksheetId}/tableTasks/${moment(startDate).format(constants.DATEFMT)}`).once('value'));
141+
promises.push(...Array(diff).fill('dummy').map(() => database.ref(`/${constants.API_VERSION}/worksheets/${worksheetId}/tableTasks/${moment(startDate).add(1, 'days').format(constants.DATEFMT)}`).once('value')));
143142
Promise.all(promises).then((datas) => {
144143
const datasVals = datas.map(data => (data.exists() ? data.val() : [{
145144
id: '', assign: '', title: 'no task', estimate: '', startTime: '', endTime: '', memo: '',
@@ -161,18 +160,28 @@ class Activity extends Component {
161160
}
162161

163162
syncStateByRender() {
163+
const { taskData } = this.state;
164164
if (!this.hot) return;
165165
const hotTasks = getHotTasksIgnoreEmptyTask(this.hot);
166-
if (!util.equal(hotTasks, this.state.taskData)) {
166+
if (!util.equal(hotTasks, taskData)) {
167167
this.setState({ taskData: JSON.stringify(hotTasks, null, '\t') });
168168
}
169169
}
170170

171171
backToWorkSheet() {
172-
this.props.history.push(`/${this.state.worksheetId}`);
172+
const { history } = this.props;
173+
const { worksheetId } = this.state;
174+
history.push(`/${worksheetId}`);
173175
}
174176

175177
render() {
178+
const {
179+
startDate,
180+
endDate,
181+
taskData,
182+
isOpenSnackbar,
183+
snackbarText,
184+
} = this.state;
176185
const { classes, theme } = this.props;
177186
return (
178187
<Grid className={classes.root} container spacing={theme.spacing.unit} alignItems="stretch" justify="center">
@@ -189,35 +198,35 @@ class Activity extends Component {
189198
<Typography gutterBottom variant="caption">
190199
本日(
191200
{moment().format(constants.DATEFMT)}
192-
)
201+
)
193202
</Typography>
194-
<DatePicker value={this.state.startDate} changeDate={(e) => { this.changeDate('startDate', e.target.value); }} label="開始" />
203+
<DatePicker value={startDate} changeDate={(e) => { this.changeDate('startDate', e.target.value); }} label="開始" />
195204
<span style={{ margin: `0 ${theme.spacing.unit * 2}px` }}>
196205
<ArrowForward />
197206
</span>
198-
<DatePicker value={this.state.endDate} changeDate={(e) => { this.changeDate('endDate', e.target.value); }} label="終了" />
207+
<DatePicker value={endDate} changeDate={(e) => { this.changeDate('endDate', e.target.value); }} label="終了" />
199208
</Grid>
200209
<Grid item xs={12}>
201-
{this.state.taskData !== '' && (
210+
{taskData !== '' && (
202211
<div>
203212
<Typography gutterBottom variant="caption">
204213
見積:
205214
<span className={classes.block} style={{ color: constants.brandColor.base.GREEN }}>
206-
215+
207216
</span>
208-
(緑色) /
217+
(緑色) /
209218
実績:
210219
<span className={classes.block} style={{ color: constants.brandColor.base.BLUE }}>
211-
220+
212221
</span>
213-
(青色) /
222+
(青色) /
214223
残:
215224
<span className={classes.block} style={{ color: constants.brandColor.base.RED }}>
216-
225+
217226
</span>
218-
(赤色)
227+
(赤色)
219228
</Typography>
220-
<ActivityChart tableTasks={JSON.parse(this.state.taskData)} />
229+
<ActivityChart tableTasks={JSON.parse(taskData)} />
221230
</div>
222231
)}
223232
</Grid>
@@ -226,7 +235,7 @@ class Activity extends Component {
226235
</Grid>
227236
<Grid item xs={4}>
228237
<CodeMirror
229-
value={this.state.taskData}
238+
value={taskData}
230239
options={Object.assign({}, editorOptions, { readOnly: true })}
231240
/>
232241
</Grid>
@@ -238,9 +247,9 @@ class Activity extends Component {
238247
</Grid>
239248
<Snackbar
240249
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
241-
open={this.state.isOpenSnackbar}
250+
open={isOpenSnackbar}
242251
onClose={() => { this.setState({ isOpenSnackbar: false }); }}
243-
message={this.state.snackbarText}
252+
message={snackbarText}
244253
/>
245254
</Grid>
246255
);

src/containers/App.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,8 @@ class App extends Component {
218218
}
219219

220220
handleUser({ displayName, email, photoURL }) {
221-
this.setState({ user: Object.assign(this.state.user, { displayName, email, photoURL }) });
221+
const { user } = this.state;
222+
this.setState({ user: Object.assign(user, { displayName, email, photoURL }) });
222223
}
223224

224225
signup({
@@ -273,38 +274,44 @@ class App extends Component {
273274
isOpenSidebar: false,
274275
});
275276
auth.signOut().then(() => {
276-
this.props.history.push('/logout');
277+
const { history } = this.props;
278+
history.push('/logout');
277279
}).catch((error) => {
278280
throw new Error(error);
279281
});
280282
}
281283

282284
createWorksheet() {
283-
if (this.state.newWorksheetName === '') {
285+
const {
286+
newWorksheetName,
287+
user,
288+
worksheets,
289+
} = this.state;
290+
if (newWorksheetName === '') {
284291
alert(i18n.t('validation.must_target', { target: i18n.t('common.worksheetName') }));
285292
return;
286293
}
287-
if (!util.validateDatabaseKey(this.state.newWorksheetName)) {
294+
if (!util.validateDatabaseKey(newWorksheetName)) {
288295
alert(i18n.t('validation.containsForbiddenCharacter_target', { target: i18n.t('common.worksheetName') }));
289296
return;
290297
}
291298
// ワークシートのIDはシート名をtoLowerCaseしてencodeURIしたものにするシート名はシート名で別管理する
292-
const newWorksheetId = util.formatURLString(this.state.newWorksheetName);
299+
const newWorksheetId = util.formatURLString(newWorksheetName);
293300
// ワークシートのIDが存在しない場合は作成できる。
294301
database.ref(`/${constants.API_VERSION}/worksheets/${newWorksheetId}/`).once('value').then((snapshot) => {
295302
if (snapshot.exists()) {
296303
alert(i18n.t('validation.cantCreate_target', { target: i18n.t('common.worksheetName') }));
297304
} else {
298305
Promise.all([
299-
database.ref(`/${constants.API_VERSION}/users/${this.state.user.uid}/worksheets/`).set(this.state.worksheets.map(worksheet => worksheet.id).concat([newWorksheetId])),
300-
database.ref(`/${constants.API_VERSION}/worksheets/${newWorksheetId}/`).set({ members: [this.state.user.uid], name: this.state.newWorksheetName, disclosureRange: constants.worksheetDisclosureRange.PRIVATE }),
306+
database.ref(`/${constants.API_VERSION}/users/${user.uid}/worksheets/`).set(worksheets.map(worksheet => worksheet.id).concat([newWorksheetId])),
307+
database.ref(`/${constants.API_VERSION}/worksheets/${newWorksheetId}/`).set({ members: [user.uid], name: newWorksheetName, disclosureRange: constants.worksheetDisclosureRange.PRIVATE }),
301308
]).then(() => {
302309
this.setState({
303-
worksheets: this.state.worksheets.concat([{ id: newWorksheetId, name: this.state.newWorksheetName }]),
310+
worksheets: worksheets.concat([{ id: newWorksheetId, name: newWorksheetName }]),
304311
newWorksheetName: '',
305312
isOpenCreateWorksheetModal: false,
306313
isOpenSnackbar: true,
307-
snackbarText: i18n.t('common.wasCreated_target', { target: this.state.newWorksheetName }),
314+
snackbarText: i18n.t('common.wasCreated_target', { target: newWorksheetName }),
308315
});
309316
this.goWorkSheet(newWorksheetId);
310317
});
@@ -313,8 +320,9 @@ class App extends Component {
313320
}
314321

315322
goWorkSheet(id) {
316-
this.props.history.push('/');
317-
setTimeout(() => { this.props.history.push(`/${id}`); });
323+
const { history } = this.props;
324+
history.push('/');
325+
setTimeout(() => { history.push(`/${id}`); });
318326
if (util.isMobile()) this.setState({ isOpenSidebar: false });
319327
}
320328

@@ -377,7 +385,13 @@ class App extends Component {
377385
</ListItem>
378386
);
379387
})}
380-
<ListItem divider button onClick={() => { this.setState({ isOpenCreateWorksheetModal: true }); }}>
388+
<ListItem
389+
divider
390+
button
391+
onClick={() => {
392+
this.setState({ isOpenCreateWorksheetModal: true });
393+
}}
394+
>
381395
<ListItemIcon>
382396
<Add />
383397
</ListItemIcon>
@@ -401,7 +415,9 @@ class App extends Component {
401415
userId={user.uid}
402416
userName={user.displayName}
403417
userPhotoURL={user.photoURL}
404-
toggleHelpDialog={() => { this.setState({ isOpenHelpDialog: !isOpenHelpDialog }); }}
418+
toggleHelpDialog={() => {
419+
this.setState({ isOpenHelpDialog: !isOpenHelpDialog });
420+
}}
405421
{...props}
406422
/>
407423
)}

src/containers/ErrorBoundary.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ class ErrorBoundary extends Component {
4444
this.state = { hasError: false };
4545
}
4646

47-
componentDidCatch(error, info) {
47+
componentDidCatch(errorEvent, info) {
4848
this.setState({ hasError: true });
49-
Raven.captureException(error, { extra: info });
49+
Raven.captureException(errorEvent, { extra: info });
5050
}
5151

5252
render() {
53-
const { classes } = this.props;
54-
if (this.state.hasError) {
53+
const { hasError } = this.state;
54+
const { classes, children } = this.props;
55+
if (hasError) {
5556
// render fallback UI
5657
return (
5758
<Grid className={classes.root} container spacing={0} alignItems="stretch" justify="center">
@@ -82,7 +83,7 @@ class ErrorBoundary extends Component {
8283
</Grid>
8384
);
8485
}
85-
return this.props.children;
86+
return children;
8687
}
8788
}
8889
ErrorBoundary.propTypes = {

0 commit comments

Comments
 (0)