diff --git a/site/pages/index.js b/site/pages/index.js index 960c373..35201c6 100644 --- a/site/pages/index.js +++ b/site/pages/index.js @@ -6,16 +6,44 @@ import styles from '../styles/Home.module.css' export default function Home({ searchText }) { const [workspaces, setWorkspaces] = useState(null) + const [versions, setVersions] = useState(null) + const [version, setVersion] = useState(null) useEffect(() => { + let currentVersion = localStorage.getItem("version") || null fetch('list.json') .then((res) => res.json()) .then((workspaces) => { + let wsversions = [] + workspaces.workspaces.forEach((workspace) => { + if(workspace.compatibility) { + workspace.compatibility.forEach((v) => { + const value = parseFloat(v) + if(wsversions.indexOf(value) === -1) { + wsversions.push(value) + } + }) + } + }) + const sorted = wsversions.sort((a,b) => a-b).reverse() + + setVersions(sorted) + if (currentVersion === null) { + currentVersion = sorted[0] + localStorage.setItem("version", currentVersion); + } + setVersion(currentVersion) setWorkspaces(workspaces) }) }, []) + const updateVersion = (version) => { + localStorage.setItem("version", version); + setVersion(version) + } + let filteredworkspaces = workspaces && workspaces.workspaces && workspaces.workspaces.length > 0 ? [...workspaces.workspaces] : []; + filteredworkspaces = filteredworkspaces.filter((v) => v.compatibility.some((el) => el === version + '.x')) const lowerSearch = searchText && searchText.toLowerCase(); if (searchText && searchText !== "") { filteredworkspaces = filteredworkspaces.filter((i) => { @@ -40,7 +68,18 @@ export default function Home({ searchText }) {
-

Workspaces {workspaces && workspaces.workspacecount}

+

+ + Workspaces + {workspaces && workspaces.workspacecount} + + + Kasm Version + {versions && versions.map((v) => ( +
updateVersion(v)}>{v}
+ ))}
+
+

{filteredworkspaces && filteredworkspaces.length > 0 && filteredworkspaces.map(function (workspace, i) { return