Skip to content
Snippets Groups Projects
Commit fbe72252 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

fix issue with articles

parent 5e3e0541
No related branches found
No related tags found
No related merge requests found
Pipeline #127655 waiting for manual action with stages
in 6 minutes and 41 seconds
<script setup lang="ts"> <script setup lang="ts">
import { useDisplay } from "vuetify"; import { useDisplay } from "vuetify";
import type { WikiArticle } from '@/types/articles'; import type { WikiArticle } from '@/types/articles';
import { useFetchArticle } from "../../composables/useFetchArticle";
export interface Props { export interface Props {
index?: number; index?: number;
...@@ -19,16 +20,15 @@ const props = withDefaults(defineProps<Props>(), { ...@@ -19,16 +20,15 @@ const props = withDefaults(defineProps<Props>(), {
isRelevant: false, isRelevant: false,
}); });
const article = ref<WikiArticle | undefined>(undefined) // const article = ref<WikiArticle | undefined>(undefined)
const { mobile } = useDisplay(); const { mobile } = useDisplay();
const show = ref(false); const show = ref(false);
onMounted(() => {
const { article: articleOnMounted } = useFetchArticle(props.doi); const { article } = useFetchArticle(props.doi);
article.value = articleOnMounted.value
})
const articleTitle = computed(() => { const articleTitle = computed(() => {
return props?.title ?? article?.value?.title ?? props.doi; return props?.title ?? article?.value?.title ?? props.doi;
...@@ -38,8 +38,8 @@ const articleAbstract = computed(() => { ...@@ -38,8 +38,8 @@ const articleAbstract = computed(() => {
}); });
</script> </script>
<template> <template>
<v-list-item :href="article?.href" :id="`ref-${props.doi}`" :target="article?.target" density="compact" <v-list-item v-if="article?.DOI" :href="article?.href" :id="`ref-${props.doi}`" :target="article?.target"
color="transparent" class="px-1"> density="compact" color="transparent" class="px-1">
<template v-if="!mobile" #prepend> <template v-if="!mobile" #prepend>
<v-icon icon="md:star" :color="props.isRelevant ? 'info' : 'transparent'"></v-icon> <v-icon icon="md:star" :color="props.isRelevant ? 'info' : 'transparent'"></v-icon>
</template> </template>
......
...@@ -6,6 +6,7 @@ import type { SearchParams } from 'meilisearch' ...@@ -6,6 +6,7 @@ import type { SearchParams } from 'meilisearch'
export function useFetchArticle(doi: string = "") { export function useFetchArticle(doi: string = "") {
const doiBaseUrl = ref(new URL("https://doi.org/")); const doiBaseUrl = ref(new URL("https://doi.org/"));
const article = useSessionStorage<WikiArticle | undefined>(doi, null, { serializer: StorageSerializers.object }) const article = useSessionStorage<WikiArticle | undefined>(doi, null, { serializer: StorageSerializers.object })
// const article = ref<WikiArticle | undefined>(null)
const client = useMeiliSearchRef() const client = useMeiliSearchRef()
const index = ref("article") const index = ref("article")
const params = ref<SearchParams>({ const params = ref<SearchParams>({
...@@ -24,6 +25,7 @@ export function useFetchArticle(doi: string = "") { ...@@ -24,6 +25,7 @@ export function useFetchArticle(doi: string = "") {
.join(", "); .join(", ");
} }
function zoteroArticleToArticle(zoteroArticle: CslJson): WikiArticle | undefined { function zoteroArticleToArticle(zoteroArticle: CslJson): WikiArticle | undefined {
console.log(zoteroArticle)
if (zoteroArticle != undefined) { if (zoteroArticle != undefined) {
const { const {
DOI, DOI,
...@@ -50,10 +52,13 @@ export function useFetchArticle(doi: string = "") { ...@@ -50,10 +52,13 @@ export function useFetchArticle(doi: string = "") {
} }
if (!article.value) { if (!article.value) {
client.index(toValue(index)).search<CslJson>("", toValue(params)).then((response) => { client.index(toValue(index)).search<CslJson>("", toValue(params)).then((data) => {
const sanitizedData = zoteroArticleToArticle(response.hits[0]) if (data !== undefined && data?.hits.length >= 1) {
article.value = sanitizedData const sanitizedData = zoteroArticleToArticle(data.hits[0])
article.value = sanitizedData
}
}).catch((error) => { }).catch((error) => {
console.log(error)
article.value = { DOI: doi } article.value = { DOI: doi }
}) })
} }
......
...@@ -6,7 +6,6 @@ function resetError(error) { ...@@ -6,7 +6,6 @@ function resetError(error) {
<template> <template>
<v-card-text> <v-card-text>
<NuxtErrorBoundary> <NuxtErrorBoundary>
<!-- ... -->
<template #error="{ error }"> <template #error="{ error }">
<ErrorAlert :error="error" @clear-error="resetError(error)"></ErrorAlert> <ErrorAlert :error="error" @clear-error="resetError(error)"></ErrorAlert>
</template> </template>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment