Skip to content

Commit e2c5532

Browse files
committed
feature: "Save activity history" option
1 parent c26a7b9 commit e2c5532

File tree

10 files changed

+118
-23
lines changed

10 files changed

+118
-23
lines changed

electron/plugins/electronStore/schema.js

+4
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ export default {
208208
type: 'boolean',
209209
default: true
210210
},
211+
'history.isSaveActivity': {
212+
type: 'boolean',
213+
default: true
214+
},
211215
'homePage.isWithRecentTracksSegment': {
212216
type: 'boolean',
213217
default: true

src/components/BaseCheckbox.vue

-17
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
</template>
2929

3030
<script>
31-
import {
32-
toggle as toggleCheckbox
33-
} from '@/helpers/actions/plugins/semantic/checkbox'
3431
import checkboxMixin from '@/mixins/checkboxMixin'
3532
3633
export default {
@@ -43,30 +40,16 @@ export default {
4340
text: String
4441
},
4542
emits: [
46-
'click',
4743
'isCheckedChange'
4844
],
4945
methods: {
50-
handleClick (
51-
event
52-
) {
53-
this.$emit(
54-
'click',
55-
event
56-
)
57-
},
5846
change (
5947
value
6048
) {
6149
this.$emit(
6250
'isCheckedChange',
6351
value
6452
)
65-
},
66-
toggle () {
67-
toggleCheckbox(
68-
this.$refs.checkbox
69-
)
7053
}
7154
}
7255
}

src/components/layout/modals/TheSettingsModal/AppSettings/HistoryOptions/ActivitySection.vue

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
/>
66

77
<div>
8+
<SaveOption />
9+
810
<BaseSettingsHistoryDeleteOption
911
:scope="scope"
1012
/>
@@ -16,12 +18,14 @@
1618
import BaseDivider from '@/components/BaseDivider.vue'
1719
import BaseSettingsHistoryDeleteOption
1820
from '@/components/settings/BaseSettingsHistoryDeleteOption.vue'
21+
import SaveOption from './ActivitySection/SaveOption.vue'
1922
2023
export default {
2124
name: 'ActivitySection',
2225
components: {
2326
BaseDivider,
24-
BaseSettingsHistoryDeleteOption
27+
BaseSettingsHistoryDeleteOption,
28+
SaveOption
2529
},
2630
data () {
2731
return {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<template>
2+
<div class="main-settings-option-container">
3+
<div class="main-settings-option">
4+
<BaseSettingsOptionHeader
5+
:text="optionText"
6+
/>
7+
8+
<BaseToggle
9+
ref="toggle"
10+
store-key="history.isSaveActivity"
11+
:is-checked="isSaveActivityHistory"
12+
@click="handleToggleClick"
13+
/>
14+
</div>
15+
</div>
16+
</template>
17+
18+
<script>
19+
import {
20+
mapState
21+
} from 'pinia'
22+
import historyStore from '@/stores/history'
23+
import BaseSettingsOptionHeader
24+
from '@/components/headers/settings/BaseSettingsOptionHeader.vue'
25+
import BaseToggle from '@/components/toggles/BaseToggle.vue'
26+
import updateProfile from '@/helpers/actions/api/profile/update'
27+
28+
export default {
29+
name: 'SaveOption',
30+
components: {
31+
BaseSettingsOptionHeader,
32+
BaseToggle
33+
},
34+
computed: {
35+
...mapState(
36+
historyStore,
37+
{
38+
isSaveActivityHistory: 'isSaveActivity'
39+
}
40+
),
41+
optionText () {
42+
return this.$t(
43+
'settings.options.app.history.activity.save'
44+
)
45+
},
46+
profileArgs () {
47+
return {
48+
isSaveActivityHistory:
49+
!this.isSaveActivityHistory
50+
}
51+
}
52+
},
53+
methods: {
54+
handleToggleClick () {
55+
updateProfile(
56+
this.profileArgs
57+
).catch(
58+
this.handleProfileUpdateError
59+
)
60+
},
61+
handleProfileUpdateError () {
62+
this.toggleToggle()
63+
},
64+
toggleToggle () {
65+
this.$refs
66+
.toggle
67+
.toggle()
68+
}
69+
}
70+
}
71+
</script>
72+
73+
<style lang="sass" scoped></style>

src/components/toggles/BaseToggle.vue

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:class="{
66
inverted: isDarkMode
77
}"
8+
@click="handleClick"
89
>
910
<input type="checkbox">
1011
</div>

src/helpers/actions/api/profile/update.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export default function (
1616
country,
1717
city,
1818
status,
19-
isPrivate
19+
isPrivate,
20+
isSaveActivityHistory
2021
}
2122
) {
2223
const profileId = profileStore().id
@@ -41,6 +42,9 @@ export default function (
4142
status,
4243
private: (
4344
isPrivate ? 1 : 0
45+
),
46+
save_activity_history: (
47+
isSaveActivityHistory ? 1 : 0
4448
)
4549
}
4650

src/helpers/actions/form.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export function handleError (
1212
error
1313
}
1414
) {
15+
const form = this?.$refs?.form?.$el
16+
17+
if (!form) { return }
18+
1519
const isForbidden = (
1620
error
1721
.response
@@ -24,8 +28,6 @@ export function handleError (
2428
?.status === 404
2529
)
2630

27-
const form = this.$refs.form.$el
28-
2931
if (isForbidden) {
3032
addErrors(
3133
{

src/mixins/checkboxMixin.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
2-
set as setCheckbox
2+
set as setCheckbox,
3+
toggle as toggleCheckbox
34
} from '@/helpers/actions/plugins/semantic/checkbox'
45
import {
56
main as mainCheckboxOptions
@@ -9,6 +10,9 @@ export default {
910
props: {
1011
isChecked: Boolean
1112
},
13+
emits: [
14+
'click'
15+
],
1216
computed: {
1317
checkboxOptions () {
1418
return mainCheckboxOptions(
@@ -28,6 +32,14 @@ export default {
2832
)
2933
},
3034
methods: {
35+
handleClick (
36+
event
37+
) {
38+
this.$emit(
39+
'click',
40+
event
41+
)
42+
},
3143
handleChecked () {
3244
this.change(
3345
true
@@ -37,6 +49,11 @@ export default {
3749
this.change(
3850
false
3951
)
52+
},
53+
toggle () {
54+
toggleCheckbox(
55+
this.$refs.checkbox
56+
)
4057
}
4158
}
4259
}

src/plugins/i18n/locales/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@
580580
"delete": "Delete search history"
581581
},
582582
"activity": {
583+
"save": "Save activity history",
583584
"delete": "Delete activity history"
584585
},
585586
"player": {

src/stores/history.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const data = {
99
savedTracksSearch: null,
1010
search: null,
1111
isSaveBrowser: null,
12-
isSavePlayer: null
12+
isSavePlayer: null,
13+
isSaveActivity: null
1314
}
1415
},
1516
actions: {
@@ -37,6 +38,11 @@ const data = {
3738
value
3839
) {
3940
this.isSavePlayer = value
41+
},
42+
setIsSaveActivity (
43+
value
44+
) {
45+
this.isSaveActivity = value
4046
}
4147
}
4248
}

0 commit comments

Comments
 (0)