diff --git a/src/main/scala/db/DBConnection.scala b/src/main/scala/db/DBConnection.scala index 59c6094..1d1ff1d 100644 --- a/src/main/scala/db/DBConnection.scala +++ b/src/main/scala/db/DBConnection.scala @@ -14,7 +14,7 @@ object DBConnection { private def getDbPassword = sys.env.getOrElse("POSTGRES_PASSWORD", "") private def getDatabaseUrl: String = - sys.env.getOrElse("DATABASE_URL", s"postgres://${getDbUser}:${getDbPassword}@0.0.0.0:5432/${getDbName}") // host - postgres for docker, 0.0.0.0 outside docker + sys.env.getOrElse("DATABASE_URL", s"postgres://${getDbUser}:${getDbPassword}@postgres:5432/${getDbName}") // host - postgres for docker, 0.0.0.0 outside docker private def parseUrl(url: String): Either[String, PostgresConfig] = { Try { diff --git a/web/src/App.tsx b/web/src/App.tsx index 0efd565..1580c3c 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,36 +1,48 @@ -import { Component, createSignal } from 'solid-js'; +import { Component, JSXElement, createSignal } from 'solid-js'; import styles from './css/App.module.css'; import { Country } from './country/Country'; import { Cities } from './cities/Cities'; import { Database } from './database/Database'; +import { Station } from './station/Station'; +import { apiHost } from './consts'; console.log("env:", import.meta.env.MODE); -console.log("api host:", import.meta.env.VITE_API_HOST); +console.log("api host:", apiHost); -type Section = "cities" | "country" | "database"; +// type Section = "station" | "cities" | "country" | "database"; const App: Component = () => { - const [getSection, setSection] = createSignal
("cities"); + const pages: [string, () => JSXElement][] = [ + ["station", () => ], + ["cities", () => ], + ["latvia", () => ], + ["database", () => ], + ]; + const [getPageTitle, setPageTitle] = createSignal("cities"); - const section = () => { - switch(getSection()) { - case "database": return ; - case "country": return ; - case "cities": return - default: - return ; - } + const getPageContent = () => { + const page = pages.find(p => p[0] === getPageTitle()); + return page ? page[1]() :
Page not found!
; + } + + const getActiveCSS = (pageTitle: string) => { + return getPageTitle() === pageTitle ? styles.active : ""; } return (
-
- setSection("cities")}>cities | - setSection("country")}>latvia | - setSection("database")}>database -
- { section() } +
    + { pages.map(([pageTitle]) => +
  • setPageTitle(pageTitle)} + > + {pageTitle} +
  • + )} +
+ { getPageContent() }
); }; diff --git a/web/src/consts.ts b/web/src/consts.ts index c19d377..c568676 100644 --- a/web/src/consts.ts +++ b/web/src/consts.ts @@ -1,4 +1,10 @@ -export const apiHost = import.meta.env.VITE_API_HOST; + +const protocol = window.location.protocol; +const host = window.location.hostname; +const port = window.location.port; +export const apiHost = import.meta.env.MODE === "development" + ? import.meta.env.VITE_API_HOST : `${protocol}//${host}:${port}`; +// export const apiHost = import.meta.env.VITE_API_HOST; export const cityList = ["Ainaži", "Alūksne", "Bauska", "Dagda", "Daugavgrīva", "Daugavpils", "Dobele", "Gulbene", "Jelgava", "Kalnciems", "Kolka", "Kuldīga", "Lielpēči", "Liepāja", "Madona", "Mērsrags", "Pāvilosta", "Piedruja", "Priekuļi", "Rēzekne", "Rīga", "Rucava", "Rūjiena", "Saldus", "Sigulda", "Sīļi", "Skrīveri", "Skulte", "Stende", "Ventspils", "Vičaki", "Zīlāni", "Zosēni"]; diff --git a/web/src/css/App.module.css b/web/src/css/App.module.css index d156436..c059c40 100644 --- a/web/src/css/App.module.css +++ b/web/src/css/App.module.css @@ -23,15 +23,30 @@ color: #b318f0; } -.sections { +.menu { position: absolute; top: 0px; left: 0px; padding-left: 20px; - line-height: 70px; text-align: left; } +.menu li{ + display: inline; + padding: 10px 0 10px 10px; + cursor: pointer; + line-height: 40px; +} + +.menu li:not(:first-child)::before { + content: '•'; + margin-right: 1ch; +} + +.active { + font-weight: bold; +} + @keyframes logo-spin { from { transform: rotate(0deg); diff --git a/web/src/station/Station.tsx b/web/src/station/Station.tsx new file mode 100644 index 0000000..81111bf --- /dev/null +++ b/web/src/station/Station.tsx @@ -0,0 +1,20 @@ +import { Component } from "solid-js"; + +export const Station: Component<{}> = (props) => { + return ( +
+

Station

+
+
+ 1st +
+
+ 2nd +
+
+ 3rd +
+
+
+ ); +} \ No newline at end of file