File size: 1,355 Bytes
ba1b267
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// src/components/Header.tsx
import React from 'react';
import { Link, useNavigate } from 'react-router-dom';

const Header: React.FC = () => {
    const token = localStorage.getItem('token');
    const navigate = useNavigate();

    const logout = () => {
        localStorage.removeItem('token');
        navigate('/login');
    };

    return (
        <header className="bg-gray-800 text-white p-4">
            <nav className="container mx-auto flex justify-between">
                <Link to="/" className="text-xl font-bold">Sentiment Tool</Link>
                <div className="space-x-4">
                    {token ? (
                        <>
                            <Link to="/analyze">Analyze</Link>
                            <Link to="/batch">Batch Analyze</Link>
                            <Link to="/history">History</Link>
                            <Link to="/profile">Profile</Link>
                            <button onClick={logout} className="text-red-400">Logout</button>
                        </>
                    ) : (
                        <>
                            <Link to="/login">Login</Link>
                            <Link to="/register">Register</Link>
                        </>
                    )}
                </div>
            </nav>
        </header>
    );
};

export default Header;