Skip to content

Commit ee5a77a

Browse files
authored
Merge pull request #198 from canyener/clean-up
Clean up
2 parents b0a5a07 + 36ea762 commit ee5a77a

File tree

3 files changed

+50
-23
lines changed

3 files changed

+50
-23
lines changed

src/app/stores/activityStore.ts

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { makeObservable, observable, action, computed } from "mobx"
1+
import { makeObservable, observable, action, computed, configure, runInAction } from "mobx"
22
import { createContext, SyntheticEvent } from 'react'
33

44
import { IActivity } from "../models/activity"
55
import agent from '../api/agent'
66

7+
configure({
8+
enforceActions: 'always'
9+
})
10+
711
class ActivityStore {
812

913
constructor() {
@@ -27,27 +31,38 @@ class ActivityStore {
2731
try {
2832
const activityList = await agent.Activities.list()
2933

30-
activityList.forEach((activity) => {
31-
activity.date = activity.date.split('.')[0]
32-
this.activityRegistry.set(activity.id, activity)
34+
runInAction(() => {
35+
activityList.forEach((activity) => {
36+
activity.date = activity.date.split('.')[0]
37+
this.activityRegistry.set(activity.id, activity)
38+
})
39+
40+
this.loadingInitial = false
3341
})
3442

35-
this.loadingInitial = false
3643
} catch (error) {
44+
runInAction(() => {
45+
this.loadingInitial = false
46+
})
3747
console.log(error)
38-
this.loadingInitial = false
3948
}
4049
}
4150

4251
@action createActivity = async (activity: IActivity) => {
4352
this.submitting = true
4453
try {
4554
await agent.Activities.create(activity)
46-
this.activityRegistry.set(activity.id, activity)
47-
this.editMode = false
48-
this.submitting = false
55+
56+
runInAction(() => {
57+
this.activityRegistry.set(activity.id, activity)
58+
this.editMode = false
59+
this.submitting = false
60+
})
61+
4962
} catch (error) {
50-
this.submitting = false
63+
runInAction(() => {
64+
this.submitting = false
65+
})
5166
console.log(error)
5267
}
5368
}
@@ -56,12 +71,18 @@ class ActivityStore {
5671
this.submitting = true
5772
try {
5873
await agent.Activities.update(activity)
59-
this.activityRegistry.set(activity.id, activity)
60-
this.selectedActivity = activity
61-
this.editMode = false
62-
this.submitting = false
74+
75+
runInAction(() => {
76+
this.activityRegistry.set(activity.id, activity)
77+
this.selectedActivity = activity
78+
this.editMode = false
79+
this.submitting = false
80+
})
81+
6382
} catch (error) {
64-
this.submitting = false
83+
runInAction(() => {
84+
this.submitting = false
85+
})
6586
console.log(error)
6687
}
6788
}
@@ -71,13 +92,18 @@ class ActivityStore {
7192
this.target = event.currentTarget.name
7293
try {
7394
await agent.Activities.delete(id)
74-
this.activityRegistry.delete(id)
75-
this.submitting = false
76-
this.target = ''
7795

96+
runInAction(() => {
97+
this.activityRegistry.delete(id)
98+
this.submitting = false
99+
this.target = ''
100+
})
78101
} catch (error) {
79-
this.submitting = false
80-
this.target = ''
102+
runInAction(() => {
103+
this.submitting = false
104+
this.target = ''
105+
})
106+
81107
console.log(error)
82108
}
83109
}

src/features/activities/dashboard/ActivityDashboard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import ActivityStore from '../../../app/stores/activityStore'
66

77
import ActivityList from './ActivityList'
88
import ActivityDetails from '../details/ActivityDetails'
9-
import { ActivityForm } from '../form/ActivityForm'
9+
import ActivityForm from '../form/ActivityForm'
1010

1111
const ActivityDashboard: React.FC = () => {
1212
const activityStore = useContext(ActivityStore)

src/features/activities/form/ActivityForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { FormEvent, useContext, useState } from 'react'
22
import { Segment, Form, Button } from 'semantic-ui-react'
33
import { v4 as uuid } from 'uuid'
4+
import { observer } from 'mobx-react-lite'
45

56
import { IActivity } from '../../../app/models/activity'
67

@@ -15,7 +16,7 @@ const ActivityForm: React.FC<IProps> = ({
1516

1617
const activityStore = useContext(ActivityStore)
1718
const { createActivity, editActivity, submitting, cancelFormOpen } = activityStore
18-
19+
1920
const initializeForm = () => {
2021
if (initialFormState) {
2122
return initialFormState
@@ -100,4 +101,4 @@ const ActivityForm: React.FC<IProps> = ({
100101

101102
ActivityForm.displayName = 'ActivityForm'
102103

103-
export { ActivityForm }
104+
export default observer(ActivityForm)

0 commit comments

Comments
 (0)