Skip to content

Commit

Permalink
Add MDView component and integrate markdown export functionality
Browse files Browse the repository at this point in the history
- Introduced `MDView.vue` component to display and copy markdown content.
- Added markdown export dialog in `Home.vue` with corresponding state management.
- Updated `DiaryEditor.vue` to invalidate markdown content queries.
- Adjusted styling and formatting in `TodoEditor.vue`.
  • Loading branch information
swuecho committed Dec 27, 2024
1 parent 53074dc commit d81a5b9
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 15 deletions.
1 change: 1 addition & 0 deletions web/src/components/DiaryEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const mutation = useMutation({
//
// Then use it here:
queryClient.invalidateQueries({ queryKey: ['todoContent'] });
queryClient.invalidateQueries({ queryKey: ['MdContent',props.date] });
},
onError: (error) => {
loading.value = false;
Expand Down
100 changes: 100 additions & 0 deletions web/src/components/MDView.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<template>
<div class="content">
<pre> {{ content }} </pre>
<button v-if="content" @click="copyToClipboard" class="copy-button">
<div v-if="copySuccess">
<Icon icon="akar-icons:check" />
</div>
<div v-else>
<Icon icon="iconamoon:copy"></Icon>
</div>
</button>
</div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue';
import { useQuery } from '@tanstack/vue-query';
import axios from '@/axiosConfig.js';
import { Icon } from '@iconify/vue2';
const props = defineProps({
noteId: String,
});
const copySuccess = ref(false);
const content = ref("");
const loading = ref(true);
const copyToClipboard = async () => {
if (content.value) {
try {
await navigator.clipboard.writeText(content.value);
copySuccess.value = true;
setTimeout(() => {
copySuccess.value = false;
}, 1500); // Reset the message after 1.5 seconds
} catch (err) {
console.error('Failed to copy text: ', err);
// Optionally provide user feedback about the failure
}
}
};
const fetchMdContent = async () => {
const { isLoading, isError, data, error } = useQuery(
{
queryKey: ['MdContent', props.noteId],
queryFn: async () => {
const response = await axios.post('/api/export_md', {
id: props.noteId
});
return response.data;
}
});
watch(isLoading, (isLoading) => {
loading.value = isLoading;
});
watch(data, (data) => {
if (content) {
content.value = data;
}
});
watch(isError, (hasError) => {
if (hasError) {
console.error('Error fetching todo content:', error.value);
}
});
};
onMounted(() => {
fetchMdContent();
});
</script>

<style>
.content {
max-width: 65rem;
margin: auto;
}
.copy-button {
background-color: #f1f1f1;
border: none;
color: black;
text-align: center;
text-decoration: none;
display: inline-block;
cursor: pointer;
border-radius: 4px;
padding: 10px;
position: absolute;
bottom: 10px;
right: 10px;
}
/* Additional styles... */
</style>
20 changes: 9 additions & 11 deletions web/src/components/TodoEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

<script setup>
defineProps({
content: {
type: [String, Object],
required: true
},
extensions: {
type: Array,
required: true
}
content: {
type: [String, Object],
required: true
},
extensions: {
type: Array,
required: true
}
});
</script>

Expand All @@ -35,8 +35,6 @@ defineProps({
pre code {
font-family: "Fira Code", Courier, Monaco, monospace;
font-family: "Fira Code", Courier, Monaco, monospace;
}
</style>
21 changes: 17 additions & 4 deletions web/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
<el-dialog :visible="dialogVisible" @close="closeModal">
<Todo></Todo>
</el-dialog>
<el-dialog :visible="dialogVisibleMd" @close="closeModalMd">
<MDView :noteId="date"></MDView>
</el-dialog>
<div class="right-corner">
<OnlineStatusIndicator />
<OnlineStatusIndicator />
<div @click="openModalMd">
<Icon icon="material-symbols:markdown-copy-outline" />
</div>
<div @click="openModal">
<Icon icon="streamline:task-list" />
<Icon icon="ri:todo-line" />
</div>
<div>
<a href="/content">
Expand All @@ -46,13 +52,13 @@ import { Icon } from '@iconify/vue2';
import tableOfContents from '@iconify/icons-mdi/table-of-contents';
import DiaryEditor from "@/components/DiaryEditor";
import Todo from '@/components/Todo.vue';
import MDView from '@/components/MDView.vue';
import OnlineStatusIndicator from '@/components/OnlineStatusIndicator.vue';
const now = ref(moment());
const date = ref(moment().format('YYYYMMDD'))
const dialogVisible = ref(false)
const dialogVisibleMd = ref(false)
onMounted(() => {
// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -96,6 +102,13 @@ function closeModal() {
dialogVisible.value = false
}
function openModalMd() {
dialogVisibleMd.value = true
}
function closeModalMd() {
dialogVisibleMd.value = false
}
</script>

<style scoped>
Expand Down

0 comments on commit d81a5b9

Please sign in to comment.