-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Donation Leaderboard Page #2981
Open
anshg1214
wants to merge
10
commits into
master
Choose a base branch
from
add-donations-page
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
426ed94
feat: Add Donations Page
anshg1214 f59367a
feat: Add endpoints for donors page
anshg1214 2e1eb3b
fix: return playlist count as dictionary
anshg1214 5f6962c
fix: listen count is not being fetched properly
anshg1214 ef311fc
fix: Hide Listen Count and Playlist Count if the value is not defined
anshg1214 1f969e3
fix: PEP8
anshg1214 7be967a
style: Improve Donor Card Design
anshg1214 4ff5c92
feat: Move Donor page link to bottom of sidebar
anshg1214 1c38c1a
style: Fix Donation date styling
anshg1214 af8e24b
feat: redirect to musicbrainz profile if user not a lb user
anshg1214 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
.donor-card { | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
border: 1px solid #e2e8f0; | ||
padding: 1rem; | ||
margin: 1.5rem 0; | ||
@media (min-width: 640px) { | ||
flex-direction: row; | ||
align-items: center; | ||
} | ||
|
||
.donor-info { | ||
display: flex; | ||
margin-bottom: 1rem; | ||
flex-direction: column; | ||
|
||
@media (min-width: 640px) { | ||
margin-bottom: 0; | ||
} | ||
|
||
.donation-user { | ||
font-weight: 600; | ||
font-size: 1.75rem; | ||
margin-bottom: 0.5rem; | ||
.donor-name { | ||
font-weight: 300 !important; | ||
&:hover, | ||
&:visited { | ||
color: #353070 !important; | ||
} | ||
} | ||
} | ||
|
||
.donation-date { | ||
display: flex; | ||
color: #6b7280; | ||
gap: 10px; | ||
align-items: baseline; | ||
} | ||
} | ||
|
||
.donor-stats { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: flex-end; | ||
|
||
.donation-amount { | ||
font-weight: 600; | ||
font-size: 1.75rem; | ||
margin-bottom: 0.5rem; | ||
} | ||
|
||
.recent-listens { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 0.5rem; | ||
|
||
.listen-item { | ||
display: flex; | ||
align-items: center; | ||
color: #6b7280; | ||
background-color: #edf2f7; | ||
padding: 0.25rem 0.75rem; | ||
border-radius: 9999px; | ||
gap: 0.5rem; | ||
font-weight: 300; | ||
|
||
&:hover, | ||
&:visited { | ||
color: #6b7280 !important; | ||
} | ||
} | ||
} | ||
} | ||
|
||
&:hover { | ||
background-color: @table-bg-hover; | ||
} | ||
} | ||
|
||
#donors { | ||
margin-top: 1.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import * as React from "react"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { | ||
faCalendar, | ||
faListAlt, | ||
faMusic, | ||
} from "@fortawesome/free-solid-svg-icons"; | ||
import { Link, useLocation, useSearchParams } from "react-router-dom"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import Pill from "../components/Pill"; | ||
import { formatListenCount } from "../explore/fresh-releases/utils"; | ||
import Pagination from "../common/Pagination"; | ||
import { getObjectForURLSearchParams } from "../utils/utils"; | ||
import { RouteQuery } from "../utils/Loader"; | ||
import Loader from "../components/Loader"; | ||
|
||
type DonorLoaderData = { | ||
data: { | ||
id: number; | ||
donated_at: string; | ||
donation: number; | ||
currency: "usd" | "eur"; | ||
musicbrainz_id: string; | ||
is_listenbrainz_user: boolean; | ||
listenCount: number; | ||
playlistCount: number; | ||
}[]; | ||
totalPageCount: number; | ||
}; | ||
|
||
function Donors() { | ||
const location = useLocation(); | ||
const [searchParams, setSearchParams] = useSearchParams(); | ||
const searchParamsObj = getObjectForURLSearchParams(searchParams); | ||
const currPageNoStr = searchParams.get("page") || "1"; | ||
const currPageNo = parseInt(currPageNoStr, 10); | ||
const sort = searchParams.get("sort") || "date"; | ||
|
||
const { data, isLoading } = useQuery<DonorLoaderData>( | ||
RouteQuery( | ||
["donors", currPageNoStr, sort], | ||
`${location.pathname}${location.search}` | ||
) | ||
); | ||
|
||
const { data: donors, totalPageCount = 1 } = data || {}; | ||
|
||
const handleClickPrevious = () => { | ||
setSearchParams({ | ||
...searchParamsObj, | ||
page: Math.max(currPageNo - 1, 1).toString(), | ||
}); | ||
}; | ||
|
||
const handleClickNext = () => { | ||
setSearchParams({ | ||
...searchParamsObj, | ||
page: Math.min(currPageNo + 1, totalPageCount).toString(), | ||
}); | ||
}; | ||
|
||
const handleSortBy = (sortBy: string) => { | ||
if (sortBy === sort) { | ||
return; | ||
} | ||
setSearchParams({ | ||
page: "1", | ||
sort: sortBy, | ||
}); | ||
}; | ||
|
||
return ( | ||
<div role="main" id="donors"> | ||
<div className="listen-header"> | ||
<h2 className="header-with-line">Donations</h2> | ||
<div className="flex" role="group" aria-label="Sort by"> | ||
<Pill | ||
type="secondary" | ||
active={sort === "date"} | ||
onClick={() => handleSortBy("date")} | ||
> | ||
Date | ||
</Pill> | ||
<Pill | ||
type="secondary" | ||
active={sort === "amount"} | ||
onClick={() => handleSortBy("amount")} | ||
> | ||
Amount | ||
</Pill> | ||
</div> | ||
</div> | ||
<Loader isLoading={isLoading}> | ||
{donors?.map((donor) => ( | ||
<div key={donor.id} className="donor-card"> | ||
<div className="donor-info"> | ||
<div className="donation-user"> | ||
{donor.musicbrainz_id && | ||
(donor.is_listenbrainz_user ? ( | ||
<Link | ||
to={`${ | ||
!donor.is_listenbrainz_user && "https://musicbrainz.org" | ||
}/user/${donor.musicbrainz_id}`} | ||
className="donor-name" | ||
> | ||
{donor.musicbrainz_id} | ||
</Link> | ||
) : ( | ||
<Link | ||
to={`https://musicbrainz.org/user/${donor.musicbrainz_id}`} | ||
className="donor-name" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
{donor.musicbrainz_id} | ||
</Link> | ||
))} | ||
</div> | ||
<div className="donation-date"> | ||
<FontAwesomeIcon icon={faCalendar} /> | ||
<span> | ||
Donation Date:{" "} | ||
{new Date(donor.donated_at).toLocaleDateString()} | ||
</span> | ||
</div> | ||
</div> | ||
<div className="donor-stats"> | ||
<p className="donation-amount"> | ||
{donor.currency === "usd" ? "$" : "€"} | ||
{donor.donation} | ||
</p> | ||
{donor.musicbrainz_id && donor.is_listenbrainz_user ? ( | ||
<div className="recent-listens"> | ||
{donor.listenCount ? ( | ||
<Link | ||
className="listen-item" | ||
to={`/user/${donor.musicbrainz_id}/stats/?range=all_time`} | ||
> | ||
<FontAwesomeIcon icon={faMusic} /> | ||
{formatListenCount(donor.listenCount)} Listens | ||
</Link> | ||
) : null} | ||
{donor.playlistCount ? ( | ||
<Link | ||
className="listen-item" | ||
to={`/user/${donor.musicbrainz_id}/playlists/`} | ||
> | ||
<FontAwesomeIcon icon={faListAlt} /> | ||
{formatListenCount(donor.playlistCount)} Playlists | ||
</Link> | ||
) : null} | ||
</div> | ||
) : null} | ||
</div> | ||
</div> | ||
))} | ||
</Loader> | ||
<Pagination | ||
currentPageNo={currPageNo} | ||
totalPageCount={totalPageCount} | ||
handleClickPrevious={handleClickPrevious} | ||
handleClickNext={handleClickNext} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
export default Donors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect this condition is never truthy,aas you are already inside a conditional check of
donor.is_listenbrainz_user ? (...