mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
use routes to generate sidebar items
This commit is contained in:
parent
506902ee24
commit
637c9a95a7
@ -16,14 +16,5 @@
|
|||||||
"feed_max_fetch": 20,
|
"feed_max_fetch": 20,
|
||||||
"style.compactMode": false,
|
"style.compactMode": false,
|
||||||
"sidebar.floating": false,
|
"sidebar.floating": false,
|
||||||
"language": "en",
|
"language": "en"
|
||||||
"sidebarKeys": [
|
|
||||||
"home",
|
|
||||||
"tv",
|
|
||||||
"music",
|
|
||||||
"events",
|
|
||||||
"groups",
|
|
||||||
"marketplace",
|
|
||||||
"dev"
|
|
||||||
]
|
|
||||||
}
|
}
|
@ -13,13 +13,6 @@
|
|||||||
"icon": "Home",
|
"icon": "Home",
|
||||||
"reachable": true
|
"reachable": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "events",
|
|
||||||
"path": "/events",
|
|
||||||
"title": "Events",
|
|
||||||
"icon": "MdLocalActivity",
|
|
||||||
"reachable": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "tv",
|
"id": "tv",
|
||||||
"path": "/tv",
|
"path": "/tv",
|
||||||
@ -33,26 +26,5 @@
|
|||||||
"title": "Music",
|
"title": "Music",
|
||||||
"icon": "MdMusicVideo",
|
"icon": "MdMusicVideo",
|
||||||
"reachable": true
|
"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
|
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -5,7 +5,6 @@ import classnames from "classnames"
|
|||||||
|
|
||||||
import config from "config"
|
import config from "config"
|
||||||
import { Icons, createIconRender } from "components/Icons"
|
import { Icons, createIconRender } from "components/Icons"
|
||||||
import { sidebarKeys as defaultSidebarItems } from "schemas/defaultSettings"
|
|
||||||
|
|
||||||
import sidebarItems from "schemas/routes.json"
|
import sidebarItems from "schemas/routes.json"
|
||||||
|
|
||||||
@ -21,6 +20,10 @@ const getSidebarComponents = () => {
|
|||||||
const items = {}
|
const items = {}
|
||||||
|
|
||||||
sidebarItems.forEach((item, index) => {
|
sidebarItems.forEach((item, index) => {
|
||||||
|
if (!item.reachable) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
items[item.id] = {
|
items[item.id] = {
|
||||||
...item,
|
...item,
|
||||||
index,
|
index,
|
||||||
@ -37,35 +40,18 @@ const getSidebarComponents = () => {
|
|||||||
|
|
||||||
const generateItems = () => {
|
const generateItems = () => {
|
||||||
const components = getSidebarComponents()
|
const components = getSidebarComponents()
|
||||||
|
|
||||||
const itemsMap = []
|
const itemsMap = []
|
||||||
const pathResolvers = {}
|
const pathResolvers = {}
|
||||||
|
|
||||||
const keys = window.app?.settings.get("sidebarKeys") ?? defaultSidebarItems
|
Object.keys(components).forEach((key, index) => {
|
||||||
|
|
||||||
// filter undefined components to avoid error
|
|
||||||
keys.filter((key) => {
|
|
||||||
if (typeof components[key] !== "undefined") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
keys.forEach((key, index) => {
|
|
||||||
const component = components[key]
|
const component = components[key]
|
||||||
|
|
||||||
try {
|
if (typeof component.path !== "undefined") {
|
||||||
// avoid if item is duplicated
|
pathResolvers[component.id] = component.path
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemsMap.push(component)
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user