fix(lib/discord/ui/settings)!: update apis
This commit is contained in:
parent
04c7275b4c
commit
3b15dc1803
2 changed files with 16 additions and 13 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import type { SettingsRowConfig, SettingsSection } from './api'
|
||||
|
||||
export const _suiData = {
|
||||
// Settings that are in the Overview screen
|
||||
// Sections to splice in the SettingsOverviewScreen
|
||||
sections: {},
|
||||
// Settings that are not in the Overview screen (submenus, hidden, etc.)
|
||||
settings: {},
|
||||
// SETTING_RENDERER_CONFIG settings
|
||||
config: {},
|
||||
} as {
|
||||
sections: Record<string, SettingsSection>
|
||||
settings: Record<string, SettingsRowConfig>
|
||||
config: Record<string, SettingsRowConfig>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +1,28 @@
|
|||
import { _suiData } from './_internal'
|
||||
|
||||
import type { DiscordModules } from '../../../types'
|
||||
import type { ComponentType, ReactNode } from 'react'
|
||||
|
||||
export function addSettingsSection(key: string, section: SettingsSection) {
|
||||
export function registerSettingsSection(key: string, section: SettingsSection) {
|
||||
_suiData.sections[key] = section
|
||||
return () => delete _suiData.sections[key]
|
||||
}
|
||||
|
||||
export function addSettingsRow(key: string, row: SettingsRowConfig) {
|
||||
_suiData.settings[key] = row
|
||||
return () => delete _suiData.settings[key]
|
||||
export function registerSetting(key: string, row: SettingsRowConfig) {
|
||||
_suiData.config[key] = row
|
||||
return () => delete _suiData.config[key]
|
||||
}
|
||||
|
||||
export function addSettingsRowToSection(sectionKey: string, rowKey: string, row: SettingsRowConfig) {
|
||||
if (!_suiData.sections[sectionKey]) throw new Error(`Section "${sectionKey}" does not exist`)
|
||||
_suiData.sections[sectionKey].settings[rowKey] = row
|
||||
return () => delete _suiData.sections[sectionKey].settings[rowKey]
|
||||
export function addSettingToSection(section: string, row: string) {
|
||||
if (!_suiData.sections[section]) throw new Error(`Section "${section}" does not exist`)
|
||||
const newLength = _suiData.sections[section].settings.push(row)
|
||||
|
||||
return () => delete _suiData.sections[section].settings[newLength - 1]
|
||||
}
|
||||
|
||||
export interface SettingsSection {
|
||||
label: string
|
||||
settings: Record<string, SettingsRowConfig>
|
||||
settings: string[]
|
||||
index?: number
|
||||
}
|
||||
|
||||
|
|
@ -28,6 +30,7 @@ interface BaseSettingsRowConfig {
|
|||
title: () => string
|
||||
parent: string | null
|
||||
unsearchable?: boolean
|
||||
variant?: DiscordModules.Components.TableRowProps['variant']
|
||||
IconComponent?: () => ReactNode
|
||||
usePredicate?: () => boolean
|
||||
useTrailing?: () => ReactNode
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue