Skip to content

Commit

Permalink
Settings page is now wrapped into routing
Browse files Browse the repository at this point in the history
- expanding one settings section will push onto the history
- now the extra button is not needed for going back
  • Loading branch information
MarmadileManteater committed Oct 21, 2024
1 parent ee5b1a3 commit 6e028cb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
2 changes: 0 additions & 2 deletions src/renderer/views/Settings/Settings.css
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
inline-size: 100%;
max-inline-size: 100%;
box-sizing: border-box;
padding-inline-end: 4%;
padding-block-end: 1em;
}

.settingsContent {
Expand Down
29 changes: 26 additions & 3 deletions src/renderer/views/Settings/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export default defineComponent({
return {
isInDesktopView: true,
settingsSectionTypeOpenInMobile: null,
unlocked: false
unlocked: false,
currentPath: window.location.hash
}
},
computed: {
Expand Down Expand Up @@ -170,9 +171,11 @@ export default defineComponent({
}
},
mounted: function () {
this.onPopState(undefined, true)
this.handleResize()
window.addEventListener('resize', this.handleResize)
document.addEventListener('scroll', this.markScrolledToSectionAsActive)
window.addEventListener('popstate', this.onPopState)

// mark first section as active before any scrolling has taken place
if (this.settingsSectionComponents.length > 0) {
Expand All @@ -183,9 +186,26 @@ export default defineComponent({
beforeDestroy: function () {
document.removeEventListener('scroll', this.markScrolledToSectionAsActive)
window.removeEventListener('resize', this.handleResize)
window.removeEventListener('popstate', this.popState)
},
methods: {
navigateToSection: function(sectionType) {
onPopState: function (ev, forcedMobile = true) {
this.currentPath = window.location.hash
if (this.currentPath === '#/settings') {
this.returnToSettingsMenu()
} else {
const subPath = this.currentPath.split('#/settings#')[1]
if (subPath !== undefined) {
this.navigateToSection(subPath, forcedMobile)
}
}
},
pushState: function (path) {
if (`#/settings${path}` !== window.location.hash) {
history.pushState({}, null, `#/settings${path}`)
}
},
navigateToSection: function(sectionType, forcedMobile = false) {
if (this.isInDesktopView) {
nextTick(() => {
const sectionElement = this.$refs[sectionType][0].$el
Expand All @@ -196,7 +216,10 @@ export default defineComponent({
sectionHeading.focus()
sectionHeading.tabIndex = -1
})
} else {
}

if ((!this.isInDesktopView) || forcedMobile) {
this.pushState(`#${sectionType}`)
this.settingsSectionTypeOpenInMobile = sectionType
}
},
Expand Down
13 changes: 0 additions & 13 deletions src/renderer/views/Settings/Settings.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
<template>
<div class="settingsPage">
<template v-if="unlocked">
<div
v-show="settingsSectionTypeOpenInMobile != null"
class="returnToMenuMobileIcon"
@click="returnToSettingsMenu"
@keydown.space.enter="returnToSettingsMenu"
>
<font-awesome-icon
:icon="['fas', 'angle-left']"
role="button"
:title="$t('Settings.Return to Settings Menu')"
tabindex="0"
/>
</div>
<ft-settings-menu
v-show="isInDesktopView || settingsSectionTypeOpenInMobile == null"
:settings-sections="settingsSectionComponents"
Expand Down

0 comments on commit 6e028cb

Please sign in to comment.