Skip to content

Commit 97b955a

Browse files
authored
Merge pull request #27 from dgomie/dashboard-styling
Dashboard styling
2 parents bd3befa + 3ae5426 commit 97b955a

File tree

7 files changed

+165
-34
lines changed

7 files changed

+165
-34
lines changed

src/app/dashboard/dashboard.module.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@
3737
padding: .5rem;
3838
}
3939

40+
.desktopWelcome {
41+
display: flex;
42+
}
43+
4044
@media (max-width: 768px) {
4145
.buttonContainer {
4246
max-width: 100%;
4347
}
48+
49+
.desktopWelcome {
50+
display: none;
51+
}
4452
}
4553

4654
@media (min-width: 768px) {
@@ -55,4 +63,8 @@
5563
right: 4rem; /* Adjust the distance from the right */
5664
z-index: 1000; /* Ensure it stays above other elements */
5765
}
66+
67+
.mobileHeader {
68+
display: none;
69+
}
5870
}

src/app/dashboard/page.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
'use client';
22

3-
import React, { useContext } from 'react';
3+
import React, { useContext, useEffect } from 'react';
44
import withAuth from '../../hoc/withAuth';
55
import { AuthContext } from '@/context/AuthContext';
66
import { useRouter } from 'next/navigation';
77
import styles from './dashboard.module.css';
88
import DashboardFeed from '@/components/dashboardFeed/DashboardFeed';
99
import BubbleMenu from '@/components/bubbleMenu/BubbleMenu';
10+
import { DashboardHeader } from '@/components/dashboardHeader/DashboardHeader';
11+
import Image from 'next/image';
1012

