2024-11-16 11:30:51 +01:00
|
|
|
import { defineStore } from "pinia";
|
2024-11-16 12:05:37 +01:00
|
|
|
import { ref, computed } from "vue";
|
2024-11-27 17:51:49 +01:00
|
|
|
import { useRoute } from "vue-router";
|
2024-11-16 11:30:51 +01:00
|
|
|
|
|
|
|
|
export const useDialogStore = defineStore("dialog", () => {
|
|
|
|
|
const content = ref(null);
|
2024-11-16 12:05:37 +01:00
|
|
|
const openedFile = ref(null);
|
|
|
|
|
const comments = computed(() => {
|
|
|
|
|
return openedFile.value.comments;
|
|
|
|
|
});
|
2024-11-16 11:30:51 +01:00
|
|
|
|
2024-11-16 12:05:37 +01:00
|
|
|
function updateFile(newFile) {
|
2024-11-28 14:45:45 +01:00
|
|
|
openedFile.value = newFile;
|
|
|
|
|
|
|
|
|
|
if (!content.value.files) return;
|
2024-11-16 12:05:37 +01:00
|
|
|
content.value.files = content.value.files.map((file) =>
|
|
|
|
|
file.id === newFile.id ? newFile : file
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 17:51:49 +01:00
|
|
|
const route = useRoute();
|
|
|
|
|
const isCommentsOpen = ref(
|
|
|
|
|
route.query.hasOwnProperty("comments") ? true : false
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return { content, openedFile, comments, isCommentsOpen, updateFile };
|
2024-11-16 11:30:51 +01:00
|
|
|
});
|