..
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171 | import React, { useEffect } from 'react';
import styled from 'styled-components';
import { IoLogOutOutline } from 'react-icons/io5';
import { useAuth, EpisodeCard, WatchingAnilist } from '../index';
import { SiAnilist } from 'react-icons/si';
import { CgProfile } from 'react-icons/cg';
import { useNavigate } from 'react-router-dom';
import { FiSettings } from 'react-icons/fi';
const TopContainer = styled.div`
display: flex;
flex-direction: column;
align-items: stretch;
width: 100%;
gap: 1rem;
@media (min-width: 1000px) {
flex-direction: row;
justify-content: space-between;
}
`;
const UserInfoContainer = styled.div`
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
`;
const ProfileContainer = styled.div`
position: relative;
padding: 0.5rem;
background-color: var(--global-div-tr);
border-radius: var(--global-border-radius);
text-align: center;
font-size: 0.9rem;
flex: 1;
justify-content: center;
align-items: center;
p {
margin: 0.75rem;
}
img {
border-radius: var(--global-border-radius);
width: 100px;
}
`;
const PreferencesContainer = styled.div`
max-width: 80rem;
margin: auto;
padding: 0.25rem;
`;
const Loginbutton = styled.div`
border-radius: var(--global-border-radius);
display: flex;
cursor: pointer;
padding: 0.75rem;
justify-content: center;
align-items: center;
background-color: var(--global-div);
color: var(--global-text);
transition: 0.1s ease-in-out;
width: 10rem; // Fixed width
margin: 0 auto; // Center horizontally
&:hover,
&:active,
&:focus {
transform: scale(1.025);
}
&:active {
transform: scale(0.975);
}
.svg-wrapper {
margin-bottom: -0.2rem;
margin-left: 0.5rem;
font-size: 1.25rem;
}
`;
// Profile component
export const Profile: React.FC = () => {
const navigate = useNavigate();
const { isLoggedIn, userData, login, logout } = useAuth();
// Profile Page Document Title
useEffect(() => {
document.title =
isLoggedIn && userData ? `${userData.name} | Profile` : 'Profile';
}, [isLoggedIn, userData]);
const handleSettingsClick = () => {
navigate('/profile/settings');
};
return (
<PreferencesContainer>
<TopContainer>
<ProfileContainer>
{/* <Loginbutton
onClick={handleSettingsClick}
style={{
position: 'absolute',
top: '0.5rem',
right: '0.5rem',
maxWidth: '2.25rem',
}}
>
<FiSettings size={22} />
</Loginbutton> */}
{isLoggedIn && userData ? (
<>
<img
src={userData.avatar.large}
alt={`${userData.name}'s avatar`}
/>
<p>
Welcome, <b>{userData.name}</b>
</p>
{userData.statistics && (
<>
<p>
Anime watched: <b>{userData.statistics.anime.count}</b>
</p>
<p>
Total episodes watched:{' '}
<b>{userData.statistics.anime.episodesWatched}</b>
</p>
<p>
Total minutes watched:{' '}
<b>{userData.statistics.anime.minutesWatched}</b>
</p>
<p>
Average score:{' '}
<b>{userData.statistics.anime.meanScore.toFixed(2)}</b>
</p>
</>
)}
<Loginbutton onClick={logout}>
<b>Log out </b>
<span className='svg-wrapper'>
<IoLogOutOutline />
</span>
</Loginbutton>
</>
) : (
<UserInfoContainer>
<CgProfile size={'5rem'} style={{ marginBottom: '1rem' }} />
<p>Guest</p>
<p>Please log in to view your profile and AniList</p>
<a onClick={login}>
<Loginbutton>
<b>Log in with </b>
<span className='svg-wrapper'>
<SiAnilist />
</span>
</Loginbutton>
</a>
</UserInfoContainer>
)}
</ProfileContainer>
</TopContainer>
<EpisodeCard />
<WatchingAnilist />
</PreferencesContainer>
);
};
export default Profile;
|
|