Skip to content

Commit

Permalink
Merge pull request #14 from BFlorian91/dev
Browse files Browse the repository at this point in the history
Feat: add remove instant from the dom without fetch, and authorId in …
  • Loading branch information
FlorianBx authored Dec 16, 2023
2 parents b68f42d + dd01a90 commit 59bea4d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
11 changes: 10 additions & 1 deletion src/components/CardSnippet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const props = defineProps({
type: String,
default: "",
},
onDelete: {
type: Function,
default: () => {},
},
});
const authorId = "Florian";
Expand All @@ -62,6 +66,11 @@ const handleEdit = (id: string) => {
const { elapsedTime } = useElapsedTime(props.updatedAt);
const handleDelete = async () => {
await deleteSnippet(props.id);
props.onDelete(props.id);
};
onMounted(async () => {
await nextTick();
Prism.highlightAll();
Expand Down Expand Up @@ -204,7 +213,7 @@ watch(readMore, async (newValue) => {
<p class="text-sm">Updated {{ elapsedTime }}</p>
</div>
<div class="flex items-center gap-4">
<button class="text-danger opacity-100" @click="deleteSnippet(id)">
<button class="text-danger opacity-100" @click="handleDelete">
<TrashIcon />
</button>
<button class="text-secondary opacity-60" @click="handleEdit(id)">
Expand Down
3 changes: 2 additions & 1 deletion src/views/EditSnippetView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ const fillSnippetData = () => {
const { updateSnippet } = useUpdateSnippet();
const handleSubmit = (event: Event) => {
const handleSubmit = async (event: Event) => {
event.preventDefault();
updateSnippet(snippetData);
router.push(`/snippet/${id}`);
await fetchSnippetById(id.toString());
};
const pushBack = () => {
Expand Down
7 changes: 7 additions & 0 deletions src/views/HomeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const { snippets, fetchSnippets, isLoading, error } = useGetSnippets();
const { filteredSnippets } = useFilter(snippets);
console.log(auth.currentUser);
const handleSnippetDelete = (deletedSnippetId: string) => {
snippets.value = snippets.value.filter(
(snippet) => snippet.id !== deletedSnippetId,
);
};
onMounted(async () => {
await fetchSnippets();
});
Expand Down Expand Up @@ -38,6 +44,7 @@ onMounted(async () => {
:language="snippet.language.toLocaleLowerCase()"
:created-at="snippet.createdAt"
:updated-at="snippet.updatedAt"
:onDelete="handleSnippetDelete"
/>
</div>
</div>
Expand Down
7 changes: 4 additions & 3 deletions src/views/ShowSnippetView.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import Prism from "prismjs";
import { useRouter } from "vue-router";
import { onMounted, reactive, nextTick, watch } from "vue";
import { onMounted, reactive, nextTick, watch, computed } from "vue";
import { useAuthStore } from "../store/authStore";
import { useGetSnippets } from "../composables/useGetSnippets";
import { useDeleteSnippet } from "../composables/useDeleteSnippet";
Expand All @@ -27,7 +27,7 @@ const snippetData = reactive({
tags: "",
createdAt: date.toISOString(),
updatedAt: date.toISOString(),
authorId: authStore.idToken,
authorId: computed(() => authStore.getUserId()),
visibility: true,
});
Expand Down Expand Up @@ -61,8 +61,9 @@ onMounted(async () => {
});
watch(isDeleting, (value) => {
console.log(value);
if (value) {
router.push("/");
fetchSnippetById(id.toString());
}
});
</script>
Expand Down

0 comments on commit 59bea4d

Please sign in to comment.