use routes to generate sidebar items

This commit is contained in:
SrGooglo 2022-12-08 13:51:26 +00:00
parent bcbf082107
commit b803860ace
3 changed files with 11 additions and 62 deletions

View File

@ -16,14 +16,5 @@
"feed_max_fetch": 20,
"style.compactMode": false,
"sidebar.floating": false,
"language": "en",
"sidebarKeys": [
"home",
"tv",
"music",
"events",
"groups",
"marketplace",
"dev"
]
"language": "en"
}

View File

@ -13,13 +13,6 @@
"icon": "Home",
"reachable": true
},
{
"id": "events",
"path": "/events",
"title": "Events",
"icon": "MdLocalActivity",
"reachable": true
},
{
"id": "tv",
"path": "/tv",
@ -33,26 +26,5 @@
"title": "Music",
"icon": "MdMusicVideo",
"reachable": true
},
{
"id": "groups",
"path": "/groups",
"title": "Groups",
"icon": "Users",
"reachable": true
},
{
"id": "marketplace",
"path": "/marketplace",
"title": "Marketplace",
"icon": "Package",
"reachable": true
},
{
"id": "dev",
"path": "/dev",
"title": "Development",
"icon": "MdOutlineCode",
"reachable": true
}
]

View File

@ -5,7 +5,6 @@ import classnames from "classnames"
import config from "config"
import { Icons, createIconRender } from "components/Icons"
import { sidebarKeys as defaultSidebarItems } from "schemas/defaultSettings"
import sidebarItems from "schemas/routes.json"
@ -21,6 +20,10 @@ const getSidebarComponents = () => {
const items = {}
sidebarItems.forEach((item, index) => {
if (!item.reachable) {
return
}
items[item.id] = {
...item,
index,
@ -37,35 +40,18 @@ const getSidebarComponents = () => {
const generateItems = () => {
const components = getSidebarComponents()
const itemsMap = []
const pathResolvers = {}
const keys = window.app?.settings.get("sidebarKeys") ?? defaultSidebarItems
// filter undefined components to avoid error
keys.filter((key) => {
if (typeof components[key] !== "undefined") {
return true
}
})
keys.forEach((key, index) => {
Object.keys(components).forEach((key, index) => {
const component = components[key]
try {
// avoid if item is duplicated
if (itemsMap.includes(component)) {
return false
}
if (typeof component.path !== "undefined") {
pathResolvers[component.id] = component.path
}
itemsMap.push(component)
} catch (error) {
return console.log(error)
if (typeof component.path !== "undefined") {
pathResolvers[component.id] = component.path
}
itemsMap.push(component)
})
return {