mirror of
https://github.com/coracle-social/flotilla.git
synced 2025-12-10 19:07:06 +00:00
Disable create room button if no permission
This commit is contained in:
committed by
Jon Staab
parent
5b22d6ac01
commit
a39a87ba6d
@@ -14,9 +14,10 @@
|
||||
import Icon from "@lib/components/Icon.svelte"
|
||||
import ModalHeader from "@lib/components/ModalHeader.svelte"
|
||||
import ModalFooter from "@lib/components/ModalFooter.svelte"
|
||||
import {hasNip29, loadChannel} from "@app/core/state"
|
||||
import {deriveUserCanCreateRoom, hasNip29, loadChannel} from "@app/core/state"
|
||||
import {makeSpacePath} from "@app/util/routes"
|
||||
import {pushToast} from "@app/util/toast"
|
||||
import {get} from "svelte/store"
|
||||
|
||||
const {url} = $props()
|
||||
|
||||
@@ -51,6 +52,8 @@
|
||||
goto(makeSpacePath(url, room.id))
|
||||
}
|
||||
|
||||
const canCreateRoom = get<boolean>(deriveUserCanCreateRoom(url))
|
||||
|
||||
const create = async () => {
|
||||
loading = true
|
||||
|
||||
@@ -99,7 +102,10 @@
|
||||
<Icon icon={AltArrowLeft} />
|
||||
Go back
|
||||
</Button>
|
||||
<Button type="submit" class="btn btn-primary" disabled={!name || loading || !hasNip29($relay)}>
|
||||
<Button
|
||||
type="submit"
|
||||
class="btn btn-primary"
|
||||
disabled={!name || loading || !hasNip29($relay) || !canCreateRoom}>
|
||||
<Spinner {loading}>Create Room</Spinner>
|
||||
<Icon icon={AltArrowRight} />
|
||||
</Button>
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
groupBy,
|
||||
always,
|
||||
tryCatch,
|
||||
last,
|
||||
} from "@welshman/lib"
|
||||
import type {Socket} from "@welshman/net"
|
||||
import {Pool, load, AuthStateEvent, AuthStatus, SocketEvent, netContext} from "@welshman/net"
|
||||
@@ -760,6 +761,17 @@ export const deriveUserMembershipStatus = (url: string, room: string) =>
|
||||
},
|
||||
)
|
||||
|
||||
export const deriveUserCanCreateRoom = (url: string) =>
|
||||
derived([pubkey, deriveEventsForUrl(url, [{kinds: [39004]}])], ([$pubkey, $events]) => {
|
||||
const latest = last($events)
|
||||
|
||||
if (!latest) {
|
||||
return true
|
||||
}
|
||||
|
||||
return getTagValues("p", latest.tags).includes($pubkey!)
|
||||
})
|
||||
|
||||
// Other utils
|
||||
|
||||
export const encodeRelay = (url: string) =>
|
||||
|
||||
Reference in New Issue
Block a user