Skip to content

Commit 698d31b

Browse files
committed
refactor: profile data setting logic
1 parent c7976a1 commit 698d31b

File tree

30 files changed

+267
-249
lines changed

30 files changed

+267
-249
lines changed

electron/actions/app/setup.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ export default function () {
1515

1616
createAboutWindow()
1717

18-
if (app.commandLine.hasSwitch(
19-
'open-about-window'
20-
)) {
18+
const isOpenAboutWindow =
19+
app
20+
.commandLine
21+
.hasSwitch(
22+
'open-about-window'
23+
)
24+
25+
if (isOpenAboutWindow) {
2126
aboutWindow.show()
2227
}
2328

electron/events/ipc/electronStore.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import {
55
handleGetElectronStoreData,
66
handleGetElectronStoreKey,
77
handleAddElectronStoreValue,
8-
handleDeleteElectronStoreValue,
9-
handleSetElectronStoreData
8+
handleDeleteElectronStoreValue
109
} from '../../handlers/ipc/electronStore.js'
1110

1211
export default function () {
@@ -29,9 +28,4 @@ export default function () {
2928
'delete-electron-store-value',
3029
handleDeleteElectronStoreValue
3130
)
32-
33-
ipcMain.handle(
34-
'set-electron-store-data',
35-
handleSetElectronStoreData
36-
)
3731
}

electron/handlers/ipc/electronStore.js

-16
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import addElectronStoreValue
66
from '../../actions/electronStore/addValue.js'
77
import deleteElectronStoreValue
88
from '../../actions/electronStore/deleteValue.js'
9-
import setElectronStoreData
10-
from '../../actions/electronStore/setData.js'
119

1210
export function handleGetElectronStoreData () {
1311
return getElectronStoreData()
@@ -48,17 +46,3 @@ export function handleDeleteElectronStoreValue (
4846
uuid
4947
)
5048
}
51-
52-
export function handleSetElectronStoreData (
53-
_,
54-
data
55-
) {
56-
const dataFormatted =
57-
JSON.parse(
58-
data
59-
)
60-
61-
return setElectronStoreData(
62-
dataFormatted
63-
)
64-
}

electron/plugins/electronStore/schema.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,19 @@ export default {
307307
type: 'boolean',
308308
default: false
309309
},
310+
'profile.id': {
311+
type: [
312+
'null',
313+
'number'
314+
],
315+
default: null
316+
},
310317
'profile.connections': {
311-
type: 'object',
312-
default: {}
318+
type: [
319+
'null',
320+
'object'
321+
],
322+
default: null
313323
},
314324
'profile.info': {
315325
type: [

src/components/App/PageLayout/RootPageLayout.vue

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
v-if="profileId"
44
/>
55

6+
<TheLoginObserver />
7+
68
<TheLogoutObserver />
79

810
<TheAccountDeleteObserver />
@@ -48,6 +50,8 @@ import {
4850
} from 'pinia'
4951
import playerStore from '@/stores/player'
5052
import profileStore from '@/stores/profile'
53+
import TheLoginObserver
54+
from '@/components/layout/observers/TheLoginObserver.vue'
5155
import TheLogoutObserver
5256
from '@/components/layout/observers/TheLogoutObserver.vue'
5357
import TheAccountDeleteObserver
@@ -101,6 +105,7 @@ export default {
101105
name: 'RootPageLayout',
102106
components: {
103107
TheOnlineObserver,
108+
TheLoginObserver,
104109
TheLogoutObserver,
105110
TheAccountDeleteObserver,
106111
TheNativeThemeObserver,

src/components/containers/forms/profile/BaseProfileCreateFormContainer.vue

+19-55
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
</template>
1111

1212
<script>
13-
import {
14-
mapState
15-
} from 'pinia'
16-
import profileStore from '@/stores/profile'
1713
import BaseFormContainer
1814
from '@/components/containers/forms/BaseFormContainer.vue'
1915
import profileCreateFormOptions
@@ -22,7 +18,6 @@ import {
2218
birthdate as formatBirthdate
2319
} from '@/helpers/formatters/dateTimeString'
2420
import createProfile from '@/helpers/actions/api/profile/create'
25-
import getProfile from '@/helpers/actions/api/profile/get'
2621
import {
2722
update as updateGlobalStore
2823
} from '@/helpers/actions/store/global'
@@ -37,12 +32,8 @@ export default {
3732
},
3833
data () {
3934
return {
40-
token: null,
41-
profileId: null,
42-
profileData: null,
4335
error: null,
4436
isLoading: false,
45-
isRemember: false,
4637
fields: [
4738
'email',
4839
'password',
@@ -52,34 +43,18 @@ export default {
5243
}
5344
},
5445
computed: {
55-
...mapState(
56-
profileStore,
57-
{
58-
profileToken: 'token'
59-
}
60-
),
6146
options () {
6247
return profileCreateFormOptions(
6348
{
64-
onSuccess: this.handleSuccess
49+
onSuccess:
50+
this.handleSubmitSuccess
6551
}
6652
)
67-
},
68-
profileArgs () {
69-
return {
70-
profileId: this.profileId
71-
}
7253
}
7354
},
74-
watch: {
75-
profileId: 'handleProfileIdChange',
76-
profileToken: 'handleProfileTokenChange',
77-
profileData: 'handleProfileDataChange'
78-
},
7955
methods: {
8056
createProfile,
81-
getProfile,
82-
handleSuccess (
57+
handleSubmitSuccess (
8358
event,
8459
fields
8560
) {
@@ -92,30 +67,27 @@ export default {
9267
9368
this.createProfile(
9469
createArgs
70+
).then(
71+
this.handleProfileCreateSuccess
9572
)
9673
},
97-
handleProfileIdChange (
98-
value
99-
) {
100-
if (value) {
101-
this.setSessionData()
102-
}
103-
},
104-
handleProfileTokenChange (
105-
value
106-
) {
107-
if (value) {
108-
this.getProfile(
109-
this.profileArgs
110-
)
111-
}
112-
},
113-
handleProfileDataChange (
114-
value
74+
async handleProfileCreateSuccess (
75+
responseData
11576
) {
77+
const profileId =
78+
responseData.profile.id
79+
80+
const profileToken =
81+
responseData.profile.token
82+
83+
const isRememberProfile =
84+
responseData.isRemember
85+
11686
updateGlobalStore(
11787
{
118-
'profile.info': value
88+
'profile.id': profileId,
89+
'profile.token': profileToken,
90+
'profile.isRemember': isRememberProfile
11991
}
12092
)
12193
},
@@ -164,14 +136,6 @@ export default {
164136
isRemember
165137
}
166138
},
167-
setSessionData () {
168-
updateGlobalStore(
169-
{
170-
'profile.token': this.token,
171-
'profile.isRemember': this.isRemember
172-
}
173-
)
174-
},
175139
validateField (
176140
value
177141
) {

src/components/containers/forms/profile/BaseProfileLoginFormContainer.vue

+19-55
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@
1010
</template>
1111

1212
<script>
13-
import {
14-
mapState
15-
} from 'pinia'
16-
import profileStore from '@/stores/profile'
1713
import BaseFormContainer
1814
from '@/components/containers/forms/BaseFormContainer.vue'
1915
import profileLoginFormOptions
2016
from '@/helpers/formatters/plugins/semantic/options/form/profile/login'
2117
import createSession from '@/helpers/actions/api/session/create'
22-
import getProfile from '@/helpers/actions/api/profile/get'
2318
import {
2419
update as updateGlobalStore
2520
} from '@/helpers/actions/store/global'
@@ -31,47 +26,27 @@ export default {
3126
},
3227
data () {
3328
return {
34-
token: null,
35-
profileId: null,
36-
profileData: null,
3729
error: null,
3830
isLoading: false,
39-
isRemember: false,
4031
fields: [
4132
'email',
4233
'password'
4334
]
4435
}
4536
},
4637
computed: {
47-
...mapState(
48-
profileStore,
49-
{
50-
profileToken: 'token'
51-
}
52-
),
5338
options () {
5439
return profileLoginFormOptions(
5540
{
56-
onSuccess: this.handleSuccess
41+
onSuccess:
42+
this.handleSubmitSuccess
5743
}
5844
)
59-
},
60-
profileArgs () {
61-
return {
62-
profileId: this.profileId
63-
}
6445
}
6546
},
66-
watch: {
67-
profileId: 'handleProfileIdChange',
68-
profileToken: 'handleProfileTokenChange',
69-
profileData: 'handleProfileDataChange'
70-
},
7147
methods: {
7248
createSession,
73-
getProfile,
74-
handleSuccess (
49+
handleSubmitSuccess (
7550
event,
7651
fields
7752
) {
@@ -84,30 +59,27 @@ export default {
8459
8560
this.createSession(
8661
sessionArgs
62+
).then(
63+
this.handleSessionCreateSuccess
8764
)
8865
},
89-
handleProfileIdChange (
90-
value
91-
) {
92-
if (value) {
93-
this.setSessionData()
94-
}
95-
},
96-
handleProfileTokenChange (
97-
value
98-
) {
99-
if (value) {
100-
this.getProfile(
101-
this.profileArgs
102-
)
103-
}
104-
},
105-
handleProfileDataChange (
106-
value
66+
async handleSessionCreateSuccess (
67+
responseData
10768
) {
69+
const profileId =
70+
responseData.profile.id
71+
72+
const profileToken =
73+
responseData.profile.token
74+
75+
const isRememberProfile =
76+
responseData.isRemember
77+
10878
updateGlobalStore(
10979
{
110-
'profile.info': value
80+
'profile.id': profileId,
81+
'profile.token': profileToken,
82+
'profile.isRemember': isRememberProfile
11183
}
11284
)
11385
},
@@ -125,14 +97,6 @@ export default {
12597
password,
12698
isRemember: !!remember
12799
}
128-
},
129-
setSessionData () {
130-
updateGlobalStore(
131-
{
132-
'profile.token': this.token,
133-
'profile.isRemember': this.isRemember
134-
}
135-
)
136100
}
137101
}
138102
}

0 commit comments

Comments
 (0)