mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Move makeSearchableList to it’s own file
This commit is contained in:
parent
50272298bf
commit
c73d62f6bc
3 changed files with 88 additions and 82 deletions
|
|
@ -10,6 +10,7 @@ import { buildVideoPayload, buildAppBenchmarkPayload } from './helpers/build-pay
|
|||
|
||||
import { categories, getAppCategory } from './helpers/categories.js'
|
||||
import { getAppEndpoint, getVideoEndpoint } from './helpers/app-derived.js'
|
||||
import { makeSearchableList } from './helpers/searchable-list.js'
|
||||
|
||||
// Setup dotenv
|
||||
dotenv.config()
|
||||
|
|
@ -149,87 +150,6 @@ class BuildLists {
|
|||
return
|
||||
}
|
||||
|
||||
// Converts a list into a smaller searchable list
|
||||
// similar to a table/spreadsheet
|
||||
makeSearchableList ( list ) {
|
||||
let firstLoop = true
|
||||
|
||||
const searchableList = new Set()
|
||||
|
||||
const tableHeader = new Set()
|
||||
|
||||
// const searchableKeys = new Set([
|
||||
// 'name',
|
||||
// 'text',
|
||||
// 'lastUpdated',
|
||||
// 'endpoint'
|
||||
// ])
|
||||
|
||||
const makeSearchable = new Map([
|
||||
[
|
||||
'name',
|
||||
item => {
|
||||
// console.log('Running name method', item)
|
||||
return item.name
|
||||
}
|
||||
],
|
||||
[
|
||||
'text',
|
||||
item => item.text
|
||||
],
|
||||
[
|
||||
'endpoint',
|
||||
item => item.endpoint
|
||||
],
|
||||
[
|
||||
'category',
|
||||
app => {
|
||||
return getAppCategory( app ).id
|
||||
}
|
||||
]
|
||||
])
|
||||
|
||||
list.forEach( ( searchableItem ) => {
|
||||
// If this is the first items
|
||||
// then store the keys
|
||||
if ( firstLoop ) {
|
||||
Object.keys(searchableItem).forEach( key => {
|
||||
// console.log(key, makeSearchable.has(key))
|
||||
|
||||
if ( !makeSearchable.has(key) ) return
|
||||
|
||||
// Add to table header so we can loop it later on
|
||||
tableHeader.add( key )
|
||||
})
|
||||
|
||||
// Add keys to table head
|
||||
searchableList.add( Array.from( tableHeader ) )
|
||||
|
||||
firstLoop = false
|
||||
}
|
||||
// This could cause an issue if the keys
|
||||
// are out of order
|
||||
|
||||
// console.log('tableHeader', tableHeader)
|
||||
|
||||
const tableRow = []
|
||||
|
||||
// Loop through keys from table header
|
||||
// and push them to this row
|
||||
tableHeader.forEach( key => {
|
||||
// console.log('searchableValue', key, searchableItem[key], makeSearchable.get(key)(searchableItem) )
|
||||
|
||||
tableRow.push( makeSearchable.get(key)(searchableItem) )
|
||||
})
|
||||
|
||||
searchableList.add( tableRow )
|
||||
|
||||
return
|
||||
})
|
||||
|
||||
return searchableList
|
||||
}
|
||||
|
||||
// Save app lists to JSON
|
||||
saveAppLists = async function () {
|
||||
|
||||
|
|
@ -246,7 +166,7 @@ class BuildLists {
|
|||
|
||||
await this.saveList( listOptions )
|
||||
|
||||
const searchableList = this.makeSearchableList( this.lists[listOptions.name] )
|
||||
const searchableList = makeSearchableList( this.lists[listOptions.name] )
|
||||
|
||||
// console.log('searchableList', searchableList)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue