Skip to content

Commit

Permalink
basic set up for variable inputs and theme dropdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nikk15 committed Jul 27, 2023
1 parent 2a325e3 commit 08adfcb
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 21 deletions.
43 changes: 24 additions & 19 deletions admin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@iarna/toml": "^2.2.3",
"@mozilla/lilypad-ui": "^1.8.2",
"@mozilla/lilypad-ui": "^1.8.6",
"aframe": "github:mozillareality/aframe#hubs/master",
"bitecs": "github:mozilla/bitECS#hubs-patches",
"classnames": "^2.2.5",
Expand Down
47 changes: 47 additions & 0 deletions admin/src/react-components/ThemeBuilder/ThemeBuilder.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, {useEffect, useState} from 'react';
// import theme from "../../utils/sample-theme";
import {Button, Input, Select} from '@mozilla/lilypad-ui'

const ThemeBuilder = ({config}) => {
const themes = JSON.parse(config?.hubs?.theme?.themes)
const formattedThemes = themes.map(theme => ({title: theme.name, value: theme.id}));

const [selectedTheme, setSelectedTheme] = useState(themes.find(theme => !!theme?.default))

const onChange = e => {
setSelectedTheme(themes.find(theme => theme.id === e.target.value))
}

const onSubmit = e => {
e.preventDefault()
console.log(selectedTheme)
}

const onVariableChange = (e, key )=> {
console.log(e.target.value, key)
e.preventDefault()
e.persist()
setSelectedTheme(prevState => {
console.log(prevState)
return {...prevState, variables: {...prevState.variables, [key]: e.target.value}}
})
}

useEffect(() => {
console.log(selectedTheme)
}, [selectedTheme])

return (
<div>
<Select label="Themes" options={formattedThemes} name="Themes" value={selectedTheme.id} onChange={onChange}/>
<form onSubmit={onSubmit} >
{Object.entries(selectedTheme.variables).map(([key, value]) => {
return <Input label={key} name={key} value={value} onChange={e => onVariableChange(e, key)}/>
})}
<Button type="submit" text="Submit" label="Submit" />
</form>
</div>
)
}

export default ThemeBuilder
5 changes: 4 additions & 1 deletion admin/src/react-components/service-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
getAdminInfo
} from "../utils/ita";
import * as AppConfigUtils from "../utils/app-config";
import ThemeBuilder from "./ThemeBuilder/ThemeBuilder";

const qs = new URLSearchParams(location.hash.split("?")[1]);

Expand Down Expand Up @@ -429,7 +430,8 @@ class ConfigurationEditor extends Component {
const configurables = this.getFilteredDescriptors(theme);
const getInput = ([path, descriptor]) => this.renderConfigurable(path, descriptor, getConfigValue(config, path));

return (
return (<>

Check failure on line 433 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Insert `⏎······`
<ThemeBuilder config={config}/>

Check failure on line 434 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Replace `····<ThemeBuilder·config={config}` with `········<ThemeBuilder·config={config}·`
<form onSubmit={this.onSubmit.bind(this)}>

Check failure on line 435 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Replace `······` with `········`
<h3 className="heading-sm mb-24">Nametags</h3>

Check failure on line 436 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Insert `··`
{getInput(configurables[0])}

Check failure on line 437 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Replace `········` with `··········`
Expand Down Expand Up @@ -466,6 +468,7 @@ class ConfigurationEditor extends Component {
)}
</div>
</form>
</>
);
}

Expand Down

0 comments on commit 08adfcb

Please sign in to comment.