improvements

This commit is contained in:
Alex Zinn
2025-08-31 18:09:07 -04:00
parent b6717e0cb1
commit ae7f3989fc
49 changed files with 838 additions and 91 deletions

View File

@@ -1,47 +1,44 @@
import {useAppSelector, useAppDispatch} from 'hooks/store';
import {WebSocketStatusViewComponent, LoginForm} from './components';
import AuthenticationService from './services/authentication.service';
import {useEffect, useState} from 'react';
import {authenticationActions, selectError} from 'store/slices/Authentication.slice';
import {authenticationActions, selectError, selectIsAuthenticated, selectCredentials} from 'store/slices/Authentication.slice';
import hostService from 'services/url.service';
import LoggerFactory from './services/logger/LoggerFactory';
import Router from 'routers/router';
import PCastApiService from './services/pcast-api.service';
import { ApplicationCredentials } from '@techniker-me/pcast-api';
export default function App() {
const dispatch = useAppDispatch();
const [isInitialized, setIsInitialized] = useState(false);
const error = useAppSelector(selectError);
const credentials = useAppSelector(selectCredentials);
const isAuthenticated = useAppSelector(selectIsAuthenticated);
useEffect(() => {
// Initialize logger after all modules are loaded to avoid circular dependencies
LoggerFactory.applyLoggerConfig();
// Set WebSocket URI only once during initialization
if (!isInitialized) {
AuthenticationService.setWebSocketUri(hostService.getWebSocketUrl());
setIsInitialized(true);
AuthenticationService.status?.subscribe(status => dispatch(authenticationActions.setStatus(status)));
}
// Subscribe to WebSocket status changes
AuthenticationService.status?.subscribe(status =>
dispatch(authenticationActions.setStatus(status))
);
}, [dispatch, isInitialized]);
const error = useAppSelector(selectError);
useEffect(() => {
if (credentials.applicationId && credentials.secret && isAuthenticated) {
const appCredentials: ApplicationCredentials = {
id: credentials.applicationId,
secret: credentials.secret
};
PCastApiService.initialize(hostService.getPcastBaseUrlOrigin(), appCredentials);
}
}, [credentials, isAuthenticated]);
return (
<>
{error && <div>{error}</div>}
<div
style={{
width: '200px',
height: '100px',
display: 'flex',
flexDirection: 'column',
margin: 'auto'
}}>
<WebSocketStatusViewComponent />
<LoginForm />
</div>
<Router />
</>
);
}