Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f9cd68a37 | ||
|
|
6b1e8a6baf | ||
|
|
c3b6b90c73 | ||
|
|
b5c801c5bb | ||
|
|
d4dba6f993 | ||
|
|
fe93da079c | ||
|
|
cac279eb9e | ||
|
|
0c675639e0 | ||
|
|
bb9c4cedec |
+21
-4
@@ -23,6 +23,10 @@ const props = defineProps({
|
|||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
refreshTick: {
|
||||||
|
type: Number,
|
||||||
|
default: 0,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits([
|
const emit = defineEmits([
|
||||||
@@ -41,14 +45,27 @@ const isNewArticle = computed(() => !props.article?.id);
|
|||||||
const localTitle = ref(props.article?.title ?? '');
|
const localTitle = ref(props.article?.title ?? '');
|
||||||
const localContent = ref(props.article?.content ?? '');
|
const localContent = ref(props.article?.content ?? '');
|
||||||
|
|
||||||
|
const syncLocalState = () => {
|
||||||
|
localTitle.value = props.article?.title ?? '';
|
||||||
|
localContent.value = props.article?.content ?? '';
|
||||||
|
};
|
||||||
|
|
||||||
// Sync local state when navigating to a different article or on initial fetch
|
// Sync local state when navigating to a different article or on initial fetch
|
||||||
watch(
|
watch(
|
||||||
() => props.article?.id,
|
() => props.article?.id,
|
||||||
newId => {
|
newId => {
|
||||||
if (newId) {
|
if (newId) syncLocalState();
|
||||||
localTitle.value = props.article?.title ?? '';
|
}
|
||||||
localContent.value = props.article?.content ?? '';
|
);
|
||||||
}
|
|
||||||
|
// Parent bumps refreshTick after re-fetching on tab visibility. Skip
|
||||||
|
// the sync while a save is in flight so we don't overwrite edits the
|
||||||
|
// user just made.
|
||||||
|
watch(
|
||||||
|
() => props.refreshTick,
|
||||||
|
() => {
|
||||||
|
if (props.isUpdating) return;
|
||||||
|
syncLocalState();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+13
-3
@@ -1,5 +1,6 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue';
|
import { ref, computed, onMounted, watch } from 'vue';
|
||||||
|
import { useDocumentVisibility } from '@vueuse/core';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { useAlert, useTrack } from 'dashboard/composables';
|
import { useAlert, useTrack } from 'dashboard/composables';
|
||||||
@@ -13,6 +14,7 @@ const route = useRoute();
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
const visibility = useDocumentVisibility();
|
||||||
|
|
||||||
const { articleSlug, portalSlug } = route.params;
|
const { articleSlug, portalSlug } = route.params;
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ const portal = computed(() => portalBySlug.value(portalSlug));
|
|||||||
|
|
||||||
const isUpdating = ref(false);
|
const isUpdating = ref(false);
|
||||||
const isSaved = ref(false);
|
const isSaved = ref(false);
|
||||||
|
const refreshTick = ref(0);
|
||||||
|
|
||||||
const articleLink = computed(() => {
|
const articleLink = computed(() => {
|
||||||
const { slug: categorySlug, locale: categoryLocale } = article.value.category;
|
const { slug: categorySlug, locale: categoryLocale } = article.value.category;
|
||||||
@@ -84,11 +87,12 @@ const goBackToArticles = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchArticleDetails = () => {
|
const fetchArticleDetails = async () => {
|
||||||
store.dispatch('articles/show', {
|
await store.dispatch('articles/show', {
|
||||||
id: articleSlug,
|
id: articleSlug,
|
||||||
portalSlug,
|
portalSlug,
|
||||||
});
|
});
|
||||||
|
refreshTick.value += 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
const previewArticle = () => {
|
const previewArticle = () => {
|
||||||
@@ -98,6 +102,11 @@ const previewArticle = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Re-fetch article when user returns to this tab
|
||||||
|
watch(visibility, state => {
|
||||||
|
if (state === 'visible') fetchArticleDetails();
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(fetchArticleDetails);
|
onMounted(fetchArticleDetails);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -106,6 +115,7 @@ onMounted(fetchArticleDetails);
|
|||||||
:article="article"
|
:article="article"
|
||||||
:is-updating="isUpdating"
|
:is-updating="isUpdating"
|
||||||
:is-saved="isSaved"
|
:is-saved="isSaved"
|
||||||
|
:refresh-tick="refreshTick"
|
||||||
@save-article="saveArticle"
|
@save-article="saveArticle"
|
||||||
@preview-article="previewArticle"
|
@preview-article="previewArticle"
|
||||||
@go-back="goBackToArticles"
|
@go-back="goBackToArticles"
|
||||||
|
|||||||
Reference in New Issue
Block a user