Skip to content

Commit dbbd5f7

Browse files
committed
Moved profile to modal.
1 parent b41a05d commit dbbd5f7

File tree

6 files changed

+97
-112
lines changed

6 files changed

+97
-112
lines changed
File renamed without changes.

frontend/src/modal/Profile.tsx

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import {
2+
IonModal,
3+
IonHeader,
4+
IonToolbar,
5+
IonButtons,
6+
IonButton,
7+
IonTitle,
8+
IonContent,
9+
IonAvatar,
10+
IonCard,
11+
IonCardHeader,
12+
IonCardSubtitle,
13+
IonCardTitle,
14+
} from "@ionic/react"
15+
import { useQuery } from "@tanstack/react-query"
16+
import { hourglass, library, eye } from "ionicons/icons"
17+
import { IProfile, getProfile } from "../api"
18+
import { useAuth } from "../hooks"
19+
import { FullpageInfo, FullpageLoading, StatDisplay } from "../components"
20+
import "./Profile.css"
21+
22+
const ProfileContent: React.FC = () => {
23+
const [{ username, token }] = useAuth()
24+
25+
const { data, isLoading, isError } = useQuery<IProfile>({
26+
queryKey: [`${username}profile`],
27+
queryFn: () => getProfile(username ?? "", token ?? ""),
28+
staleTime: Infinity,
29+
})
30+
31+
if (!username || isError) {
32+
return <FullpageInfo text="An error occurred when loading information." />
33+
}
34+
35+
if (isLoading) {
36+
return <FullpageLoading />
37+
}
38+
39+
const yearJoined = new Date(data?.registered ?? 0).getFullYear()
40+
41+
return (
42+
<IonContent className="ion-padding">
43+
<div className="avatar-background" style={{ backgroundImage: `url(${data?.banner_url})` }}>
44+
<div className="profile-column">
45+
<IonAvatar>
46+
<img src={data?.avatar_url} />
47+
</IonAvatar>
48+
</div>
49+
<IonCard style={{ textAlign: "center", marginBottom: 50 }}>
50+
<IonCardHeader>
51+
<IonCardTitle>{data?.username}</IonCardTitle>
52+
<IonCardSubtitle>{data?.name}</IonCardSubtitle>
53+
</IonCardHeader>
54+
</IonCard>
55+
<br />
56+
</div>
57+
<div>
58+
<StatDisplay
59+
items={[
60+
{ icon: hourglass, value: yearJoined, label: "Registered" },
61+
{ icon: library, value: data?.num_collection, label: "Collected" },
62+
{ icon: eye, value: data?.num_wantlist, label: "Wanted" },
63+
]}
64+
/>
65+
</div>
66+
</IonContent>
67+
)
68+
}
69+
70+
const ProfileModal: React.FC<{
71+
open: boolean
72+
onClose: () => void
73+
}> = ({ open, onClose }) => (
74+
<IonModal isOpen={open}>
75+
<IonHeader>
76+
<IonToolbar>
77+
<IonButtons slot="start">
78+
<IonButton onClick={() => onClose()}>Close</IonButton>
79+
</IonButtons>
80+
<IonTitle>Profile</IonTitle>
81+
</IonToolbar>
82+
</IonHeader>
83+
<ProfileContent />
84+
</IonModal>
85+
)
86+
87+
export default ProfileModal

frontend/src/modal/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
export { default as ViewAlbumDetails } from "./ViewAlbumDetails"
21
export { default as BarcodeScanDialog } from "./Barcode"
2+
export { default as ProfileModal } from "./Profile"
3+
export { default as ViewAlbumDetails } from "./ViewAlbumDetails"

frontend/src/pages/Collection.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query"
2020
import { filterOutline, personOutline, pricetagOutline, timeOutline, listOutline, gridOutline } from "ionicons/icons"
2121
import { IReleaseSet, IReleases, getCollectionAndWants } from "../api"
2222
import { FullpageLoading, AlbumGrid, FullpageInfo, AlbumListGroups } from "../components"
23-
import { ViewAlbumDetails } from "../modal"
23+
import { ProfileModal, ViewAlbumDetails } from "../modal"
2424
import { useAuth, useSettings } from "../hooks"
2525
import { masterSort } from "../utils"
2626
import { IReleaseTuple } from "../types"
@@ -67,6 +67,7 @@ const CollectionPage: React.FC = () => {
6767
const [layout, setLayout] = useSettings<"grid" | "list">("collectionLayout", "grid")
6868
const [modalInfo, setModalInfo] = useState<IReleases | undefined>(undefined)
6969
const [loading, setLoading] = useState<{ page: number; pages: number }>({ page: 0, pages: 0 })
70+
const [profileModal, setProfileModal] = useState<boolean>(false)
7071
const [viewState, setViewState] = useState<"collection" | "want">("collection")
7172
const [dataSorted, setDataSorted] = useState<{
7273
collected: IReleaseTuple
@@ -153,6 +154,11 @@ const CollectionPage: React.FC = () => {
153154
<IonPage>
154155
<IonHeader>
155156
<IonToolbar>
157+
<IonButtons slot="secondary">
158+
<IonButton onClick={() => setProfileModal(true)}>
159+
<IonIcon slot="icon-only" icon={personOutline} />
160+
</IonButton>
161+
</IonButtons>
156162
<IonButtons slot="primary">
157163
<IonButton
158164
onClick={() => {
@@ -241,6 +247,7 @@ const CollectionPage: React.FC = () => {
241247
/>
242248
)}
243249
</IonContent>
250+
<ProfileModal open={profileModal} onClose={() => setProfileModal(false)} />
244251
</IonPage>
245252
)
246253
}

frontend/src/pages/Profile.tsx

Lines changed: 0 additions & 109 deletions
This file was deleted.

frontend/src/pages/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export { default as CollectionPage } from "./Collection"
2-
export { default as ProfilePage } from "./Profile"
32
export { default as SearchPage } from "./Search"
43
export { default as SettingsPage } from "./Settings"

0 commit comments

Comments
 (0)