Skip to content

Commit

Permalink
Fix for previous list sharing commit (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachsa committed Nov 18, 2022
1 parent 11fca4d commit b9175ba
Showing 1 changed file with 57 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import packageJson from '../../../../../../../package.json'
import { CLIENTS_PUBLIC_ADDRESS } from '../../../../../../config'
import { Div } from '../../../../../../components/html-tags'

/**
* TODO This should probably be generated from a GraphQL type query
* otherwise in the future this may become outdated, causing bugs
* that are difficult to track down
*/
const FILTER_KEYS = ['identifiers', 'ids', 'dois', 'text', 'terms', 'extent']

/**
* Dialogue contents of the share dialogue
* This component will be mounted AFTER the
Expand All @@ -27,33 +34,73 @@ export default ({ tabIndex, search = undefined }) => {
`)

useEffect(() => {
console.log(global)
saveList({
variables: {
createdBy: `${packageJson.name} v${packageJson.version}`,
filter: Object.fromEntries(
Object.entries(global.filter).map(([key, value]) => {
console.log('global', global)
console.log(
'filter',
Object.fromEntries(
Object.entries(global)
.map(([key, value]) => {
if (key === 'filter' || key === 'selectedIds' || key === 'selectAll') {
return null
}

if (key === 'extent') {
return [key, global.extent || value]
return [key, value || global.filter[key]]
}

if (value?.constructor === Array) {
return [
key,
[
...(global.filter[key] || []),
...value,
...(global[key] || []),
...(key === 'ids' ? global.selectedIds || [] : []),
].filter(_ => _),
]
}

if (key === 'text') {
return [key, `${global[key] || ''} ${value}`]
return [key, `${value || ''} ${global.filter[key] || ''}`.trim()]
}

return [key, global[key] || value]
return [key, global.filter[key] || value]
})
.filter(_ => _)
)
)

saveList({
variables: {
createdBy: `${packageJson.name} v${packageJson.version}`,
filter: Object.fromEntries(
Object.entries(global)
.map(([key, value]) => {
if (!FILTER_KEYS.includes(key)) {
return null
}

if (key === 'text') {
return [key, `${value || ''} ${global.filter[key] || ''}`.trim()]
}

if (key === 'extent') {
return [key, value || global.filter[key]]
}

if (value?.constructor === Array) {
return [
key,
[
...(global.filter[key] || []),
...value,
...(key === 'ids' ? global.selectedIds || [] : []),
].filter(_ => _),
]
}

return [key, global.filter[key] || value]
})
.filter(_ => _)
),
},
})
Expand Down

0 comments on commit b9175ba

Please sign in to comment.