mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 18:43:41 -05:00
Merge f3f03dd28c
into 5d41b49462
This commit is contained in:
commit
ff126be783
1 changed files with 41 additions and 4 deletions
|
@ -16,6 +16,13 @@ interface SetTimezoneProps {
|
||||||
refreshProfile: () => void
|
refreshProfile: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PronounsElementProps {
|
||||||
|
userID: string
|
||||||
|
pronouns: PronounSet[]
|
||||||
|
client: Client
|
||||||
|
refreshProfile: () => void
|
||||||
|
}
|
||||||
|
|
||||||
const getCurrentTimezone = () => new Intl.DateTimeFormat().resolvedOptions().timeZone
|
const getCurrentTimezone = () => new Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||||
|
|
||||||
const currentTimeAdjusted = (tz: string) => {
|
const currentTimeAdjusted = (tz: string) => {
|
||||||
|
@ -89,6 +96,37 @@ const SetTimeZoneElement = ({ tz, client, refreshProfile }: SetTimezoneProps) =>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const PronounsElement = ({ userID, pronouns, client, refreshProfile }: PronounsElementProps) => {
|
||||||
|
const display = pronouns.map(pronounSet => ensureString(pronounSet.summary)).join(", ")
|
||||||
|
if (userID !== client.userID) {
|
||||||
|
return <>
|
||||||
|
<div>Pronouns:</div>
|
||||||
|
<div>{display}</div>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
const savePronouns = (newPronouns: string) => {
|
||||||
|
// convert to pronouns object
|
||||||
|
const newPronounsArray = newPronouns.split(",").map(pronoun => ({ summary: pronoun.trim(), language: "en" }))
|
||||||
|
console.debug("Rendered new pronouns:", newPronounsArray)
|
||||||
|
client.rpc.setProfileField("io.fsky.nyx.pronouns", newPronounsArray).then(
|
||||||
|
() => {console.debug("Set new pronouns."); refreshProfile()},
|
||||||
|
err => {
|
||||||
|
console.error("Failed to set pronouns:", err)
|
||||||
|
window.alert(`Failed to set pronouns: ${err}`)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return <>
|
||||||
|
<label htmlFor="userprofile-pronouns-input">Pronouns:</label>
|
||||||
|
<input
|
||||||
|
id="userprofile-pronouns-input"
|
||||||
|
defaultValue={display}
|
||||||
|
onKeyDown={evt => evt.key === "Enter" && savePronouns(evt.currentTarget.value)}
|
||||||
|
onBlur={evt => evt.currentTarget.value !== display && savePronouns(evt.currentTarget.value)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const UserExtendedProfile = ({ profile, refreshProfile, client, userID }: ExtendedProfileProps)=> {
|
const UserExtendedProfile = ({ profile, refreshProfile, client, userID }: ExtendedProfileProps)=> {
|
||||||
if (!profile) {
|
if (!profile) {
|
||||||
|
@ -105,16 +143,15 @@ const UserExtendedProfile = ({ profile, refreshProfile, client, userID }: Extend
|
||||||
|
|
||||||
const pronouns = ensureArray(profile["io.fsky.nyx.pronouns"]) as PronounSet[]
|
const pronouns = ensureArray(profile["io.fsky.nyx.pronouns"]) as PronounSet[]
|
||||||
const userTimeZone = ensureString(profile["us.cloke.msc4175.tz"])
|
const userTimeZone = ensureString(profile["us.cloke.msc4175.tz"])
|
||||||
|
const displayPronouns = pronouns.length > 0 || client.userID === userID
|
||||||
return <>
|
return <>
|
||||||
<hr/>
|
<hr/>
|
||||||
<div className="extended-profile">
|
<div className="extended-profile">
|
||||||
{userTimeZone && <ClockElement tz={userTimeZone} />}
|
{userTimeZone && <ClockElement tz={userTimeZone} />}
|
||||||
{userID === client.userID &&
|
{userID === client.userID &&
|
||||||
<SetTimeZoneElement tz={userTimeZone} client={client} refreshProfile={refreshProfile} />}
|
<SetTimeZoneElement tz={userTimeZone} client={client} refreshProfile={refreshProfile} />}
|
||||||
{pronouns.length > 0 && <>
|
{displayPronouns &&
|
||||||
<div>Pronouns:</div>
|
<PronounsElement userID={userID} pronouns={pronouns} client={client} refreshProfile={refreshProfile} />}
|
||||||
<div>{pronouns.map(pronounSet => ensureString(pronounSet.summary)).join(", ")}</div>
|
|
||||||
</>}
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue