Files
car/frontend/src/App.jsx

70 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useState, useCallback } from 'react';
import ScheduleView from './components/ScheduleView.jsx';
import CarManagement from './components/CarManagement.jsx';
import TimelineView from './components/TimelineView.jsx';
import useWebSocket from './hooks/useWebSocket.js';
import styles from './App.module.css';
export default function App() {
const [page, setPage] = useState('schedule');
const [reloadKey, setReloadKey] = useState(0);
const handleWsMessage = useCallback((msg) => {
if (msg.type === 'data_changed') {
setReloadKey((k) => k + 1);
}
}, []);
const { status: wsStatus } = useWebSocket(handleWsMessage);
return (
<div className={styles.app}>
<header className={styles.header}>
<div className={styles.headerLeft}>
<span
className={`${styles.wsIndicator} ${styles['wsIndicator_' + wsStatus]}`}
title={
wsStatus === 'connected' ? 'リアルタイム同期: 接続中' :
wsStatus === 'connecting' || wsStatus === 'disconnected' ? 'リアルタイム同期: 再接続中...' :
'リアルタイム同期: 接続失敗'
}
/>
<h1 className={styles.title}>🚗 代車スケジュール管理</h1>
</div>
<nav className={styles.nav}>
<button
className={`${styles.navBtn} ${page === 'schedule' ? styles.active : ''}`}
onClick={() => setPage('schedule')}
>
📅 スケジュール
</button>
<button
className={`${styles.navBtn} ${page === 'timeline' ? styles.active : ''}`}
onClick={() => setPage('timeline')}
>
📊 タイムライン
</button>
<button
className={`${styles.navBtn} ${page === 'cars' ? styles.active : ''}`}
onClick={() => setPage('cars')}
>
🚙 代車管理
</button>
</nav>
</header>
{wsStatus === 'error' && (
<div className={styles.wsError}>
サーバーとの接続が切断されましたページを再読み込みしてください
</div>
)}
<main className={styles.main}>
{page === 'schedule' && <ScheduleView reloadKey={reloadKey} />}
{page === 'timeline' && <TimelineView reloadKey={reloadKey} />}
{page === 'cars' && <CarManagement reloadKey={reloadKey} />}
</main>
</div>
);
}