-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add custom scroll, restore snippet position during init (#10)
- Loading branch information
1 parent
e8f4bce
commit 889624f
Showing
12 changed files
with
767 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,77 @@ | ||
<template> | ||
<div class="list"> | ||
<div | ||
ref="listRef" | ||
class="snippet-list" | ||
> | ||
<div class="header"> | ||
<SnippetListHeader /> | ||
</div> | ||
<div class="body"> | ||
<SnippetListItem | ||
v-for="(i, index) in snippetStore.snippets" | ||
:id="i.id" | ||
:key="i.id" | ||
:index="index" | ||
:folder="i.folder?.name" | ||
:date="i.updatedAt" | ||
:name="i.name" | ||
/> | ||
<div | ||
ref="listRef" | ||
class="body" | ||
> | ||
<PerfectScrollbar> | ||
<SnippetListItem | ||
v-for="(i, index) in snippetStore.snippets" | ||
:id="i.id" | ||
:key="i.id" | ||
:data-id="i.id" | ||
:index="index" | ||
:folder="i.folder?.name" | ||
:date="i.updatedAt" | ||
:name="i.name" | ||
/> | ||
</PerfectScrollbar> | ||
</div> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { emitter } from '@/composable' | ||
import { useAppStore } from '@/store/app' | ||
import { useSnippetStore } from '@/store/snippets' | ||
import { ref, watch } from 'vue' | ||
const snippetStore = useSnippetStore() | ||
const appStore = useAppStore() | ||
const listRef = ref<HTMLElement>() | ||
const setScrollPosition = (offset: number) => { | ||
const ps = listRef.value?.querySelector<HTMLElement>('.ps') | ||
ps!.scrollTop = offset | ||
} | ||
watch( | ||
() => appStore.isInit, | ||
() => { | ||
const el = document.querySelector<HTMLElement>( | ||
`[data-id='${snippetStore.selectedId!}']` | ||
) | ||
if (el?.offsetTop) setScrollPosition(el.offsetTop) | ||
} | ||
) | ||
emitter.on('folder:click', () => { | ||
setScrollPosition(0) | ||
}) | ||
</script> | ||
<style lang="scss" scoped> | ||
.list { | ||
.snippet-list { | ||
border-right: 1px solid var(--color-border); | ||
display: grid; | ||
grid-template-rows: 50px 1fr; | ||
grid-template-rows: 50px 1fr 10px; | ||
} | ||
.header { | ||
padding-top: var(--title-bar-height); | ||
display: flex; | ||
border-bottom: 1px solid var(--color-border); | ||
} | ||
.body { | ||
overflow-y: scroll; | ||
padding: var(--spacing-xs) 0; | ||
height: calc(100vh - 50px); | ||
:deep(.ps) { | ||
height: calc(100vh - 60px); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export type EmitterEvents = { | ||
'focus:snippet-name': boolean | ||
'folder:click': any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ export interface State { | |
theme: string | ||
sizes: AppSizes | ||
showTags: boolean | ||
isInit: boolean | ||
} |
Oops, something went wrong.