Add form to add new app/section
This commit is contained in:
parent
57d1156425
commit
87d17216c1
Binary file not shown.
@ -24,3 +24,4 @@ sections:
|
|||||||
url: https://woodpecker.dvirlabs.com
|
url: https://woodpecker.dvirlabs.com
|
||||||
name: Dev-tools
|
name: Dev-tools
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -29,13 +29,16 @@ def get_apps():
|
|||||||
with open(APPS_FILE, "r") as f:
|
with open(APPS_FILE, "r") as f:
|
||||||
return yaml.safe_load(f)
|
return yaml.safe_load(f)
|
||||||
|
|
||||||
class AppEntry(BaseModel):
|
class AppData(BaseModel):
|
||||||
section: str
|
|
||||||
name: str
|
name: str
|
||||||
icon: str
|
icon: str
|
||||||
description: str
|
description: str
|
||||||
url: str
|
url: str
|
||||||
|
|
||||||
|
class AppEntry(BaseModel):
|
||||||
|
section: str
|
||||||
|
app: AppData
|
||||||
|
|
||||||
@app.post("/add_app")
|
@app.post("/add_app")
|
||||||
def add_app(entry: AppEntry):
|
def add_app(entry: AppEntry):
|
||||||
if not APPS_FILE.exists():
|
if not APPS_FILE.exists():
|
||||||
@ -47,22 +50,12 @@ def add_app(entry: AppEntry):
|
|||||||
# Find or create section
|
# Find or create section
|
||||||
for section in current["sections"]:
|
for section in current["sections"]:
|
||||||
if section["name"] == entry.section:
|
if section["name"] == entry.section:
|
||||||
section["apps"].append({
|
section["apps"].append(entry.app.dict())
|
||||||
"name": entry.name,
|
|
||||||
"icon": entry.icon,
|
|
||||||
"description": entry.description,
|
|
||||||
"url": entry.url,
|
|
||||||
})
|
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
current["sections"].append({
|
current["sections"].append({
|
||||||
"name": entry.section,
|
"name": entry.section,
|
||||||
"apps": [{
|
"apps": [entry.app.dict()]
|
||||||
"name": entry.name,
|
|
||||||
"icon": entry.icon,
|
|
||||||
"description": entry.description,
|
|
||||||
"url": entry.url,
|
|
||||||
}]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
with open(APPS_FILE, "w") as f:
|
with open(APPS_FILE, "w") as f:
|
||||||
@ -70,6 +63,7 @@ def add_app(entry: AppEntry):
|
|||||||
|
|
||||||
return {"status": "added"}
|
return {"status": "added"}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import uvicorn
|
import uvicorn
|
||||||
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)
|
||||||
@ -1,19 +1,26 @@
|
|||||||
|
// src/App.jsx
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import SectionGrid from './components/SectionGrid';
|
import SectionGrid from './components/SectionGrid';
|
||||||
|
import ControlPanel from './components/ControlPanel';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [sections, setSections] = useState([]);
|
const [sections, setSections] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
const fetchSections = () => {
|
||||||
fetch('/apps')
|
fetch('/apps')
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(data => setSections(data.sections || []));
|
.then(data => setSections(data.sections || []));
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchSections();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<h1 className="main-title">🔷 Navix</h1>
|
<h1 className="main-title">🔷 Navix</h1>
|
||||||
|
<ControlPanel onUpdate={fetchSections} />
|
||||||
{sections.map((section) => (
|
{sections.map((section) => (
|
||||||
<SectionGrid key={section.name} section={section} />
|
<SectionGrid key={section.name} section={section} />
|
||||||
))}
|
))}
|
||||||
|
|||||||
@ -6,7 +6,8 @@ export default defineConfig({
|
|||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
'/apps': 'http://localhost:8000'
|
'/apps': 'http://localhost:8000',
|
||||||
|
'/add_app': 'http://localhost:8000',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user