2024-12-16 20:54:17 +00:00
|
|
|
<script lang="ts">
|
2026-02-10 00:57:44 +00:00
|
|
|
import {onMount} from "svelte"
|
2026-06-29 22:48:43 +00:00
|
|
|
import {goto} from "$app/navigation"
|
2026-06-18 10:52:04 +00:00
|
|
|
import {displayProfileByPubkey, loadMessagingRelayList} from "@welshman/app"
|
2025-09-10 22:26:39 +00:00
|
|
|
import AltArrowLeft from "@assets/icons/alt-arrow-left.svg?dataurl"
|
2026-06-18 10:52:04 +00:00
|
|
|
import UserCircle from "@assets/icons/user-circle.svg?dataurl"
|
2025-11-13 21:44:52 +00:00
|
|
|
import MinusCircle from "@assets/icons/minus-circle.svg?dataurl"
|
2026-06-30 17:02:02 +00:00
|
|
|
import UserMinus from "@assets/icons/user-minus.svg?dataurl"
|
2026-02-13 21:05:17 +00:00
|
|
|
import Restart from "@assets/icons/restart.svg?dataurl"
|
2024-12-16 20:54:17 +00:00
|
|
|
import Icon from "@lib/components/Icon.svelte"
|
2025-11-13 21:44:52 +00:00
|
|
|
import Confirm from "@lib/components/Confirm.svelte"
|
2024-12-16 20:54:17 +00:00
|
|
|
import Button from "@lib/components/Button.svelte"
|
2026-01-30 22:14:12 +00:00
|
|
|
import Modal from "@lib/components/Modal.svelte"
|
|
|
|
|
import ModalBody from "@lib/components/ModalBody.svelte"
|
2024-12-16 20:54:17 +00:00
|
|
|
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
2025-05-29 21:30:22 +00:00
|
|
|
import Profile from "@app/components/Profile.svelte"
|
2026-07-03 00:01:31 +00:00
|
|
|
import ProfileAbout from "@app/components/ProfileAbout.svelte"
|
2025-06-05 20:01:36 +00:00
|
|
|
import ProfileBadges from "@app/components/ProfileBadges.svelte"
|
2026-07-03 00:27:28 +00:00
|
|
|
import ProfileMenu from "@app/components/ProfileMenu.svelte"
|
2026-06-22 20:36:57 +00:00
|
|
|
import {
|
|
|
|
|
deriveUserIsSpaceAdmin,
|
|
|
|
|
deriveSpaceBannedPubkeyItems,
|
2026-06-30 17:02:02 +00:00
|
|
|
removeSpaceMembers,
|
2026-06-22 20:36:57 +00:00
|
|
|
addSpaceMembers,
|
|
|
|
|
banSpaceMembers,
|
|
|
|
|
} from "@app/members"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {pushModal} from "@app/modal"
|
|
|
|
|
import {pushToast} from "@app/toast"
|
2026-06-29 22:48:43 +00:00
|
|
|
import {makeProfilePath} from "@app/routes"
|
2024-12-16 20:54:17 +00:00
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
export type Props = {
|
|
|
|
|
pubkey: string
|
|
|
|
|
url?: string
|
|
|
|
|
}
|
2024-12-16 20:54:17 +00:00
|
|
|
|
2025-04-15 18:03:27 +00:00
|
|
|
const {pubkey, url}: Props = $props()
|
|
|
|
|
|
2025-11-13 21:44:52 +00:00
|
|
|
const userIsAdmin = deriveUserIsSpaceAdmin(url)
|
|
|
|
|
|
2026-02-13 21:05:17 +00:00
|
|
|
const bannedPubkeys = url ? deriveSpaceBannedPubkeyItems(url) : undefined
|
|
|
|
|
|
|
|
|
|
const isBanned = $derived($bannedPubkeys?.some(item => item.pubkey === pubkey) ?? false)
|
|
|
|
|
|
2024-12-16 20:54:17 +00:00
|
|
|
const back = () => history.back()
|
|
|
|
|
|
2026-06-29 22:48:43 +00:00
|
|
|
const viewProfile = () => goto(makeProfilePath(pubkey), {replaceState: true})
|
2025-11-13 21:44:52 +00:00
|
|
|
|
|
|
|
|
const banMember = () =>
|
|
|
|
|
pushModal(Confirm, {
|
|
|
|
|
title: "Ban User",
|
2025-11-14 19:35:19 +00:00
|
|
|
message: `Are you sure you want to ban @${displayProfileByPubkey(pubkey)} from the space?`,
|
2025-11-13 21:44:52 +00:00
|
|
|
confirm: async () => {
|
2026-06-22 20:36:57 +00:00
|
|
|
const error = await banSpaceMembers(url!, [pubkey])
|
2025-11-13 21:44:52 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "User has successfully been banned!"})
|
|
|
|
|
back()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
2026-06-30 17:02:02 +00:00
|
|
|
const removeMember = async () => {
|
|
|
|
|
const error = await removeSpaceMembers(url!, [pubkey])
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "User has successfully been removed!"})
|
|
|
|
|
back()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-13 21:05:17 +00:00
|
|
|
const restoreMember = async () => {
|
2026-03-19 15:40:34 +00:00
|
|
|
const error = await addSpaceMembers(url!, [pubkey])
|
2026-02-13 21:05:17 +00:00
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
pushToast({theme: "error", message: error})
|
|
|
|
|
} else {
|
|
|
|
|
pushToast({message: "User has successfully been restored!"})
|
|
|
|
|
back()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-10 00:57:44 +00:00
|
|
|
onMount(() => {
|
|
|
|
|
loadMessagingRelayList(pubkey)
|
|
|
|
|
})
|
2024-12-16 20:54:17 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-01-30 22:14:12 +00:00
|
|
|
<Modal>
|
|
|
|
|
<ModalBody>
|
|
|
|
|
<div class="flex flex-col gap-4">
|
|
|
|
|
<div class="flex justify-between">
|
|
|
|
|
<Profile showPubkey avatarSize={14} {pubkey} {url} />
|
2026-07-03 00:27:28 +00:00
|
|
|
<ProfileMenu {pubkey} {url}>
|
|
|
|
|
{#snippet customActions()}
|
|
|
|
|
{#if $userIsAdmin}
|
|
|
|
|
{#if isBanned}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={restoreMember}>
|
|
|
|
|
<Icon icon={Restart} />
|
|
|
|
|
Restore Membership
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{:else}
|
|
|
|
|
<li>
|
|
|
|
|
<Button onclick={removeMember}>
|
|
|
|
|
<Icon icon={UserMinus} />
|
|
|
|
|
Remove Member
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
<li>
|
|
|
|
|
<Button class="text-error" onclick={banMember}>
|
|
|
|
|
<Icon icon={MinusCircle} />
|
|
|
|
|
Ban User
|
|
|
|
|
</Button>
|
|
|
|
|
</li>
|
|
|
|
|
{/if}
|
2026-01-30 22:14:12 +00:00
|
|
|
{/if}
|
2026-07-03 00:27:28 +00:00
|
|
|
{/snippet}
|
|
|
|
|
</ProfileMenu>
|
2025-11-13 21:44:52 +00:00
|
|
|
</div>
|
2026-07-03 00:01:31 +00:00
|
|
|
<ProfileAbout {pubkey} {url} />
|
2026-01-30 22:14:12 +00:00
|
|
|
<ProfileBadges {pubkey} {url} />
|
|
|
|
|
</div>
|
|
|
|
|
</ModalBody>
|
2024-12-16 20:54:17 +00:00
|
|
|
<ModalFooter>
|
2026-06-24 20:56:53 +00:00
|
|
|
<Button onclick={back} class="button button-link hidden md:flex">
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={AltArrowLeft} />
|
2024-12-16 20:54:17 +00:00
|
|
|
Go back
|
|
|
|
|
</Button>
|
|
|
|
|
<div class="flex gap-2">
|
2026-06-18 10:52:04 +00:00
|
|
|
<Button onclick={viewProfile} class="button button-primary">
|
|
|
|
|
<Icon icon={UserCircle} />
|
|
|
|
|
View Full Profile
|
2024-12-16 20:54:17 +00:00
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</ModalFooter>
|
2026-01-30 22:14:12 +00:00
|
|
|
</Modal>
|