feat: showing service class name in browser tab and on top of the frontend page

This commit is contained in:
Mose Müller 2024-07-04 12:19:19 +02:00
parent 6f3910efd0
commit 639161d373
2 changed files with 9 additions and 2 deletions

View File

@ -46,6 +46,7 @@ const reducer = (state: State, action: Action): State => {
}; };
const App = () => { const App = () => {
const [state, dispatch] = useReducer(reducer, null); const [state, dispatch] = useReducer(reducer, null);
const [serviceName, setServiceName] = useState(null);
const [webSettings, setWebSettings] = useState<Record<string, WebSetting>>({}); const [webSettings, setWebSettings] = useState<Record<string, WebSetting>>({});
const [isInstantUpdate, setIsInstantUpdate] = useState(false); const [isInstantUpdate, setIsInstantUpdate] = useState(false);
const [showSettings, setShowSettings] = useState(false); const [showSettings, setShowSettings] = useState(false);
@ -72,7 +73,12 @@ const App = () => {
// Fetch data from the API when the client connects // Fetch data from the API when the client connects
fetch(`http://${hostname}:${port}/service-properties`) fetch(`http://${hostname}:${port}/service-properties`)
.then((response) => response.json()) .then((response) => response.json())
.then((data: State) => dispatch({ type: 'SET_DATA', data })); .then((data: State) => {
dispatch({ type: 'SET_DATA', data });
setServiceName(data.name);
document.title = data.name; // Setting browser tab title
});
fetch(`http://${hostname}:${port}/web-settings`) fetch(`http://${hostname}:${port}/web-settings`)
.then((response) => response.json()) .then((response) => response.json())
.then((data: Record<string, WebSetting>) => setWebSettings(data)); .then((data: Record<string, WebSetting>) => setWebSettings(data));
@ -149,7 +155,7 @@ const App = () => {
<> <>
<Navbar expand={false} bg="primary" variant="dark" fixed="top"> <Navbar expand={false} bg="primary" variant="dark" fixed="top">
<Container fluid> <Container fluid>
<Navbar.Brand>Data Service App</Navbar.Brand> <Navbar.Brand>{serviceName}</Navbar.Brand>
<Navbar.Toggle aria-controls="offcanvasNavbar" onClick={handleShowSettings} /> <Navbar.Toggle aria-controls="offcanvasNavbar" onClick={handleShowSettings} />
</Container> </Container>
</Navbar> </Navbar>

View File

@ -2,6 +2,7 @@ import { SerializedValue } from '../components/GenericComponent';
export type State = { export type State = {
type: string; type: string;
name: string;
value: Record<string, SerializedValue> | null; value: Record<string, SerializedValue> | null;
readonly: boolean; readonly: boolean;
doc: string | null; doc: string | null;