forked from coracle/flotilla
Replace state when opening a modal from a drawer
This commit is contained in:
@@ -38,15 +38,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const showMembers = () =>
|
const showMembers = () =>
|
||||||
pushModal(ProfileList, {pubkeys: members, title: `Members of`, subtitle: displayRelayUrl(url)})
|
pushModal(
|
||||||
|
ProfileList,
|
||||||
|
{pubkeys: members, title: `Members of`, subtitle: displayRelayUrl(url)},
|
||||||
|
{replaceState}
|
||||||
|
)
|
||||||
|
|
||||||
const createInvite = () => pushModal(SpaceInvite, {url})
|
const createInvite = () => pushModal(SpaceInvite, {url}, {replaceState})
|
||||||
|
|
||||||
const leaveSpace = () => pushModal(SpaceExit, {url})
|
const leaveSpace = () => pushModal(SpaceExit, {url}, {replaceState})
|
||||||
|
|
||||||
const joinSpace = () => pushModal(SpaceJoin, {url})
|
const joinSpace = () => pushModal(SpaceJoin, {url}, {replaceState})
|
||||||
|
|
||||||
const addRoom = () => pushModal(RoomCreate, {url})
|
const addRoom = () => pushModal(RoomCreate, {url}, {replaceState})
|
||||||
|
|
||||||
const getDelay = (reset = false) => {
|
const getDelay = (reset = false) => {
|
||||||
if (reset) {
|
if (reset) {
|
||||||
@@ -60,12 +64,16 @@
|
|||||||
|
|
||||||
let delay = 0
|
let delay = 0
|
||||||
let showMenu = false
|
let showMenu = false
|
||||||
|
let replaceState = false
|
||||||
|
let element: Element
|
||||||
|
|
||||||
$: rooms = getMembershipRoomsByUrl(url, $userMembership)
|
$: rooms = getMembershipRoomsByUrl(url, $userMembership)
|
||||||
$: otherRooms = ($roomsByUrl.get(url) || []).filter(room => !rooms.concat(GENERAL).includes(room))
|
$: otherRooms = ($roomsByUrl.get(url) || []).filter(room => !rooms.concat(GENERAL).includes(room))
|
||||||
$: members = $memberships.filter(l => hasMembershipUrl(l, url)).map(l => l.event.pubkey)
|
$: members = $memberships.filter(l => hasMembershipUrl(l, url)).map(l => l.event.pubkey)
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
replaceState = Boolean(element.closest('.drawer'))
|
||||||
|
|
||||||
const error = (await checkRelayConnection(url)) || (await checkRelayAuth(url))
|
const error = (await checkRelayConnection(url)) || (await checkRelayAuth(url))
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -74,93 +82,95 @@
|
|||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SecondaryNavSection>
|
<div bind:this={element}>
|
||||||
<div>
|
<SecondaryNavSection>
|
||||||
<SecondaryNavItem class="w-full !justify-between" on:click={openMenu}>
|
<div>
|
||||||
<strong>{displayRelayUrl(url)}</strong>
|
<SecondaryNavItem class="w-full !justify-between" on:click={openMenu}>
|
||||||
<Icon icon="alt-arrow-down" />
|
<strong>{displayRelayUrl(url)}</strong>
|
||||||
</SecondaryNavItem>
|
<Icon icon="alt-arrow-down" />
|
||||||
{#if showMenu}
|
</SecondaryNavItem>
|
||||||
<Popover hideOnClick onClose={toggleMenu}>
|
{#if showMenu}
|
||||||
<ul
|
<Popover hideOnClick onClose={toggleMenu}>
|
||||||
transition:fly
|
<ul
|
||||||
class="menu absolute z-popover mt-2 w-full rounded-box bg-base-100 p-2 shadow-xl">
|
transition:fly
|
||||||
<li>
|
class="menu absolute z-popover mt-2 w-full rounded-box bg-base-100 p-2 shadow-xl">
|
||||||
<Button on:click={showMembers}>
|
<li>
|
||||||
<Icon icon="user-rounded" />
|
<Button on:click={showMembers}>
|
||||||
View Members ({members.length})
|
<Icon icon="user-rounded" />
|
||||||
</Button>
|
View Members ({members.length})
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<Button on:click={createInvite}>
|
|
||||||
<Icon icon="link-round" />
|
|
||||||
Create Invite
|
|
||||||
</Button>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
{#if getMembershipUrls($userMembership).includes(url)}
|
|
||||||
<Button on:click={leaveSpace} class="text-error">
|
|
||||||
<Icon icon="exit" />
|
|
||||||
Leave Space
|
|
||||||
</Button>
|
</Button>
|
||||||
{:else}
|
</li>
|
||||||
<Button on:click={joinSpace}>
|
<li>
|
||||||
<Icon icon="login-2" />
|
<Button on:click={createInvite}>
|
||||||
Join Space
|
<Icon icon="link-round" />
|
||||||
|
Create Invite
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
</li>
|
||||||
</li>
|
<li>
|
||||||
</ul>
|
{#if getMembershipUrls($userMembership).includes(url)}
|
||||||
</Popover>
|
<Button on:click={leaveSpace} class="text-error">
|
||||||
{/if}
|
<Icon icon="exit" />
|
||||||
</div>
|
Leave Space
|
||||||
<div in:fly={{delay: getDelay(true)}}>
|
</Button>
|
||||||
<SecondaryNavItem href={makeSpacePath(url)}>
|
{:else}
|
||||||
<Icon icon="notes-minimalistic" /> Threads
|
<Button on:click={joinSpace}>
|
||||||
</SecondaryNavItem>
|
<Icon icon="login-2" />
|
||||||
</div>
|
Join Space
|
||||||
<div transition:slide={{delay: getDelay()}}>
|
</Button>
|
||||||
<div class="h-2" />
|
{/if}
|
||||||
<SecondaryNavHeader>Your Rooms</SecondaryNavHeader>
|
</li>
|
||||||
</div>
|
</ul>
|
||||||
<div transition:slide={{delay: getDelay()}}>
|
</Popover>
|
||||||
<SecondaryNavItem href={makeSpacePath(url, GENERAL)}>
|
{/if}
|
||||||
<Icon icon="hashtag" />
|
</div>
|
||||||
{GENERAL}
|
<div in:fly={{delay: getDelay(true)}}>
|
||||||
</SecondaryNavItem>
|
<SecondaryNavItem href={makeSpacePath(url)}>
|
||||||
</div>
|
<Icon icon="notes-minimalistic" /> Threads
|
||||||
{#each rooms as room, i (room)}
|
|
||||||
<div transition:slide={{delay: getDelay()}}>
|
|
||||||
<SecondaryNavItem href={makeSpacePath(url, room)}>
|
|
||||||
<Icon icon="hashtag" />
|
|
||||||
{room}
|
|
||||||
</SecondaryNavItem>
|
</SecondaryNavItem>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
|
||||||
{#if otherRooms.length > 0}
|
|
||||||
<div transition:slide={{delay: getDelay()}}>
|
<div transition:slide={{delay: getDelay()}}>
|
||||||
<div class="h-2" />
|
<div class="h-2" />
|
||||||
<SecondaryNavHeader>
|
<SecondaryNavHeader>Your Rooms</SecondaryNavHeader>
|
||||||
{#if rooms.length > 0}
|
|
||||||
Other Rooms
|
|
||||||
{:else}
|
|
||||||
Rooms
|
|
||||||
{/if}
|
|
||||||
</SecondaryNavHeader>
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
|
||||||
{#each otherRooms as room, i (room)}
|
|
||||||
<div transition:slide={{delay: getDelay()}}>
|
<div transition:slide={{delay: getDelay()}}>
|
||||||
<SecondaryNavItem href={makeSpacePath(url, room)}>
|
<SecondaryNavItem href={makeSpacePath(url, GENERAL)}>
|
||||||
<Icon icon="hashtag" />
|
<Icon icon="hashtag" />
|
||||||
{room}
|
{GENERAL}
|
||||||
</SecondaryNavItem>
|
</SecondaryNavItem>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{#each rooms as room, i (room)}
|
||||||
<div in:fly={{delay: getDelay()}}>
|
<div transition:slide={{delay: getDelay()}}>
|
||||||
<SecondaryNavItem on:click={addRoom}>
|
<SecondaryNavItem href={makeSpacePath(url, room)}>
|
||||||
<Icon icon="add-circle" />
|
<Icon icon="hashtag" />
|
||||||
Create room
|
{room}
|
||||||
</SecondaryNavItem>
|
</SecondaryNavItem>
|
||||||
</div>
|
</div>
|
||||||
</SecondaryNavSection>
|
{/each}
|
||||||
|
{#if otherRooms.length > 0}
|
||||||
|
<div transition:slide={{delay: getDelay()}}>
|
||||||
|
<div class="h-2" />
|
||||||
|
<SecondaryNavHeader>
|
||||||
|
{#if rooms.length > 0}
|
||||||
|
Other Rooms
|
||||||
|
{:else}
|
||||||
|
Rooms
|
||||||
|
{/if}
|
||||||
|
</SecondaryNavHeader>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{#each otherRooms as room, i (room)}
|
||||||
|
<div transition:slide={{delay: getDelay()}}>
|
||||||
|
<SecondaryNavItem href={makeSpacePath(url, room)}>
|
||||||
|
<Icon icon="hashtag" />
|
||||||
|
{room}
|
||||||
|
</SecondaryNavItem>
|
||||||
|
</div>
|
||||||
|
{/each}
|
||||||
|
<div in:fly={{delay: getDelay()}}>
|
||||||
|
<SecondaryNavItem on:click={addRoom}>
|
||||||
|
<Icon icon="add-circle" />
|
||||||
|
Create room
|
||||||
|
</SecondaryNavItem>
|
||||||
|
</div>
|
||||||
|
</SecondaryNavSection>
|
||||||
|
</div>
|
||||||
|
|||||||
+2
-1
@@ -8,7 +8,8 @@ export const getKey = <T>(key: string) => state.get(key) as T | undefined
|
|||||||
export const popKey = <T>(key: string) => {
|
export const popKey = <T>(key: string) => {
|
||||||
const value: T | undefined = state.get(key)
|
const value: T | undefined = state.get(key)
|
||||||
|
|
||||||
state.delete(key)
|
// Goofy hack due to sveltekit's double-rendering
|
||||||
|
setTimeout(() => state.delete(key), 300)
|
||||||
|
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -6,6 +6,7 @@ import {goto} from "$app/navigation"
|
|||||||
export type ModalOptions = {
|
export type ModalOptions = {
|
||||||
drawer?: boolean
|
drawer?: boolean
|
||||||
fullscreen?: boolean
|
fullscreen?: boolean
|
||||||
|
replaceState?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Modal = {
|
export type Modal = {
|
||||||
@@ -28,7 +29,7 @@ export const pushModal = (
|
|||||||
|
|
||||||
modals.update(assoc(id, {id, component, props, options}))
|
modals.update(assoc(id, {id, component, props, options}))
|
||||||
|
|
||||||
goto("#" + id)
|
goto("#" + id, {replaceState: options.replaceState})
|
||||||
|
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
export let onClose
|
export let onClose
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="fixed inset-0 z-modal">
|
<div class="fixed inset-0 z-modal drawer">
|
||||||
<button
|
<button
|
||||||
class="absolute inset-0 cursor-pointer bg-black opacity-50"
|
class="absolute inset-0 cursor-pointer bg-black opacity-50"
|
||||||
transition:fade
|
transition:fade
|
||||||
|
|||||||
Reference in New Issue
Block a user