Skip to content

Commit

Permalink
fix(ui): Settings > Option to disable tabs (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
flawiddsouza committed Oct 11, 2024
1 parent 763a4b5 commit a41ee9c
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
9 changes: 9 additions & 0 deletions packages/ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ export default {
const savedElectronSwitchToChromiumFetch = localStorage.getItem(constants.LOCAL_STORAGE_KEY.ELECTRON_SWITCH_TO_CHROMIUM_FETCH)
const savedDisableIframeSandbox = localStorage.getItem(constants.LOCAL_STORAGE_KEY.DISABLE_IFRAME_SANDBOX)
const savedDisableAutoUpdate = localStorage.getItem(constants.LOCAL_STORAGE_KEY.DISABLE_AUTO_UPDATE)
const savedShowTabs = localStorage.getItem(constants.LOCAL_STORAGE_KEY.SHOW_TABS)
if(savedTheme) {
this.$store.state.theme = savedTheme
Expand Down Expand Up @@ -403,6 +404,14 @@ export default {
}
}
if(savedShowTabs) {
try {
this.$store.state.flags.showTabs = JSON.parse(savedShowTabs)
} catch(e) {
this.$store.state.flags.showTabs = true
}
}
emitter.on('error', this.handleError)
if(import.meta.env.MODE === 'desktop-electron') {
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/components/Frame.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import ImportModal from '@/components/ImportModal.vue'
import { computed, onMounted, onBeforeUnmount, ref } from 'vue'
import { useStore } from 'vuex'
import constants from '../constants'
import { getSettingsConfig } from '@/helpers'
const store = useStore()
const activeTab = computed(() => store.state.activeTab)
const showTabs = computed(() => getSettingsConfig().showTabs)
const showTabs = computed(() => store.state.flags.showTabs)
const requestResponseLayoutTopBottom = computed(() => store.state.requestResponseLayout === 'top-bottom')
const detachedTabs = computed({
get() {
Expand Down
31 changes: 25 additions & 6 deletions packages/ui/src/components/modals/SettingsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
</div>
<div>
<label style="padding-top: 1rem; display: flex;">
<input type="checkbox" v-model="showTabs"> <div style="margin-left: 0.5rem;">Tab view</div> <div style="margin-left: 0.5rem;"></div>
<input type="checkbox" v-model="showTabs"> <div style="margin-left: 0.5rem;">Show Tabs</div> <div style="margin-left: 0.5rem;"></div>
</label>
<div style="margin-left: 1.3rem; margin-top: 0.3rem;">Un-ticking this will not show tabs when clicking on either request or folder. Please refresh the app or click <button type="button" class="button" @click="refreshPage()">Refresh</button> for the changes to take effect.</div>
<div style="margin-left: 1.3rem; margin-top: 0.3rem;">Un-ticking this will not show tabs when clicking on either request or folder.</div>
</div>
<template v-if="flags.isElectron || flags.isWebStandalone">
<div style="padding-top: 1rem"></div>
Expand Down Expand Up @@ -102,7 +102,7 @@
<script>
import Modal from '@/components/Modal.vue'
import constants from '../../constants'
import { getVersion, refreshPage } from '@/helpers'
import { getVersion } from '@/helpers'
export default {
props: {
Expand Down Expand Up @@ -176,10 +176,10 @@ export default {
},
showTabs() {
localStorage.setItem(constants.LOCAL_STORAGE_KEY.SHOW_TABS, this.showTabs)
}
this.$store.state.flags.showTabs = this.showTabs
},
},
methods: {
refreshPage,
getVersion,
resetWidths() {
localStorage.removeItem(constants.LOCAL_STORAGE_KEY.SIDEBAR_WIDTH)
Expand Down Expand Up @@ -208,6 +208,14 @@ export default {
localStorage.removeItem(constants.LOCAL_STORAGE_KEY.GLOBAL_USER_AGENT)
this.globalUserAgent = ''
},
resetIndentSize() {
localStorage.removeItem(constants.LOCAL_STORAGE_KEY.INDENT_SIZE)
this.indentSize = constants.EDITOR_CONFIG.indent_size
},
resetShowTabs() {
localStorage.removeItem(constants.LOCAL_STORAGE_KEY.SHOW_TABS)
this.showTabs = true
},
resetSettings(target = null) {
if(target) {
if(target === 'widths') {
Expand All @@ -227,6 +235,8 @@ export default {
this.resetDisableIframeSandbox()
this.resetDisableAutoUpdate()
this.resetGlobalUserAgent()
this.resetIndentSize()
this.resetShowTabs()
document.location.reload()
},
Expand Down Expand Up @@ -278,28 +288,37 @@ export default {
this.electronSwitchToChromiumFetch = false
}
}
if(savedDisableIframeSandbox) {
try {
this.disableIframeSandbox = JSON.parse(savedDisableIframeSandbox)
} catch (e) {
this.disableIframeSandbox = false
}
}
if(savedDisableAutoUpdate) {
try {
this.disableAutoUpdate = JSON.parse(savedDisableAutoUpdate)
} catch (e) {
this.disableAutoUpdate = false
}
}
if(savedGlobalUserAgent) {
this.globalUserAgent = savedGlobalUserAgent
}
if(savedIndentSize) {
this.indentSize = savedIndentSize
}
if(savedShowTabs) {
this.showTabs = savedShowTabs
try {
this.showTabs = JSON.parse(savedShowTabs)
} catch (e) {
this.showTabs = true
}
}
},
getCurrentUserAgent() {
Expand Down
3 changes: 0 additions & 3 deletions packages/ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,6 @@ export default {
EDITOR_CONFIG: {
indent_size: '4',
},
APP_CONFIG: {
show_tabs: true,
},
GRANT_TYPES: {
'password_credentials': 'password',
'client_credentials': 'client_credentials',
Expand Down
4 changes: 0 additions & 4 deletions packages/ui/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,3 @@ export interface OpenApiSpecPathParams {
export interface EditorConfig {
indentSize: number
}

export interface AppConfig {
showTabs: boolean
}
11 changes: 0 additions & 11 deletions packages/ui/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
State,
OpenApiSpecPathParams,
EditorConfig,
AppConfig,
} from './global'
import { ActionContext } from 'vuex'
import { version } from '../../electron/package.json'
Expand Down Expand Up @@ -1845,13 +1844,3 @@ export function getSpaces(value: string | number): string {
export function deepClone(obj: any) {
return JSON.parse(JSON.stringify(obj))
}

export function getSettingsConfig(): AppConfig {
return {
showTabs: localStorage.getItem(constants.LOCAL_STORAGE_KEY.SHOW_TABS) ? (localStorage.getItem(constants.LOCAL_STORAGE_KEY.SHOW_TABS) === 'true') : constants.APP_CONFIG.show_tabs
}
}

export function refreshPage(): void {
location.reload()
}
1 change: 1 addition & 0 deletions packages/ui/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export const store = createStore<State>({
electronSwitchToChromiumFetch: false,
disableIframeSandbox : false,
disableAutoUpdate : false,
showTabs: true,
},
openContextMenuElement: null,
sockets: {},
Expand Down

0 comments on commit a41ee9c

Please sign in to comment.