v0.7.1 minor bug fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "jama-frontend",
|
||||
"version": "0.7.0",
|
||||
"version": "0.7.1",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
|
||||
@@ -20,11 +20,20 @@ function ProtectedRoute({ children }) {
|
||||
|
||||
function AuthRoute({ children }) {
|
||||
const { user, loading, mustChangePassword } = useAuth();
|
||||
// Always show login in light mode regardless of user's saved theme preference
|
||||
document.documentElement.setAttribute('data-theme', 'light');
|
||||
if (loading) return null;
|
||||
if (user && !mustChangePassword) return <Navigate to="/" replace />;
|
||||
return children;
|
||||
}
|
||||
|
||||
function RestoreTheme() {
|
||||
// Called when entering a protected route — restore the user's saved theme
|
||||
const saved = localStorage.getItem('jama-theme') || 'light';
|
||||
document.documentElement.setAttribute('data-theme', saved);
|
||||
return null;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
@@ -34,7 +43,7 @@ export default function App() {
|
||||
<Routes>
|
||||
<Route path="/login" element={<AuthRoute><Login /></AuthRoute>} />
|
||||
<Route path="/change-password" element={<ChangePassword />} />
|
||||
<Route path="/" element={<ProtectedRoute><Chat /></ProtectedRoute>} />
|
||||
<Route path="/" element={<ProtectedRoute><RestoreTheme /><Chat /></ProtectedRoute>} />
|
||||
<Route path="*" element={<Navigate to="/" replace />} />
|
||||
</Routes>
|
||||
</SocketProvider>
|
||||
|
||||
@@ -3,10 +3,6 @@ import ReactDOM from 'react-dom/client';
|
||||
import App from './App.jsx';
|
||||
import './index.css';
|
||||
|
||||
// Apply saved theme immediately to avoid flash of wrong theme
|
||||
const savedTheme = localStorage.getItem('jama-theme') || 'light';
|
||||
document.documentElement.setAttribute('data-theme', savedTheme);
|
||||
|
||||
// Register service worker
|
||||
if ('serviceWorker' in navigator) {
|
||||
window.addEventListener('load', () => {
|
||||
|
||||
@@ -194,9 +194,21 @@ export default function Chat() {
|
||||
});
|
||||
};
|
||||
|
||||
// Session displaced: another login on the same device type kicked us out
|
||||
const handleSessionDisplaced = ({ device: displacedDevice }) => {
|
||||
// Only act if it's our device slot that was taken over
|
||||
// (The server emits to user room so all sockets of this user receive it;
|
||||
// our socket's device is embedded in the socket but we can't read it here,
|
||||
// so we force logout unconditionally — the new session will reconnect cleanly)
|
||||
localStorage.removeItem('tc_token');
|
||||
sessionStorage.removeItem('tc_token');
|
||||
window.dispatchEvent(new CustomEvent('jama:session-displaced'));
|
||||
};
|
||||
|
||||
socket.on('group:new', handleGroupNew);
|
||||
socket.on('group:deleted', handleGroupDeleted);
|
||||
socket.on('group:updated', handleGroupUpdated);
|
||||
socket.on('session:displaced', handleSessionDisplaced);
|
||||
|
||||
// Bug B fix: on reconnect, reload groups to catch any messages missed while offline
|
||||
const handleReconnect = () => { loadGroups(); };
|
||||
@@ -217,6 +229,7 @@ export default function Chat() {
|
||||
socket.off('group:deleted', handleGroupDeleted);
|
||||
socket.off('group:updated', handleGroupUpdated);
|
||||
socket.off('connect', handleReconnect);
|
||||
socket.off('session:displaced', handleSessionDisplaced);
|
||||
document.removeEventListener('visibilitychange', handleVisibility);
|
||||
};
|
||||
}, [socket, toast, activeGroupId, user, isMobile, loadGroups]);
|
||||
|
||||
Reference in New Issue
Block a user