1113
const Dashboard = () => {
1214
const { currentUser } = useContext(AuthContext);
13-
const router = useRouter();
1415

1516
const handleButtonClick = (location) => {
1617
router.push(location);
1718
};
1819

1920
return (
2021
<div className={styles.mainContainer}>
22+
<div className={styles.mobileHeader}>
23+
<DashboardHeader currentUserImage={currentUser.profileImg} />
24+
</div>
2125
<div className={styles.dashboardContainer}>
2226
{currentUser && (
23-
<div className={styles.welcomeMessage}>
24-
Welcome, {currentUser.username}!
27+
<div className={styles.desktopWelcome}>
28+
<Image
29+
src={currentUser.profileImg}
30+
width={50}
31+
height={50}
32+
alt="User profile image"
33+
style={{ borderRadius: '50%' }}
34+
/>
35+
<div className={styles.welcomeMessage}>
36+
Welcome, {currentUser.username}!
37+
</div>
2538
</div>
2639
)}
2740
<DashboardFeed currentUserId={currentUser.uid} />

src/app/legions/Legions.module.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
margin: 0 0 5rem;
1717
}
1818

19+
.title {
20+
font-size: 1.5rem;
21+
font-weight: bold;
22+
text-align: center;
23+
margin: 1rem 0 0 0;
24+
}
25+
1926
@media (min-width: 768px) {
2027
.mainContainer {
2128
display: flex;
@@ -25,4 +32,8 @@
2532
.legionsContainer {
2633
width: 60%;
2734
}
35+
36+
.mobileHeader {
37+
display: none;
38+
}
2839
}

src/app/legions/page.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import Loader from '@/components/loader/Loader';
88
import styles from './Legions.module.css';
99
import withAuth from '@/hoc/withAuth';
1010
import Button from '@/components/button/Button';
11+
import { DashboardHeader } from '@/components/dashboardHeader/DashboardHeader';
1112

12-
const Legions = () => {
13+
const Legions = ({ currentUser }) => {
1314
const [legions, setLegions] = useState([]);
1415
const [lastVisible, setLastVisible] = useState(null);
1516
const [loading, setLoading] = useState(false);
@@ -56,32 +57,39 @@ const Legions = () => {
5657
};
5758

5859
return (
59-
<div className={styles.mainContainer}>
60-
<div className={styles.legionsContainer}>
61-
{legions.map((legion, index) => (
62-
<DashboardCard
63-
key={legion.id}
64-
legionName={legion.legionName}
65-
legionDescription={legion.legionDescription}
66-
players={legion.players}
67-
maxNumPlayers={legion.maxNumPlayers}
68-
numRounds={legion.numRounds}
69-
onClick={() => {
70-
handleCardClick(legion.id);
71-
}}
72-
/>
73-
))}
74-
{loading && <Loader />}
75-
{!loading && hasMore && (
76-
<Button onClick={loadMoreLegions} variant="transparentWhite">
77-
Load More Legions
78-
</Button>
79-
)}
80-
{!loading && !hasMore && (
81-
<div className={styles.noneLeft}>No more legions left to load</div>
82-
)}
60+
<>
61+
<div className={styles.mobileHeader}>
62+
<DashboardHeader currentUserImage={currentUser.profileImg} />
8363
</div>
84-
</div>
64+
<div className={styles.title}>Explore Active Legions</div>
65+
66+
<div className={styles.mainContainer}>
67+
<div className={styles.legionsContainer}>
68+
{legions.map((legion, index) => (
69+
<DashboardCard
70+
key={legion.id}
71+
legionName={legion.legionName}
72+
legionDescription={legion.legionDescription}
73+
players={legion.players}
74+
maxNumPlayers={legion.maxNumPlayers}
75+
numRounds={legion.numRounds}
76+
onClick={() => {
77+
handleCardClick(legion.id);
78+
}}
79+
/>
80+
))}
81+
{loading && <Loader />}
82+
{!loading && hasMore && (
83+
<Button onClick={loadMoreLegions} variant="transparentWhite">
84+
Load More Legions
85+
</Button>
86+
)}
87+
{!loading && !hasMore && (
88+
<div className={styles.noneLeft}>No more legions left to load</div>
89+
)}
90+
</div>
91+
</div>
92+
</>
8593
);
8694
};
8795

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use client'; // Ensure this is a client-side component
2+
3+
import React from 'react';
4+
import { useRouter } from 'next/navigation'; // Use next/navigation for client-side routing
5+
import styles from './DashboardHeader.module.css';
6+
import Image from 'next/image';
7+
8+
export const DashboardHeader = ({ currentUserImage }) => {
9+
const router = useRouter(); // Initialize the router
10+
11+
const handleLogoClick = () => {
12+
if (router) {
13+
router.push('/dashboard'); // Navigate to /dashboard
14+
}
15+
};
16+
17+
const handleIconClick = () => {
18+
if (router) {
19+
router.push('/profile');
20+
}
21+
};
22+
23+
return (
24+
<div className={styles.mainContainer}>
25+
<Image
26+
src={'/img/navlogo.svg'}
27+
width={100}
28+
height={100}
29+
alt="Legion of Tones Logo"
30+
onClick={handleLogoClick} // Add the click handler
31+
/>
32+
<div className={styles.imageContainer}>
33+
<Image
34+
src={currentUserImage}
35+
width={50}
36+
height={50}
37+
alt="user profile"
38+
onClick={handleIconClick}
39+
style={{borderRadius: '50%'}}
40+
/>
41+
</div>
42+
</div>
43+
);
44+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.mainContainer {
2+
background: linear-gradient(to right, #57bacb, #e372ed);
3+
width: 100vw;
4+
height: 4rem;
5+
display: flex;
6+
padding: 1rem;
7+
justify-content: space-between;
8+
align-items: center;
9+
}
10+
11+
.imageContainer {
12+
border-radius: 50%;
13+
}

src/components/login/Login.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,40 @@ const Login = () => {
3636
// Request notification permission and get FCM token
3737
const permissionGranted = await requestNotificationPermission();
3838
if (permissionGranted) {
39-
const fcmToken = await getFcmToken();
40-
if (fcmToken) {
41-
const userDocRef = doc(db, 'users', user.uid); // Create a reference to the user's Firestore document
42-
await updateDoc(userDocRef, { fcmToken }); // Update the document with the FCM token
39+
const newFcmToken = await getFcmToken();
40+
if (newFcmToken) {
41+
const userDocRef = doc(db, 'users', user.uid); // Reference to the user's Firestore document
42+
43+
// Retrieve the old FCM token from the user's document
44+
const userDocSnap = await userDocRef.get();
45+
const oldFcmToken = userDocSnap.exists()
46+
? userDocSnap.data().fcmToken
47+
: null;
48+
49+
// Update the user's FCM token
50+
await updateDoc(userDocRef, { fcmToken: newFcmToken });
51+
52+
if (oldFcmToken) {
53+
// Query all legions where the old FCM token exists in the playerTokens array
54+
const legionsQuery = db
55+
.collection('legions')
56+
.where('playerTokens', 'array-contains', oldFcmToken)
57+
.where('isActive', '==', true);
58+
const legionsSnapshot = await legionsQuery.get();
59+
60+
// Update each legion document
61+
const batch = db.batch();
62+
legionsSnapshot.forEach((doc) => {
63+
const legionRef = doc.ref;
64+
const updatedPlayerTokens = doc
65+
.data()
66+
.playerTokens.map((token) =>
67+
token === oldFcmToken ? newFcmToken : token
68+
);
69+
batch.update(legionRef, { playerTokens: updatedPlayerTokens });
70+
});
71+
await batch.commit();
72+
}
4373
} else {
4474
console.warn('Failed to retrieve FCM token.');
4575
}

0 commit comments

Comments
 (0)