feat: add flags to profile pages

This commit is contained in:
Sam 2023-05-29 03:26:20 +02:00
parent c28df5fc7f
commit 5b954778cf
No known key found for this signature in database
GPG Key ID: B4EF20DDE721CAA1
3 changed files with 55 additions and 3 deletions

View File

@ -40,6 +40,7 @@
import StatusLine from "$lib/components/StatusLine.svelte";
import defaultPreferences from "$lib/api/default_preferences";
import { addToast } from "$lib/toast";
import ProfileFlag from "./ProfileFlag.svelte";
export let data: PageData;
@ -117,16 +118,16 @@
onMount(async () => {
if ($userStore && $userStore.id === data.id) {
console.log("User is current user, fetching members")
console.log("User is current user, fetching members");
try {
const members = await apiFetchClient<PartialMember[]>("/users/@me/members");
data.members = members;
} catch (e) {
// If it fails, we fail silently but log to console anyway
console.error("Fetching members:", e)
console.error("Fetching members:", e);
}
}
})
});
</script>
<div class="container">
@ -140,6 +141,13 @@
<div class="row">
<div class="col-md-4 text-center">
<FallbackImage width={200} urls={userAvatars(data)} alt="Avatar for @{data.name}" />
{#if data.flags && data.bio}
<div class="d-flex flex-wrap m-4">
{#each data.flags as flag}
<ProfileFlag {flag} />
{/each}
</div>
{/if}
</div>
<div class="col-md">
{#if data.display_name}
@ -174,6 +182,13 @@
</div>
{/if}
</div>
{#if data.flags && !data.bio}
<div class="d-flex flex-wrap m-4">
{#each data.flags as flag}
<ProfileFlag {flag} />
{/each}
</div>
{/if}
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3">
{#if data.names.length > 0}
<div class="col-md">

View File

@ -0,0 +1,22 @@
<script lang="ts">
import { flagURL, type PrideFlag } from "$lib/api/entities";
import { Tooltip } from "sveltestrap";
export let flag: PrideFlag;
let elem: HTMLElement;
</script>
<span class="mx-2 my-1">
<Tooltip target={elem} aria-hidden placement="top">{flag.description ?? flag.name}</Tooltip>
<img bind:this={elem} class="flag" src={flagURL(flag)} alt={flag.description ?? flag.name} />
{flag.name}
</span>
<style>
.flag {
height: 1.5rem;
max-width: 200px;
border-radius: 3px;
}
</style>

View File

@ -20,6 +20,7 @@
import StatusLine from "$lib/components/StatusLine.svelte";
import defaultPreferences from "$lib/api/default_preferences";
import { addToast } from "$lib/toast";
import ProfileFlag from "../ProfileFlag.svelte";
export let data: PageData;
@ -69,6 +70,13 @@
<div class="row">
<div class="col-md-4 text-center">
<FallbackImage width={200} urls={memberAvatars(data)} alt="Avatar for @{data.name}" />
{#if data.flags && data.bio}
<div class="d-flex flex-wrap m-4">
{#each data.flags as flag}
<ProfileFlag {flag} />
{/each}
</div>
{/if}
</div>
<div class="col-md">
<h2>{data.display_name ?? data.name}</h2>
@ -97,6 +105,13 @@
</div>
{/if}
</div>
{#if data.flags && !data.bio}
<div class="d-flex flex-wrap m-4">
{#each data.flags as flag}
<ProfileFlag {flag} />
{/each}
</div>
{/if}
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3">
{#if data.names.length > 0}
<div class="col-md">