Skip to content

Commit

Permalink
Insert tags into all datasets when "edit all tags" is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
skiars committed Sep 10, 2023
1 parent 1861029 commit 8d70730
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/components/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {appWindow} from '@tauri-apps/api/window'
import {confirm, message} from '@tauri-apps/api/dialog'
let history: EditorHistory = new EditorHistory
let tagInsPos: number | undefined = undefined
let workDir: string = ''
let editState: Array<any> | undefined = undefined
const dataset = ref<TagData[]>([])
Expand Down Expand Up @@ -94,13 +93,16 @@ function onDeleteTags(d: TagData[], tags: string[]) {
history.edit(deleteTags(d, tags))
}
function onInsertTags(tags: string[]) {
history.edit(insertTags(selectedDataset(), tags, tagInsPos))
function editableDataset(): TagData[] {
return editAllTags.value ? dataset.value : selectedDataset()
}
function onInsertTags({tags, position}: { tags: string[], position?: number }) {
history.edit(insertTags(editableDataset(), tags, position))
}
function onReplaceTags({from, to}: { from: string[], to: string[] }) {
const ds = editAllTags.value ? dataset.value : selectedDataset()
history.edit(replaceTags(ds, from, to))
history.edit(replaceTags(editableDataset(), from, to))
}
function onAddTagFilter(e: string[]) {
Expand Down Expand Up @@ -218,15 +220,14 @@ invoke('load_tags_db', {}).then(() => console.log(`load tags db finished ${Date.
v-on:filter="onAddTagFilter"/>
<tag-editor style="flex-shrink: 0"
v-model:editAllTags="editAllTags"
v-on:updatePosition="x => tagInsPos = x"
v-on:updateTags="onInsertTags"
v-on:insertTags="onInsertTags"
v-on:replaceTags="onReplaceTags"/>
</splitter-panel>
<splitter-panel class="column-flex">
<tag-list style="flex-grow: 1" :tags="allTags"
:editable="editAllTags" nodrag
v-on:delete="e => onDeleteTags(dataset, e)"
v-on:active="onInsertTags"
v-on:active="e => onInsertTags({tags: e})"
v-on:filter="onAddTagFilter"/>
</splitter-panel>
</splitter>
Expand Down
10 changes: 4 additions & 6 deletions src/components/TagEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ const props = defineProps<{
}>()
const emit = defineEmits<{
(e: 'updateTags', value: string[]): void
(e: 'updatePosition', value: number | undefined): void
(e: 'insertTags', value: { tags: string[], position?: number }): void
(e: 'update:editAllTags', value: boolean): void,
(e: 'replaceTags', value: {from: string[], to: string[]}): void
(e: 'replaceTags', value: { from: string[], to: string[] }): void
}>()
const position = ref<number>()
const position = ref<number | undefined>()
const tags = ref<string[]>([])
const replaceTags = ref<string[]>([])
const more = ref<boolean>()
Expand All @@ -39,9 +38,8 @@ const editAllTags = computed<boolean>({
<tag-input v-model="tags" placeholder="Separate tags with ',' or press Enter"/>
<span>position</span>
<input-number v-model="position" placeholder="auto"
v-on:update:modelValue="emit('updatePosition', $event)"
:inputStyle="{ padding: '0.25em', width: '4em' }"/>
<Button class="fixed" rounded v-on:click="emit('updateTags', tags)">
<Button class="fixed" rounded v-on:click="emit('insertTags', {tags, position})">
Insert
</Button>
<span>edit all tags</span>
Expand Down

0 comments on commit 8d70730

Please sign in to comment.