Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore(systemtags): Use files systemtags service
Signed-off-by: Christopher Ng <[email protected]>
  • Loading branch information
Pytal committed Nov 16, 2023
commit 0983ce19b1920207cca5ef25b59ac3e96da0f557
39 changes: 17 additions & 22 deletions apps/systemtags/src/components/SystemTags.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,16 @@ import NcSelectTags from '@nextcloud/vue/dist/Components/NcSelectTags.js'
import { translate as t } from '@nextcloud/l10n'
import { showError } from '@nextcloud/dialogs'

import { defaultBaseTag } from '../utils.js'
import { fetchLastUsedTagIds, fetchTags } from '../services/api.js'
import {
createTag,
deleteTag,
fetchLastUsedTagIds,
fetchSelectedTags,
fetchTags,
selectTag,
} from '../services/api.js'

import type { BaseTag, Tag, TagWithId } from '../types.js'

const defaultBaseTag: BaseTag = {
userVisible: true,
userAssignable: true,
canAssign: true,
}
createTagForFile,
deleteTagForFile,
fetchTagsForFile,
setTagForFile,
} from '../services/files.js'

import type { Tag, TagWithId } from '../types.js'

export default Vue.extend({
name: 'SystemTags',
Expand Down Expand Up @@ -133,7 +127,7 @@ export default Vue.extend({
async handler() {
this.loadingTags = true
try {
this.selectedTags = await fetchSelectedTags(this.fileId)
this.selectedTags = await fetchTagsForFile(this.fileId)
this.$emit('has-tags', this.selectedTags.length > 0)
} catch (error) {
showError(t('systemtags', 'Failed to load selected tags'))
Expand Down Expand Up @@ -175,14 +169,15 @@ export default Vue.extend({
},

async handleSelect(tags: Tag[]) {
const selectedTag = tags[tags.length - 1]
if (!selectedTag.id) {
const lastTag = tags[tags.length - 1]
if (!lastTag.id) {
// Ignore created tags handled by `handleCreate()`
return
}
const selectedTag = lastTag as TagWithId
this.loading = true
try {
await selectTag(this.fileId, selectedTag)
await setTagForFile(selectedTag, this.fileId)
const sortToFront = (a: TagWithId, b: TagWithId) => {
if (a.id === selectedTag.id) {
return -1
Expand All @@ -201,7 +196,7 @@ export default Vue.extend({
async handleCreate(tag: Tag) {
this.loading = true
try {
const id = await createTag(this.fileId, tag)
const id = await createTagForFile(tag, this.fileId)
const createdTag = { ...tag, id }
this.sortedTags.unshift(createdTag)
this.selectedTags.push(createdTag)
Expand All @@ -211,10 +206,10 @@ export default Vue.extend({
this.loading = false
},

async handleDeselect(tag: Tag) {
async handleDeselect(tag: TagWithId) {
this.loading = true
try {
await deleteTag(this.fileId, tag)
await deleteTagForFile(tag, this.fileId)
} catch (error) {
showError(t('systemtags', 'Failed to delete tag'))
}
Expand Down