From 071e3c7b885e44d9fd1a88da3439ef0485b5e2c7 Mon Sep 17 00:00:00 2001 From: BFlorian91 Date: Thu, 23 Nov 2023 01:12:43 +0100 Subject: [PATCH] feat: add useDeleteSnippet and fix error with type of tags in the CardSnippet --- src/assets/icons/CrossIcon.vue | 16 ++++++++++++++++ src/assets/icons/TrashIcon.vue | 16 ++++++++++++++++ src/components/CardSnippet.vue | 16 +++++++++++++--- src/composables/useDeleteSnippet.ts | 29 +++++++++++++++++++++++++++++ src/views/EditSnippetView.vue | 13 ++++++++++++- src/views/HomeView.vue | 6 +++--- src/views/ShowSnippetView.vue | 19 +++++++++++++++++-- tailwind.config.js | 2 +- 8 files changed, 107 insertions(+), 10 deletions(-) create mode 100644 src/assets/icons/CrossIcon.vue create mode 100644 src/assets/icons/TrashIcon.vue create mode 100644 src/composables/useDeleteSnippet.ts diff --git a/src/assets/icons/CrossIcon.vue b/src/assets/icons/CrossIcon.vue new file mode 100644 index 0000000..0b22727 --- /dev/null +++ b/src/assets/icons/CrossIcon.vue @@ -0,0 +1,16 @@ + diff --git a/src/assets/icons/TrashIcon.vue b/src/assets/icons/TrashIcon.vue new file mode 100644 index 0000000..f4e4f94 --- /dev/null +++ b/src/assets/icons/TrashIcon.vue @@ -0,0 +1,16 @@ + diff --git a/src/components/CardSnippet.vue b/src/components/CardSnippet.vue index 7e7604c..eccbe83 100644 --- a/src/components/CardSnippet.vue +++ b/src/components/CardSnippet.vue @@ -21,12 +21,16 @@ defineProps({ type: String, default: "", }, - tag: { - type: Array, + tags: { + type: String, default: "", }, }); +const splitTags = (tags: string) => { + return tags.split(","); +}; + onMounted(() => { Prism.highlightAll(); }); @@ -49,7 +53,13 @@ onMounted(() => {

- {{ tag }} + + {{ tag }} +

(null); + const isDeleting = ref(false); + + const deleteSnippet = async (snippetId: string): Promise => { + try { + isDeleting.value = true; + const snippetDocRef = doc(db, "snippets", snippetId); + await deleteDoc(snippetDocRef); + console.log("Snippet deleted successfully."); + error.value = null; + } catch (e) { + error.value = + e instanceof Error ? e.message : "Could not delete the snippet."; + } finally { + isDeleting.value = false; + } + }; + + return { + error, + isDeleting, + deleteSnippet, + }; +} diff --git a/src/views/EditSnippetView.vue b/src/views/EditSnippetView.vue index b528476..dd7d3d3 100644 --- a/src/views/EditSnippetView.vue +++ b/src/views/EditSnippetView.vue @@ -5,6 +5,7 @@ import InputForRichText from "../components/InputForRichText.vue"; import { useAuthStore } from "../store/authStore"; import { useUpdateSnippet } from "../composables/useUpdateSnippet"; import { useGetSnippets } from "../composables/useGetSnippets"; +import CrossIcon from "../assets/icons/CrossIcon.vue"; import { useRouter } from "vue-router"; const authStore = useAuthStore(); @@ -45,6 +46,10 @@ const handleSubmit = (event: Event) => { router.push(`/snippet/${id}`); }; +const pushBack = () => { + router.push(`/snippet/${id}`); +}; + onMounted(async () => { if (!authStore.isLoggedIn) { router.push("/login"); @@ -60,8 +65,14 @@ onMounted(async () => { >
+

{ - fetchSnippets(); +onMounted(async () => { + await fetchSnippets(); }); @@ -36,7 +36,7 @@ onMounted(() => { :code="snippet.code" :title="snippet.title" :description="snippet.description" - :tag="snippet.tags" + :tags="snippet.tags" />

diff --git a/src/views/ShowSnippetView.vue b/src/views/ShowSnippetView.vue index d13abad..b5fefbd 100644 --- a/src/views/ShowSnippetView.vue +++ b/src/views/ShowSnippetView.vue @@ -1,10 +1,12 @@