mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: start of avatars
This commit is contained in:
1 parent
455679a981
commit
ea412086d4
7 files changed
+72
-15
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
.avatar-card {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
|
||||||
|
.avatar-image {
|
||||||
|
width: 100%;
|
||||||
|
aspect-ratio: 7 / 8;
|
||||||
|
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.avatar-label {
|
||||||
|
max-width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import type { Avatar } from "../../protos/avatar";
|
||||||
|
import { Text } from "../Text";
|
||||||
|
import "./index.css";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
avatar: Avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AvatarCard({ avatar }: Props) {
|
||||||
|
return (
|
||||||
|
<div className="avatar-card">
|
||||||
|
<div
|
||||||
|
className="avatar-image"
|
||||||
|
style={{ backgroundImage: `url(/api/avatars/${avatar.name}.webp)` }}
|
||||||
|
/>
|
||||||
|
<Text className="avatar-label">{avatar.name}</Text>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,19 +1,9 @@
|
|||||||
import { fetchPB } from "@blitzkit/core";
|
import { fetchPB } from "@blitzkit/core";
|
||||||
import { Tank } from "../../protos/tank";
|
import { Avatars } from "../../protos/avatars";
|
||||||
import { TankList } from "../../protos/tank_list";
|
|
||||||
import { Tanks } from "../../protos/tanks";
|
|
||||||
import { AbstractAPI } from "./abstract";
|
import { AbstractAPI } from "./abstract";
|
||||||
|
|
||||||
export class ClientAPI extends AbstractAPI {
|
export class ClientAPI extends AbstractAPI {
|
||||||
tanks() {
|
protected _avatars() {
|
||||||
return fetchPB("/api/tanks/all.pb", Tanks);
|
return fetchPB("/api/avatars/all.pb", Avatars);
|
||||||
}
|
|
||||||
|
|
||||||
tankList() {
|
|
||||||
return fetchPB("/api/tanks/list.pb", TankList);
|
|
||||||
}
|
|
||||||
|
|
||||||
tank(id: string) {
|
|
||||||
return fetchPB(`/api/tanks/${id}.pb`, Tank);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,19 @@
|
|||||||
|
import { AvatarCard } from "../../../components/AvatarCard";
|
||||||
|
import { api } from "../../../core/api/dynamic";
|
||||||
|
import { useAwait } from "../../../hooks/useAwait";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
skeleton?: boolean;
|
skeleton?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Page({ skeleton }: Props) {}
|
export function Page({ skeleton }: Props) {
|
||||||
|
const { avatars } = useAwait(() => api.avatars(), "avatars");
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="avatars">
|
||||||
|
{avatars.map((avatar) => (
|
||||||
|
<AvatarCard key={avatar.name} avatar={avatar} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -7,6 +7,14 @@ export { getStaticPaths } from "../index.astro";
|
|||||||
const { locale } = Astro.props;
|
const { locale } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
|
<style is:global>
|
||||||
|
.avatars {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fill, minmax(var(--space-7), 1fr));
|
||||||
|
gap: var(--space-4);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
<BaseLayout {locale} accent="gold">
|
<BaseLayout {locale} accent="gold">
|
||||||
<Page client:only="react">
|
<Page client:only="react">
|
||||||
<Page skeleton slot="fallback" />
|
<Page skeleton slot="fallback" />
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { api } from "../../../core/api/dynamic";
|
import { api } from "../../../core/api/dynamic";
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const { avatars } = await api.avatars();
|
const avatars = await api.avatars();
|
||||||
return Response.json(avatars);
|
return Response.json(avatars);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { api } from "../../../core/api/dynamic";
|
||||||
|
import { Avatars } from "../../../protos/avatars";
|
||||||
|
|
||||||
|
export async function GET() {
|
||||||
|
const avatars = await api.avatars();
|
||||||
|
return new Response(Avatars.encode(avatars).finish());
|
||||||
|
}
|
||||||
Reference in new issue
Block a user