mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
Clean up code
This commit is contained in:
parent
fc54faf551
commit
0e4addd3fc
3 changed files with 59 additions and 60 deletions
|
@ -19,7 +19,8 @@ import type {
|
||||||
ClientWellKnown,
|
ClientWellKnown,
|
||||||
EventID,
|
EventID,
|
||||||
EventRowID,
|
EventRowID,
|
||||||
EventType, JSONValue,
|
EventType,
|
||||||
|
JSONValue,
|
||||||
LoginFlowsResponse,
|
LoginFlowsResponse,
|
||||||
LoginRequest,
|
LoginRequest,
|
||||||
Mentions,
|
Mentions,
|
||||||
|
|
|
@ -76,6 +76,21 @@ export interface UserProfile {
|
||||||
[custom: string]: unknown
|
[custom: string]: unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PronounSet {
|
||||||
|
subject?: string
|
||||||
|
object?: string
|
||||||
|
possessive_determiner?: string
|
||||||
|
possessive_pronoun?: string
|
||||||
|
reflexive?: string
|
||||||
|
summary: string
|
||||||
|
language: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ExtendedUserProfile extends UserProfile {
|
||||||
|
"us.cloke.msc4175.tz"?: string
|
||||||
|
"io.fsky.nyx.pronouns"?: PronounSet[]
|
||||||
|
}
|
||||||
|
|
||||||
export type Membership = "join" | "leave" | "ban" | "invite" | "knock"
|
export type Membership = "join" | "leave" | "ban" | "invite" | "knock"
|
||||||
|
|
||||||
export interface MemberEventContent extends UserProfile {
|
export interface MemberEventContent extends UserProfile {
|
||||||
|
@ -294,18 +309,3 @@ export interface RespOpenIDToken {
|
||||||
matrix_server_name: string
|
matrix_server_name: string
|
||||||
token_type: "Bearer"
|
token_type: "Bearer"
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PronounSet {
|
|
||||||
subject?: string
|
|
||||||
object?: string
|
|
||||||
possessive_determiner?: string
|
|
||||||
possessive_pronoun?: string
|
|
||||||
reflexive?: string
|
|
||||||
summary: string
|
|
||||||
language: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ExtendedProfileAttributes {
|
|
||||||
"us.cloke.msc4175.tz"?: string
|
|
||||||
"io.fsky.nyx.pronouns"?: PronounSet[]
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import Client from "@/api/client.ts"
|
import Client from "@/api/client.ts"
|
||||||
import { ExtendedProfileAttributes, PronounSet, UserProfile } from "@/api/types"
|
import { ExtendedUserProfile, PronounSet } from "@/api/types"
|
||||||
import { ensureArray } from "@/util/validation.ts"
|
import { ensureArray, ensureString } from "@/util/validation.ts"
|
||||||
|
|
||||||
interface ExtendedProfileProps {
|
interface ExtendedProfileProps {
|
||||||
profile: UserProfile & ExtendedProfileAttributes
|
profile: ExtendedUserProfile
|
||||||
client: Client
|
client: Client
|
||||||
userID: string
|
userID: string
|
||||||
}
|
}
|
||||||
|
@ -51,8 +51,7 @@ function SetTimezoneElement({ tz, client }: SetTimezoneProps) {
|
||||||
// The defaulting to the current timezone causes `newTz !== tz` to never be true when the user has
|
// The defaulting to the current timezone causes `newTz !== tz` to never be true when the user has
|
||||||
// no timezone set.
|
// no timezone set.
|
||||||
|
|
||||||
return (
|
return <>
|
||||||
<>
|
|
||||||
<input
|
<input
|
||||||
list="timezones"
|
list="timezones"
|
||||||
className="text-input"
|
className="text-input"
|
||||||
|
@ -60,28 +59,28 @@ function SetTimezoneElement({ tz, client }: SetTimezoneProps) {
|
||||||
onChange={(e) => setTz(e.currentTarget.value)}
|
onChange={(e) => setTz(e.currentTarget.value)}
|
||||||
/>
|
/>
|
||||||
<datalist id="timezones">
|
<datalist id="timezones">
|
||||||
{
|
{zones.map((zone) => <option key={zone} value={zone} />)}
|
||||||
zones.map((zone) => <option key={zone} value={zone} />)
|
|
||||||
}
|
|
||||||
</datalist>
|
</datalist>
|
||||||
</>
|
</>
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default function UserExtendedProfile({ profile, client, userID }: ExtendedProfileProps) {
|
export default function UserExtendedProfile({ profile, client, userID }: ExtendedProfileProps) {
|
||||||
if (!profile) return null
|
if (!profile) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
const extendedProfileKeys = ["us.cloke.msc4175.tz", "io.fsky.nyx.pronouns"]
|
const extendedProfileKeys = ["us.cloke.msc4175.tz", "io.fsky.nyx.pronouns"]
|
||||||
const hasExtendedProfile = extendedProfileKeys.some((key) => key in profile)
|
const hasExtendedProfile = extendedProfileKeys.some((key) => profile[key])
|
||||||
if (!hasExtendedProfile && client.userID !== userID) return null
|
if (!hasExtendedProfile && client.userID !== userID) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
// Explicitly only return something if the profile has the keys we're looking for.
|
// Explicitly only return something if the profile has the keys we're looking for.
|
||||||
// otherwise there's an ugly and pointless <hr/> for no real reason.
|
// otherwise there's an ugly and pointless <hr/> for no real reason.
|
||||||
|
|
||||||
const pronouns: PronounSet[] = ensureArray(profile["io.fsky.nyx.pronouns"]) as PronounSet[]
|
const pronouns = ensureArray(profile["io.fsky.nyx.pronouns"]) as PronounSet[]
|
||||||
const userTimezone: string | undefined = profile["us.cloke.msc4175.tz"]
|
const userTimezone = ensureString(profile["us.cloke.msc4175.tz"])
|
||||||
return (
|
return <>
|
||||||
<>
|
|
||||||
<hr/>
|
<hr/>
|
||||||
<div className="extended-profile">
|
<div className="extended-profile">
|
||||||
{userTimezone && <>
|
{userTimezone && <>
|
||||||
|
@ -100,5 +99,4 @@ export default function UserExtendedProfile({ profile, client, userID }: Extende
|
||||||
</>}
|
</>}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue