mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-12-05 15:52:55 +01:00
feat: search functionality
This commit is contained in:
1 parent
63ce327458
commit
610b59f4c6
9 files changed
+133
-81
No files matched your search
@@ -1,13 +1,7 @@
|
||||
import { useMemo } from "react";
|
||||
import { AvatarCard } from "../../../components/AvatarCard";
|
||||
import { AvatarControls } from "../../../components/AvatarControls";
|
||||
import { IncrementalLoader } from "../../../components/IncrementalLoader";
|
||||
import { AvatarsList } from "../../../components/AvatarsList";
|
||||
import { Section } from "../../../components/Section";
|
||||
import { api } from "../../../core/api/dynamic";
|
||||
import { useAwait } from "../../../hooks/useAwait";
|
||||
import { useGameStrings } from "../../../hooks/useGameStrings";
|
||||
import { LocaleProvider, useLocale } from "../../../hooks/useLocale";
|
||||
import type { Avatar } from "../../../protos/avatar";
|
||||
import { LocaleProvider } from "../../../hooks/useLocale";
|
||||
|
||||
interface PageProps extends ContentProps {
|
||||
locale: string;
|
||||
@@ -25,57 +19,7 @@ interface ContentProps {
|
||||
skeleton?: boolean;
|
||||
}
|
||||
|
||||
const indexingPattern = /.+_(\d+)$/;
|
||||
|
||||
function Content({}: ContentProps) {
|
||||
const locale = useLocale();
|
||||
const { avatars } = useAwait(() => api.avatars(), "avatars");
|
||||
const profileAvatarEntityStrings = useGameStrings("ProfileAvatarEntity");
|
||||
const groups = useMemo(() => {
|
||||
const groups = new Map<string, Avatar[]>();
|
||||
|
||||
for (const avatar of avatars) {
|
||||
const name =
|
||||
profileAvatarEntityStrings[avatar.stuff_ui!.display_name] ??
|
||||
avatar.stuff_ui!.display_name;
|
||||
|
||||
if (groups.has(name)) {
|
||||
groups.get(name)!.push(avatar);
|
||||
} else {
|
||||
groups.set(name, [avatar]);
|
||||
}
|
||||
}
|
||||
|
||||
return groups;
|
||||
}, []);
|
||||
const ordered = useMemo(() => {
|
||||
const array = Array.from(groups.entries());
|
||||
return array
|
||||
.sort((a, b) => a[0].localeCompare(b[0], locale))
|
||||
.map(([name, avatars]) => ({
|
||||
name,
|
||||
avatars: avatars.sort((a, b) => {
|
||||
const gradeA = a.stuff_ui!.grade;
|
||||
const gradeB = b.stuff_ui!.grade;
|
||||
let diff = gradeA - gradeB;
|
||||
|
||||
if (diff === 0) {
|
||||
const matchesA = a.name.match(indexingPattern);
|
||||
const matchesB = b.name.match(indexingPattern);
|
||||
|
||||
if (matchesA && matchesB) {
|
||||
const indexA = Number(matchesA[1]);
|
||||
const indexB = Number(matchesB[1]);
|
||||
|
||||
diff = indexA - indexB;
|
||||
}
|
||||
}
|
||||
|
||||
return diff;
|
||||
}),
|
||||
}));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Section>
|
||||
@@ -83,14 +27,7 @@ function Content({}: ContentProps) {
|
||||
</Section>
|
||||
|
||||
<Section>
|
||||
<div className="avatars">
|
||||
<IncrementalLoader
|
||||
initial={40}
|
||||
intermediate={10}
|
||||
data={ordered}
|
||||
Component={AvatarCard}
|
||||
/>
|
||||
</div>
|
||||
<AvatarsList />
|
||||
</Section>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -9,14 +9,6 @@ export { getStaticPaths } from "../index.astro";
|
||||
const { locale } = Astro.props;
|
||||
---
|
||||
|
||||
<style is:global>
|
||||
.avatars {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(var(--space-7), 1fr));
|
||||
gap: var(--space-5) var(--space-4);
|
||||
}
|
||||
</style>
|
||||
|
||||
<BaseLayout {locale} accent="gold">
|
||||
<ToolBanner {locale} tool={tools.avatars} slot="pre-app" />
|
||||
|
||||
|
||||
Reference in new issue
Block a user