forked from mirrors/pronouns.cc
Merge branch 'feature/preference-cheatsheet'
This commit is contained in:
commit
cfed74d6bf
3 changed files with 73 additions and 0 deletions
|
@ -45,6 +45,7 @@
|
|||
import ProfileFlag from "./ProfileFlag.svelte";
|
||||
import IconButton from "$lib/components/IconButton.svelte";
|
||||
import Badges from "./badges/Badges.svelte";
|
||||
import PreferencesCheatsheet from "./PreferencesCheatsheet.svelte";
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
|
@ -258,6 +259,12 @@
|
|||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<PreferencesCheatsheet
|
||||
preferences={data.custom_preferences}
|
||||
names={data.names}
|
||||
pronouns={data.pronouns}
|
||||
fields={data.fields}
|
||||
/>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<InputGroup>
|
||||
|
|
59
frontend/src/routes/@[username]/PreferencesCheatsheet.svelte
Normal file
59
frontend/src/routes/@[username]/PreferencesCheatsheet.svelte
Normal file
|
@ -0,0 +1,59 @@
|
|||
<script lang="ts">
|
||||
import type { CustomPreferences, Field, FieldEntry, Pronoun } from "$lib/api/entities";
|
||||
import defaultPreferences from "$lib/api/default_preferences";
|
||||
import StatusIcon from "$lib/components/StatusIcon.svelte";
|
||||
|
||||
export let preferences: CustomPreferences;
|
||||
export let names: FieldEntry[];
|
||||
export let pronouns: Pronoun[];
|
||||
export let fields: Field[];
|
||||
|
||||
let mergedPreferences: CustomPreferences;
|
||||
$: mergedPreferences = Object.assign({}, defaultPreferences, preferences);
|
||||
|
||||
// Filter default preferences to the ones the user/member has used
|
||||
// This is done separately from custom preferences to make the shown list cleaner
|
||||
let usedDefaultPreferences: Array<{ id: string; preference: CustomPreference }>;
|
||||
$: usedDefaultPreferences = Object.keys(defaultPreferences)
|
||||
.filter(
|
||||
(pref) =>
|
||||
names.some((entry) => entry.status === pref) ||
|
||||
pronouns.some((entry) => entry.status === pref) ||
|
||||
fields.some((field) => field.entries.some((entry) => entry.status === pref)),
|
||||
)
|
||||
.map((key) => ({
|
||||
id: key,
|
||||
preference: defaultPreferences[key],
|
||||
}));
|
||||
// Do the same for custom preferences
|
||||
let usedCustomPreferences: Array<{ id: string; preference: CustomPreference }>;
|
||||
$: usedCustomPreferences = Object.keys(preferences)
|
||||
.filter(
|
||||
(pref) =>
|
||||
names.some((entry) => entry.status === pref) ||
|
||||
pronouns.some((entry) => entry.status === pref) ||
|
||||
fields.some((field) => field.entries.some((entry) => entry.status === pref)),
|
||||
)
|
||||
.map((pref) => ({ id: pref, preference: mergedPreferences[pref] }));
|
||||
</script>
|
||||
|
||||
<div class="text-center">
|
||||
<ul class="list-inline text-body-secondary">
|
||||
{#each usedDefaultPreferences as pref (pref.id)}
|
||||
<li class="list-inline-item mx-2">
|
||||
<StatusIcon {preferences} status={pref.id} />
|
||||
{pref.preference.tooltip}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{#if usedCustomPreferences}
|
||||
<ul class="list-inline text-body-secondary">
|
||||
{#each usedCustomPreferences as pref (pref.id)}
|
||||
<li class="list-inline-item mx-2">
|
||||
<StatusIcon {preferences} status={pref.id} />
|
||||
{pref.preference.tooltip}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
</div>
|
|
@ -22,6 +22,7 @@
|
|||
import { addToast } from "$lib/toast";
|
||||
import ProfileFlag from "../ProfileFlag.svelte";
|
||||
import IconButton from "$lib/components/IconButton.svelte";
|
||||
import PreferencesCheatsheet from "../PreferencesCheatsheet.svelte";
|
||||
|
||||
export let data: PageData;
|
||||
|
||||
|
@ -154,6 +155,12 @@
|
|||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<PreferencesCheatsheet
|
||||
preferences={data.user.custom_preferences}
|
||||
names={data.names}
|
||||
pronouns={data.pronouns}
|
||||
fields={data.fields}
|
||||
/>
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<InputGroup>
|
||||
|
|
Loading…
Reference in a new issue