mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-18 06:44:46 -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 { categories, getAppCategory } from './helpers/categories.js'
|
||||||
import { getAppEndpoint, getVideoEndpoint } from './helpers/app-derived.js'
|
import { getAppEndpoint, getVideoEndpoint } from './helpers/app-derived.js'
|
||||||
|
import { makeSearchableList } from './helpers/searchable-list.js'
|
||||||
|
|
||||||
// Setup dotenv
|
// Setup dotenv
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
@ -149,87 +150,6 @@ class BuildLists {
|
||||||
return
|
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
|
// Save app lists to JSON
|
||||||
saveAppLists = async function () {
|
saveAppLists = async function () {
|
||||||
|
|
||||||
|
|
@ -246,7 +166,7 @@ class BuildLists {
|
||||||
|
|
||||||
await this.saveList( listOptions )
|
await this.saveList( listOptions )
|
||||||
|
|
||||||
const searchableList = this.makeSearchableList( this.lists[listOptions.name] )
|
const searchableList = makeSearchableList( this.lists[listOptions.name] )
|
||||||
|
|
||||||
// console.log('searchableList', searchableList)
|
// console.log('searchableList', searchableList)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
// Universal JS imports only
|
||||||
|
|
||||||
|
|
||||||
// Contains all types of properies to keep data consistent
|
// Contains all types of properies to keep data consistent
|
||||||
export const categoryTemplate = {
|
export const categoryTemplate = {
|
||||||
|
|
|
||||||
84
helpers/searchable-list.js
Normal file
84
helpers/searchable-list.js
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
// Universal JS imports only
|
||||||
|
import { getAppCategory } from './categories.js'
|
||||||
|
|
||||||
|
|
||||||
|
// Converts a list into a smaller searchable list
|
||||||
|
// similar to a table/spreadsheet
|
||||||
|
export function makeSearchableList ( listSet ) {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
]
|
||||||
|
])
|
||||||
|
|
||||||
|
listSet.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
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue