Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): save splitpanes size to local storage #5166

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions packages/ui/client/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,32 @@ import { Pane, Splitpanes } from 'splitpanes'
import { coverageUrl, coverageVisible, initializeNavigation } from '../composables/navigation'

const dashboardVisible = initializeNavigation()
const mainSizes = reactive([33, 67])
const detailSizes = reactive([33, 67])
const mainSizes = useLocalStorage<[left: number, right: number]>('vitest-ui_splitpanes-mainSizes', [33, 67], {
initOnMounted: true,
})
const detailSizes = useLocalStorage<[left: number, right: number]>('vitest-ui_splitpanes-detailSizes', [33, 67], {
initOnMounted: true,
})

const onMainResized = useDebounceFn((event: { size: number }[]) => {
event.forEach((e, i) => {
mainSizes[i] = e.size
mainSizes.value[i] = e.size
})
}, 0)
const onModuleResized = useDebounceFn((event: { size: number }[]) => {
event.forEach((e, i) => {
detailSizes[i] = e.size
detailSizes.value[i] = e.size
})
}, 0)

function resizeMain() {
const width = window.innerWidth
const panelWidth = Math.min(width / 3, 300)
mainSizes[0] = (100 * panelWidth) / width
mainSizes[1] = 100 - mainSizes[0]
mainSizes.value[0] = (100 * panelWidth) / width
mainSizes.value[1] = 100 - mainSizes.value[0]
// initialize suite width with the same navigation panel width in pixels (adjust its % inside detail's split pane)
detailSizes[0] = (100 * panelWidth) / (width - panelWidth)
detailSizes[1] = 100 - detailSizes[0]
detailSizes.value[0] = (100 * panelWidth) / (width - panelWidth)
detailSizes.value[1] = 100 - detailSizes.value[0]
}
</script>

Expand Down