-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added update and delete tags functionality
- Loading branch information
1 parent
0a1b74e
commit 9c2eea9
Showing
4 changed files
with
146 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<template> | ||
<q-page class="flex flex-center"> | ||
<q-card v-if="isEditing" flat bordered class="my-card"> | ||
<q-card-section class="row items-center q-pb-none q-mb-md" vertical> | ||
<div class="text-h6">Edit: {{ tag.name }}</div> | ||
</q-card-section> | ||
|
||
<q-card-section> | ||
<q-form @submit.prevent="handleSubmit"> | ||
<q-input filled v-model="tag.name" label="Tag Name" required lazy-rules | ||
:rules="[val => val && val.length > 0 || 'Tag Name is required']" /> | ||
|
||
|
||
<q-page-sticky position="bottom-right" :offset="[18, 18]"> | ||
<q-btn type="submit" fab icon="done" color="primary"> | ||
</q-btn> | ||
</q-page-sticky> | ||
</q-form> | ||
</q-card-section> | ||
|
||
<q-page-sticky position="bottom-left" :offset="[18, 18]"> | ||
<q-btn @click="isEditing = false" fab icon="undo" color="negative"> | ||
</q-btn> | ||
</q-page-sticky> | ||
</q-card> | ||
|
||
|
||
<q-card v-else class="my-card q-mt-md" flat bordered> | ||
<q-card-section> | ||
<div class="row items-center no-wrap"> | ||
<div class="col"> | ||
<div class="text-h6">{{ tag.name }}</div> | ||
</div> | ||
</div> | ||
</q-card-section> | ||
|
||
|
||
<q-card-actions> | ||
<q-btn color="primary" type="button" size="sm" @click="isEditing = true">Edit</q-btn> | ||
<q-btn color="negative" type="button" size="sm" @click="confirm">Delete</q-btn> | ||
</q-card-actions> | ||
</q-card> | ||
|
||
<q-page-sticky position="bottom-left" :offset="[18, 18]"> | ||
<q-btn :to="{ 'name': 'tags' }" fab icon="undo" color="negative"> | ||
</q-btn> | ||
</q-page-sticky> | ||
</q-page> | ||
</template> | ||
|
||
<script setup> | ||
import { ref } from 'vue'; | ||
import { useRoute, useRouter } from 'vue-router'; | ||
import { Dialog, date, Notify } from 'quasar'; | ||
import { useNotesStore } from '../stores/notes.js'; | ||
const notesStore = useNotesStore(); | ||
const route = useRoute(); | ||
const router = useRouter(); | ||
const isEditing = ref(false); | ||
const tag = ref({ | ||
id: '', | ||
name: '' | ||
}); | ||
tag.value = notesStore.getTagById(route.params.id); | ||
function handleSubmit() { | ||
try { | ||
notesStore.updateTag(route.params.id, tag.value); | ||
isEditing = false; | ||
Notify.create({ | ||
message: 'Tag Updated Successfully', | ||
type: "positive", | ||
actions: [ | ||
{ icon: 'close', color: 'white', round: true, } | ||
] | ||
}) | ||
} catch (error) { | ||
Notify.create({ | ||
message: error.message, | ||
type: "negative", | ||
actions: [ | ||
{ icon: 'close', color: 'white', round: true, } | ||
] | ||
}) | ||
} | ||
}; | ||
function confirm(id) { | ||
Dialog.create({ | ||
dark: true, | ||
title: 'Confirm', | ||
color: 'primary', | ||
message: 'Delete this tag?, Your Notes that has this tag will not be deleted', | ||
cancel: true, | ||
persistent: true | ||
}).onOk(() => { | ||
try { | ||
notesStore.deleteTag(id) | ||
router.push('/tags'); | ||
Notify.create({ | ||
message: 'Tag Deleted Successfully', | ||
type: "positive", | ||
actions: [ | ||
{ icon: 'close', color: 'white', round: true, } | ||
] | ||
}) | ||
} catch (error) { | ||
Notify.create({ | ||
message: error.message, | ||
type: "negative", | ||
actions: [ | ||
{ icon: 'close', color: 'white', round: true, } | ||
] | ||
}) | ||
} | ||
}) | ||
}; | ||
</script> | ||
|
||
|
||
<style lang="sass" scoped> | ||
.my-card | ||
width: 100% | ||
width: 350px | ||
</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