From e05a5b9d7a31663ef4e8c9bfdcf8ad9085496199 Mon Sep 17 00:00:00 2001 From: upsiflu Date: Mon, 17 Mar 2025 13:30:11 +0100 Subject: [PATCH] fix(front): [WIP] in search modal, show rss result as channel link --- front/src/components/ui/Section.vue | 1 + front/src/locales/en_US.json | 2 +- front/src/ui/modals/Search.vue | 49 +++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/front/src/components/ui/Section.vue b/front/src/components/ui/Section.vue index f50f6026b..8ed82680a 100644 --- a/front/src/components/ui/Section.vue +++ b/front/src/components/ui/Section.vue @@ -87,6 +87,7 @@ const headerGrid (100) const queryDebounced = refDebounced(query, 500) const trimmedQuery = computed(() => trim(trim(queryDebounced.value), '@')) -const isUri = computed(() => trimmedQuery.value.startsWith('http://') || trimmedQuery.value.startsWith('https://') || trimmedQuery.value.includes('@')) +const isFetch = computed(() => ((trimmedQuery.value.startsWith('http://') || trimmedQuery.value.startsWith('https://')) || trimmedQuery.value.includes('@')) && !isRss.value) +const isRss = computed(() => trimmedQuery.value.includes('.rss') || trimmedQuery.value.includes('.xml')) const isLoading = ref(false) @@ -130,14 +132,16 @@ const categories = computed(() => [ type: 'rss', label: t('views.Search.label.rss'), endpoint: '/channels/rss-subscribe/', + post: true, params: { - object: trimmedQuery.value + url: trimmedQuery.value } }, { type: 'federation', label: t('views.Search.label.fetches'), endpoint: '/federation/fetches/', + post: true, params: { object: trimmedQuery.value } @@ -145,6 +149,7 @@ const categories = computed(() => [ ] as const satisfies { type: Category label: string + post?: true params?: { [key: string]: string } @@ -152,15 +157,23 @@ const categories = computed(() => [ }[]) // Limit the available categories based on the search query -const federatedCategories: Category[] = ['federation', 'rss'] - +// Show fetch if the query is a URL; show RSS if the query is an email address; show all other cateories otherwise const availableCategories = computed(() => categories.value.filter(({ type }) => - isUri.value - ? federatedCategories.includes(type) - : !federatedCategories.includes(type) + isFetch.value + ? type==='federation' + : isRss.value + ? type==='rss' + : !['federation', 'rss'].includes(type) )) +// If there is only one available category, open it immediately +watch(availableCategories, () => { + if (availableCategories.value.length === 1 && openSectionHistory.value.at(0) !== availableCategories.value[0].type) { + openSectionHistory.value.unshift(availableCategories.value[0].type) + } +}) + /** * Get the results for a given category * @param category The category to get the results for @@ -250,9 +263,11 @@ const search = async () => { ...response.data } } else { - const response = await axios.get( + console.log("endpoint", category.endpoint) + console.log("params", params) + const response = await axios['post' in category ? 'post' : 'get']( category.endpoint, - { params } + isRss.value ? ({ url: trimmedQuery.value }) : ({ params }) ) results.value = { ...results.value, @@ -303,6 +318,7 @@ watch(queryDebounced, search, { immediate: true }) >
Link to go directly to the federation page --> + + + If the following link does not work, wait a few seconds and try again + + {{ channel.artist.name }} + + + + + {{ resultsPerCategory(category.type) }} +