Skip to content

Commit 7351293

Browse files
authored
Merge pull request #1626 from rslgp/main
PR to include sort by on userstats
2 parents a5eddc1 + afee0fb commit 7351293

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

src/components/UserStats.svelte

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,23 @@
1616
import Notification from "./Notification.svelte";
1717
1818
export let steamUser: ISteamUser;
19-
2019
let tab: string = "addons";
2120
22-
/**
23-
* Changes the view into the selected tab
24-
*/
21+
// Sorting state
22+
let sortType: "latest" | "views" | "subscribers" | "favorites" | "likes" | "dislikes" =
23+
"subscribers";
24+
25+
// Computed visible addons based on sort type
26+
$: visibleAddons = [...steamUser.addons].sort((a, b) => {
27+
if (sortType === "latest") return 0;
28+
if (sortType === "views") return b.views - a.views;
29+
if (sortType === "subscribers") return b.subscribers - a.subscribers;
30+
if (sortType === "favorites") return b.favorites - a.favorites;
31+
if (sortType === "likes") return b.likes - a.likes;
32+
if (sortType === "dislikes") return b.dislikes - a.dislikes;
33+
return 0;
34+
});
35+
2536
function changeTab(e: Event) {
2637
e.preventDefault();
2738
tab = (e.target as HTMLButtonElement).value;
@@ -35,8 +46,12 @@
3546
})}
3647
</h2>
3748
<img src={steamUser.profileImageUrl} class="h-44 my-8 rounded-full" alt="Steam Profile" />
49+
3850
{#if steamUser.addons.length > 0}
39-
<div class="stats stats-vertical lg:stats-horizontal bg-secondary mx-10 text-center shadow-sm">
51+
<!-- Stats summary -->
52+
<div
53+
class="stats stats-vertical lg:stats-horizontal bg-secondary mx-10 text-center shadow-sm"
54+
>
4055
<StatTitle title={$_("stats.views")} faIcon={faEye} value={steamUser.views} />
4156
<StatTitle
4257
title={$_("stats.subscribers")}
@@ -51,6 +66,8 @@
5166
value={steamUser.dislikes}
5267
/>
5368
</div>
69+
70+
<!-- Tab controls -->
5471
<div class="invisible lg:visible my-8">
5572
<button
5673
on:click={changeTab}
@@ -67,16 +84,30 @@
6784
{$_("stats.graph")}
6885
</button>
6986
</div>
87+
7088
{#if tab === "addons"}
89+
<!-- Sort control -->
90+
<div class="controls mb-4">
91+
<label class="mr-2">Sort by:</label>
92+
<select bind:value={sortType} class="btn btn-sm">
93+
<option value="latest">Time</option>
94+
<option value="views">{$_("stats.views")}</option>
95+
<option value="subscribers">{$_("stats.subscribers")}</option>
96+
<option value="favorites">{$_("stats.favorites")}</option>
97+
<option value="likes">{$_("stats.likes")}</option>
98+
<option value="dislikes">{$_("stats.dislikes")}</option>
99+
</select>
100+
</div>
101+
71102
<h2 class="mb-8">
72-
{$_("stats.addonsOf", {
73-
values: { username: steamUser.username },
74-
})}
103+
{$_("stats.addonsOf", { values: { username: steamUser.username } })}
75104
</h2>
105+
106+
<!-- Add-ons grid -->
76107
<div
77108
class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-8 mx-8"
78109
>
79-
{#each steamUser.addons as addon}
110+
{#each visibleAddons as addon}
80111
<Addon
81112
id={addon.id}
82113
title={addon.title}

0 commit comments

Comments
 (0)