From 26fda48f2643f4f07e937ff613a428b6e6d1a505 Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Sun, 17 Nov 2024 16:36:17 -0500 Subject: [PATCH] Migrate Post view to Composition API (#6133) * Migrate Post view to Composition API * add missing watch * move constants below import * Use shallowRef for post Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> * Add missing import for shallowRef --------- Co-authored-by: absidue <48293849+absidue@users.noreply.github.com> --- src/renderer/views/Post/Post.js | 74 -------------------------------- src/renderer/views/Post/Post.vue | 69 ++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 75 deletions(-) delete mode 100644 src/renderer/views/Post/Post.js diff --git a/src/renderer/views/Post/Post.js b/src/renderer/views/Post/Post.js deleted file mode 100644 index e515992de17c9..0000000000000 --- a/src/renderer/views/Post/Post.js +++ /dev/null @@ -1,74 +0,0 @@ -import { defineComponent } from 'vue' -import FtCard from '../../components/ft-card/ft-card.vue' -import FtCommunityPost from '../../components/FtCommunityPost/FtCommunityPost.vue' -import FtLoader from '../../components/ft-loader/ft-loader.vue' -import WatchVideoComments from '../../components/watch-video-comments/watch-video-comments.vue' - -import { getInvidiousCommunityPost } from '../../helpers/api/invidious' - -export default defineComponent({ - name: 'Post', - components: { - FtCard, - FtCommunityPost, - FtLoader, - WatchVideoComments - }, - data: function () { - return { - id: '', - authorId: '', - post: null, - comments: null, - isLoading: true, - } - }, - computed: { - backendPreference: function () { - return this.$store.getters.getBackendPreference - }, - backendFallback: function () { - return this.$store.getters.getBackendFallback - }, - isInvidiousAllowed: function() { - return this.backendPreference === 'invidious' || this.backendFallback - } - }, - watch: { - async '$route.params.id'() { - // react to route changes... - this.isLoading = true - if (this.isInvidiousAllowed) { - this.id = this.$route.params.id - this.authorId = this.$route.query.authorId - await this.loadDataInvidiousAsync() - } - } - }, - mounted: async function () { - if (this.isInvidiousAllowed) { - this.id = this.$route.params.id - this.authorId = this.$route.query.authorId - await this.loadDataInvidiousAsync() - } - }, - methods: { - loadDataInvidiousAsync: async function() { - this.post = await getInvidiousCommunityPost(this.id, this.authorId) - this.authorId = this.post.authorId - this.isLoading = false - - // If the authorId is missing from the URL we should add it, - // that way if the user comes back to this page by pressing the back button - // we don't have to resolve the authorId again - if (this.authorId !== this.$route.query.authorId) { - this.$router.replace({ - path: `/post/${this.id}`, - query: { - authorId: this.authorId - } - }) - } - } - } -}) diff --git a/src/renderer/views/Post/Post.vue b/src/renderer/views/Post/Post.vue index 22b316ebaeaa7..6d366cb4daa81 100644 --- a/src/renderer/views/Post/Post.vue +++ b/src/renderer/views/Post/Post.vue @@ -28,4 +28,71 @@ -