Get dynamic routes working on production

Remove unused api
This commit is contained in:
Chris Hunt 2023-01-10 11:16:36 +00:00
parent c2c1599221
commit affa698a24
2 changed files with 67 additions and 40 deletions

View File

@ -4,8 +4,34 @@ import { saveAs } from 'file-saver';
import CreatableSelect from 'react-select/creatable'; import CreatableSelect from 'react-select/creatable';
import Select from 'react-select'; import Select from 'react-select';
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import allapps from '../../../public/list.json'
export default function AddApp() {
export async function getStaticPaths() {
let paths = allapps.apps.map(app => ({
params: {
app: [btoa(app.name)]
}
}))
paths.push({
params: { app: null }
})
return {
paths,
fallback: false, // can also be true or 'blocking'
}
}
// `getStaticPaths` requires using `getStaticProps`
export async function getStaticProps({ params }) {
const app = params.app
return {
// Passed to the page component as props
props: { app: app ?? null },
}
}
export default function AddApp({ app = null }) {
function friendlyUrl(url) { function friendlyUrl(url) {
// make the url lowercase // make the url lowercase
@ -50,7 +76,7 @@ export default function AddApp() {
const [ext, setExt] = useState('png') const [ext, setExt] = useState('png')
const [inlineImage, setInlineImage] = useState(null) const [inlineImage, setInlineImage] = useState(null)
const [application, setApplication] = useState({ const defaultState = {
friendly_name: null, friendly_name: null,
image_src: null, image_src: null,
description: null, description: null,
@ -64,46 +90,52 @@ export default function AddApp() {
require_gpu: false, require_gpu: false,
enabled: true, enabled: true,
image_type: 'Container', image_type: 'Container',
}) }
const [application, setApplication] = useState(defaultState)
const router = useRouter() const router = useRouter()
const { app } = router.query // const { app } = router.query
useEffect(() => { useEffect(() => {
fetch('../../list.json') if(app === null) {
.then((res) => res.json()) description.current.value = ''
.then((apps) => { name.current.value = ''
if (app && app[0]) { friendly_name.current.value = ''
const appDetails = apps.apps.find(el => el.name === atob(app[0])) setCategories(null)
delete appDetails['sha'] setArchitecture(null)
description.current.value = appDetails.description setApplication(defaultState)
name.current.value = appDetails.name }
friendly_name.current.value = appDetails.friendly_name else if (app && app[0]) {
if (appDetails.categories) { const appDetails = allapps.apps.find(el => el.name === atob(app[0]))
let catMap = [] delete appDetails['sha']
appDetails.categories.map((e) => catMap.push({ description.current.value = appDetails.description
label: e, name.current.value = appDetails.name
value: e, friendly_name.current.value = appDetails.friendly_name
})) if (appDetails.categories) {
setCategories(catMap) let catMap = []
} appDetails.categories.map((e) => catMap.push({
if (appDetails.architecture) { label: e,
let archMap = [] value: e,
appDetails.architecture.map((e) => archMap.push({ }))
label: e, setCategories(catMap)
value: e, }
})) if (appDetails.architecture) {
setArchitecture(archMap) let archMap = []
} appDetails.architecture.map((e) => archMap.push({
label: e,
value: e,
}))
setArchitecture(archMap)
}
setInlineImage('../../icons/' + appDetails.image_src) setInlineImage('../../icons/' + appDetails.image_src)
setApplication({ setApplication({
...application, ...application,
...appDetails ...appDetails
})
}
}) })
}
}, [app]) }, [app])
const displayApplication = () => { const displayApplication = () => {

View File

@ -1,5 +0,0 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
export default function handler(req, res) {
res.status(200).json({ name: 'John Doe' })
}