Skip to content

Commit

Permalink
refactor: rename bibliography to text in DOI store and related compon…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
jeffnawroth committed Jan 5, 2025
1 parent c44f5b0 commit a328155
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/components/Input/FileInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useDoiStore } from '~/stores/doi'
// Doi Store
const doiStore = useDoiStore()
const { bibliography, file, dois } = storeToRefs(doiStore)
const { text, file, dois } = storeToRefs(doiStore)
// Data
Expand All @@ -17,18 +17,18 @@ async function extractPDFText() {
const pdf = await getDocumentProxy(new Uint8Array(buffer))
const { text } = await extractText(pdf, { mergePages: true })
const { text: pdfText } = await extractText(pdf, { mergePages: true })
bibliography.value = text
text.value = pdfText
bibliography.value = dois.value.length > 0 ? dois.value.join('\n') : ''
text.value = dois.value.length > 0 ? dois.value.join('\n') : ''
}
catch (error) {
console.error('Error extracting text:', error)
}
}
else {
bibliography.value = ''
text.value = ''
console.warn('Please upload a valid PDF file.')
}
}
Expand All @@ -38,7 +38,7 @@ watch(file, (newValue) => {
extractPDFText()
}
else {
bibliography.value = ''
text.value = ''
}
})
</script>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Input/TextInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { autoImportOption } from '~/logic'
import { useDoiStore } from '~/stores/doi'
// App Store
const { bibliography, dois, url } = storeToRefs(useDoiStore())
const { text, dois, url } = storeToRefs(useDoiStore())
// Listen for messages
onMessage('bibliography', ({ data }) => {
bibliography.value = data.selectedText
text.value = data.selectedText
})
onMessage('autoImportBibliography', ({ data }) => {
Expand All @@ -18,9 +18,9 @@ onMessage('autoImportBibliography', ({ data }) => {
url.value = data.url
bibliography.value = data.selectedText
text.value = data.selectedText
bibliography.value = dois.value.length > 0 ? dois.value.join('\n') : ''
text.value = dois.value.length > 0 ? dois.value.join('\n') : ''
})
// I18n
Expand All @@ -34,7 +34,7 @@ const placeholder = computed(() => autoImportOption.value ? t('reload-page-auto-

<template>
<v-textarea
v-model="bibliography"
v-model="text"
auto-grow
:prepend-inner-icon="mdiText"
:placeholder
Expand Down
4 changes: 2 additions & 2 deletions src/components/Report/States/NoDoisFoundState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { useDoiStore } from '~/stores/doi'
const { t } = useI18n()
// Doi Store
const { dois, bibliography, file } = storeToRefs(useDoiStore())
const { dois, text, file } = storeToRefs(useDoiStore())
</script>

<template>
<v-empty-state
v-if="dois.length === 0 && (!!bibliography.length || file)"
v-if="dois.length === 0 && (!!text.length || file)"
:icon=" mdiAlertCircleOutline"
:title="t('no-valid-dois-were-found')"
:text="t('check-dois')"
Expand Down
4 changes: 2 additions & 2 deletions src/components/Report/States/NoInputState.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import { useDoiStore } from '~/stores/doi'
const { t } = useI18n()
// Doi Store
const { bibliography, file } = storeToRefs(useDoiStore())
const { text, file } = storeToRefs(useDoiStore())
</script>

<template>
<v-empty-state
v-if="bibliography.length === 0 && !file"
v-if="text.length === 0 && !file"
:icon="mdiInformationOutline"
:text="t('enter-dois')"
:title="t('no-input-provided')"
Expand Down
14 changes: 7 additions & 7 deletions src/stores/doi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { extractDOIs } from '~/utils/doiExtractor'

export const useDoiStore = defineStore('doi', () => {
// Data
const bibliography = ref<string>('')
const text = ref<string>('')
const client = new CrossrefClient()
const loading = ref(false)
const loadAborted = ref(false)
Expand All @@ -19,10 +19,10 @@ export const useDoiStore = defineStore('doi', () => {

// Computed

// Extracts DOIs from the bibliography
const dois = computed(() => extractDOIs(bibliography.value))
// Extracts DOIs from the text
const dois = computed(() => extractDOIs(text.value))

// Number of DOIs found in the bibliography
// Number of DOIs found in the text
const found = computed(() => works.value.length)

// Number of DOIs that passed the check
Expand Down Expand Up @@ -79,13 +79,13 @@ export const useDoiStore = defineStore('doi', () => {
reset()
})

watch(bibliography, (newValue) => {
watch(text, (newValue) => {
if (!newValue)
reset()
})

function reset() {
bibliography.value = ''
text.value = ''
url.value = ''
file.value = null
works.value = []
Expand All @@ -97,7 +97,7 @@ export const useDoiStore = defineStore('doi', () => {
loading.value = false
}

return { dois, resolveDOI, bibliography, loading, loadAborted, works, found, valid, invalid, getDOIsMetadata, abortFetching, url, file }
return { dois, resolveDOI, text, loading, loadAborted, works, found, valid, invalid, getDOIsMetadata, abortFetching, url, file }
})

if (import.meta.hot) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/doiExtractor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// src/utils/doiExtractor.ts
export function extractDOIs(bibliography: string): string[] {
export function extractDOIs(text: string): string[] {
const extractedDOIs: string[] = []

const doiPatterns = [
Expand All @@ -17,13 +17,13 @@ export function extractDOIs(bibliography: string): string[] {
// Check for embedded DOIs in URLs (using global flag 'g')
let urlMatches
// eslint-disable-next-line no-cond-assign
while ((urlMatches = urlPattern.exec(bibliography)) !== null) {
while ((urlMatches = urlPattern.exec(text)) !== null) {
extractedDOIs.push(urlMatches[1].replace(/\.$/, '')) // Remove any trailing period
}

// Check for normal DOIs based on the defined patterns
doiPatterns.forEach((pattern) => {
const matches = bibliography.match(pattern)
const matches = text.match(pattern)
if (matches) {
extractedDOIs.push(
...matches.map(match => match.replace(/\.$/, '')), // Remove any trailing period if present
Expand Down

0 comments on commit a328155

Please sign in to comment.