Skip to content

Commit

Permalink
Merge pull request #3 from sanwu-maizi/feature/tjy/deleteBotton
Browse files Browse the repository at this point in the history
Feature/tjy/delete botton
  • Loading branch information
happice0746 authored Oct 8, 2024
2 parents 7592605 + 9d03b31 commit 1e2b409
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
35 changes: 34 additions & 1 deletion src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,45 @@ body {
.update {
background: -webkit-linear-gradient(60deg, var(--color-primary), limegreen);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-size: 200% auto;
animation: shine 3s ease infinite;
}
#app {
height: 100vh;
overflow: hidden;
}
.app {
&-title-bar {
position: absolute;
top: 0;
width: 100%;
height: var(--title-bar-height);
user-select: none;
-webkit-app-region: drag;
z-index: 1010;
transition: all 0.5s;
&.is-win {
border-top: 1px solid var(--color-border);
}
}
}
.top-notification {
position: absolute;
top: 5px;
right: var(--spacing-sm);
z-index: 1020;
text-transform: uppercase;
font-size: 10px;
font-weight: bold;
display: flex;
gap: var(--spacing-sm);
}
@keyframes shine {
from {
background-position: 200%;
Expand Down
1 change: 1 addition & 0 deletions src/renderer/components/sidebar/TheSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
>
<template #action>
<AppActionButton v-tooltip="i18n.t('newFolder')">
<UniconsTrash @click="onAddNewFolder" />
<UniconsPlus @click="onAddNewFolder" />
</AppActionButton>
</template>
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/components/snippets/SnippetListHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
v-model="query"
:placeholder="`${i18n.t('search')}...`"
>
<AppActionButton
v-if="!query"
v-tooltip="i18n.t('deleteAllSnippets')"
class="item"
@click="onDeleteAllSnippets"
>
<UniconsTrash />
</AppActionButton>
<AppActionButton
v-if="!query"
v-tooltip="i18n.t('newSnippet')"
Expand All @@ -25,7 +33,7 @@
</template>

<script setup lang="ts">
import { emitter, onAddNewSnippet } from '@/composable'
import { emitter, onAddNewSnippet, onDeleteAllSnippets } from '@/composable'
import { useSnippetStore } from '@/store/snippets'
import { useDebounceFn } from '@vueuse/core'
import { computed, onUnmounted, ref } from 'vue'
Expand Down
36 changes: 35 additions & 1 deletion src/renderer/composable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ export const useApi = createFetch({

export const emitter = mitt<EmitterEvents>()

export const onDeleteAllSnippets = () => {
const snippetStore = useSnippetStore()
const folderStore = useFolderStore()
snippetStore.deleteAllSnippets()
folderStore.deleteFolders()
}
export const onAddNewSnippet = async () => {
const folderStore = useFolderStore()
const snippetStore = useSnippetStore()

console.log(111)
console.log(snippetStore.all)
snippetStore.fragment = 0
snippetStore.isMarkdownPreview = false

Expand All @@ -34,7 +41,24 @@ export const onAddNewSnippet = async () => {
emitter.emit('snippet:focus-name', true)
track('snippets/add-new')
}
export const onNewSnippet = async () => {
const folderStore = useFolderStore()
const snippetStore = useSnippetStore()

snippetStore.fragment = 0
snippetStore.isMarkdownPreview = false

await snippetStore.addNewSnippet()

if (folderStore.selectedId) {
await snippetStore.getSnippetsByFolderIds(folderStore.selectedIds!)
} else {
snippetStore.setSnippetsByAlias('inbox')
}

emitter.emit('snippet:focus-name', true)
track('snippets/add-new')
}
export const onCreateSnippet = async (body: Partial<Snippet>) => {
const snippetStore = useSnippetStore()

Expand Down Expand Up @@ -68,6 +92,16 @@ export const onAddDescription = async () => {
track('snippets/add-description')
}

export const onAddFolder = async () => {
const folderStore = useFolderStore()
const snippetStore = useSnippetStore()

const folder = await folderStore.addNewFolder()
snippetStore.selected = undefined

emitter.emit('scroll-to:folder', folder.id)
track('folders/add-new')
}
export const onAddNewFolder = async () => {
const folderStore = useFolderStore()
const snippetStore = useSnippetStore()
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/store/folders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const useFolderStore = defineStore('folders', {
},

actions: {
deleteFolders () {
this.folders = []
this.foldersTree = []
},
async getFolders () {
const { data } = await useApi<Folder[]>('/folders').get().json()
this.folders = data.value
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ export const useSnippetStore = defineStore('snippets', {

sortSnippetsBy(this.snippets, this.sort)
},
deleteAllSnippets () {
this.snippets = []
this.all = []
},
togglePreview (type: PreviewType) {
switch (type) {
case 'markdown':
Expand Down

0 comments on commit 1e2b409

Please sign in to comment.