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 @@