mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-22 08:58:11 +00:00
base
This commit is contained in:
0
client/admin/main.jsx
Normal file
0
client/admin/main.jsx
Normal file
@@ -1,8 +1,7 @@
|
|||||||
|
import 'core-js/es/string/to-well-formed.js'; // Polyfill for older browsers
|
||||||
import 'core-js/es/string/to-well-formed.js'; //Polyfill for older browsers
|
|
||||||
import './homebrew.less';
|
import './homebrew.less';
|
||||||
import React from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { StaticRouter as Router, Route, Routes, useParams, useSearchParams } from 'react-router';
|
import { BrowserRouter as Router, Routes, Route, useParams, useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
import { updateLocalStorage } from './utils/updateLocalStorage/updateLocalStorageKeys.js';
|
import { updateLocalStorage } from './utils/updateLocalStorage/updateLocalStorageKeys.js';
|
||||||
|
|
||||||
@@ -22,42 +21,46 @@ const WithRoute = ({ el: Element, ...rest })=>{
|
|||||||
return <Element {...rest} {...params} query={queryParams} />;
|
return <Element {...rest} {...params} query={queryParams} />;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Homebrew = (props)=>{
|
const Homebrew = ()=>{
|
||||||
const {
|
// SPA defaults / client-side state
|
||||||
url = '',
|
const [account, setAccount] = useState(null);
|
||||||
version = '0.0.0',
|
const [version] = useState('0.0.0');
|
||||||
account = null,
|
const [config, setConfig] = useState({});
|
||||||
config,
|
const [brew, setBrew] = useState({
|
||||||
brew = {
|
title : '',
|
||||||
title : '',
|
text : '',
|
||||||
text : '',
|
shareId : null,
|
||||||
shareId : null,
|
editId : null,
|
||||||
editId : null,
|
createdAt : null,
|
||||||
createdAt : null,
|
updatedAt : null,
|
||||||
updatedAt : null,
|
lang : ''
|
||||||
lang : ''
|
});
|
||||||
},
|
const [userThemes, setUserThemes] = useState([]);
|
||||||
userThemes,
|
const [brews, setBrews] = useState([]);
|
||||||
brews
|
|
||||||
} = props;
|
|
||||||
|
|
||||||
global.account = account;
|
// Maybe should fetch the data here?
|
||||||
global.version = version;
|
//probably should fetch the object later
|
||||||
global.config = config;
|
// useEffect(() => { fetch('/api/...').then(res => res.json()).then(setBrew) }, []);
|
||||||
|
|
||||||
|
// Set globals if needed (legacy)
|
||||||
|
global.account = account;
|
||||||
|
global.version = version;
|
||||||
|
global.config = config;
|
||||||
|
|
||||||
const backgroundObject = ()=>{
|
const backgroundObject = ()=>{
|
||||||
if(global.config?.deployment || (config?.local && config?.development)){
|
if(config?.deployment || (config?.local && config?.development)) {
|
||||||
const bgText = global.config?.deployment || 'Local';
|
const bgText = config?.deployment || 'Local';
|
||||||
return {
|
return {
|
||||||
backgroundImage : `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='100px' width='200px'><text x='0' y='15' fill='%23fff7' font-size='20'>${bgText}</text></svg>")`
|
backgroundImage : `url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='100px' width='200px'><text x='0' y='15' fill='%23fff7' font-size='20'>${bgText}</text></svg>")`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
updateLocalStorage();
|
updateLocalStorage();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router location={url}>
|
<Router>
|
||||||
<div className={`homebrew${(config?.deployment || config?.local) ? ' deployment' : ''}`} style={backgroundObject()}>
|
<div className={`homebrew${(config?.deployment || config?.local) ? ' deployment' : ''}`} style={backgroundObject()}>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route path='/edit/:id' element={<WithRoute el={EditPage} brew={brew} userThemes={userThemes}/>} />
|
<Route path='/edit/:id' element={<WithRoute el={EditPage} brew={brew} userThemes={userThemes}/>} />
|
||||||
@@ -80,4 +83,4 @@ const Homebrew = (props)=>{
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Homebrew;
|
export default Homebrew;
|
||||||
|
|||||||
9
client/homebrew/main.jsx
Normal file
9
client/homebrew/main.jsx
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { createRoot } from "react-dom/client";
|
||||||
|
import { BrowserRouter } from "react-router-dom";
|
||||||
|
import App from "./App";
|
||||||
|
|
||||||
|
createRoot(document.getElementById("reactRoot")).render(
|
||||||
|
<BrowserRouter>
|
||||||
|
<App />
|
||||||
|
</BrowserRouter>
|
||||||
|
);
|
||||||
@@ -24,6 +24,6 @@
|
|||||||
<body>
|
<body>
|
||||||
<main id="reactRoot"></main>
|
<main id="reactRoot"></main>
|
||||||
|
|
||||||
<script type="module" src="/src/main.jsx"></script>
|
<script type="module" src="/src/homebrewMain.jsx"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
import { createRoot } from "react-dom/client";
|
|
||||||
import App from "./App";
|
|
||||||
|
|
||||||
const root = createRoot(document.getElementById("reactRoot"));
|
|
||||||
root.render(<App />);
|
|
||||||
Reference in New Issue
Block a user