From be1209dff4495f24644b21d5299afccd669ccd3c Mon Sep 17 00:00:00 2001 From: Kb-commit Date: Wed, 16 Oct 2019 00:33:08 -0700 Subject: [PATCH] Adding views and routes --- config/react.go | 7 ++++ templates/commit0/commit0.tmpl | 6 +++- templates/react/public/index.html.tmpl | 43 ++++++++++++++++++++++++ templates/react/src/App.js | 21 +++++++----- templates/react/src/config/index.js | 12 ++++++- templates/react/src/config/index.js.tmpl | 10 +++++- templates/react/src/views/account.js | 9 +++++ templates/react/src/views/home.js | 9 +++++ 8 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 templates/react/public/index.html.tmpl create mode 100644 templates/react/src/views/account.js create mode 100644 templates/react/src/views/home.js diff --git a/config/react.go b/config/react.go index b1207b861..6cfcd9349 100644 --- a/config/react.go +++ b/config/react.go @@ -16,9 +16,16 @@ type reactAccount struct { Enabled bool Required bool } + +type reactView struct { + Path string + Component string +} + type React struct { App reactApp Account reactAccount Header reactHeader Sidenav reactSidenav + Views []reactView } diff --git a/templates/commit0/commit0.tmpl b/templates/commit0/commit0.tmpl index 71a4a9ff0..e2266aefa 100644 --- a/templates/commit0/commit0.tmpl +++ b/templates/commit0/commit0.tmpl @@ -28,5 +28,9 @@ react: required: false sidenav: enabled: true - + views: + - path: /account + component: account + - path: / + component: home services: diff --git a/templates/react/public/index.html.tmpl b/templates/react/public/index.html.tmpl new file mode 100644 index 000000000..b25f35486 --- /dev/null +++ b/templates/react/public/index.html.tmpl @@ -0,0 +1,43 @@ + + + + + + + + + + + + + {{ .React.App.Name }} + + + +
+ + + diff --git a/templates/react/src/App.js b/templates/react/src/App.js index d734e7173..dfc660513 100644 --- a/templates/react/src/App.js +++ b/templates/react/src/App.js @@ -1,21 +1,24 @@ import React from 'react'; import { BrowserRouter as Router, Switch, Route } from "react-router-dom"; import Layout from 'components/layout'; +import config from 'config'; + +const renderView = (view) => { + return ( + + ) +} export default function App() { + + return ( - - a - - - b - - - c - + { + config.views && config.views.map(renderView) + } diff --git a/templates/react/src/config/index.js b/templates/react/src/config/index.js index c4006e493..f9d555762 100644 --- a/templates/react/src/config/index.js +++ b/templates/react/src/config/index.js @@ -11,5 +11,15 @@ export default { }, sidenav: { enabled: true, - } + }, + views: [ + { + path: '/account', + component: 'account', + }, + { + path: '/', + component: 'home', + }, + ], } diff --git a/templates/react/src/config/index.js.tmpl b/templates/react/src/config/index.js.tmpl index 710a0a554..832321826 100644 --- a/templates/react/src/config/index.js.tmpl +++ b/templates/react/src/config/index.js.tmpl @@ -11,5 +11,13 @@ export default { }, sidenav: { enabled: {{ .React.Sidenav.Enabled }}, - } + }, + views: [ + {{ range .React.Views }} + { + path: '{{ .Path }}', + component: '{{ .Component }}', + }, + {{ end }} + ], } diff --git a/templates/react/src/views/account.js b/templates/react/src/views/account.js new file mode 100644 index 000000000..86177f2cb --- /dev/null +++ b/templates/react/src/views/account.js @@ -0,0 +1,9 @@ +import React from 'react'; + +export default function Account() { + return ( +
+ Account +
+ ); +} diff --git a/templates/react/src/views/home.js b/templates/react/src/views/home.js new file mode 100644 index 000000000..ef991146f --- /dev/null +++ b/templates/react/src/views/home.js @@ -0,0 +1,9 @@ +import React from 'react'; + +export default function Home() { + return ( +
+ Home +
+ ); +}