Remove other spaces menu, just use the page version
This commit is contained in:
@@ -1,84 +0,0 @@
|
||||
<script lang="ts">
|
||||
import {insertAt, removeAt} from "@welshman/lib"
|
||||
import MenuSpacesItem from "@app/components/MenuSpacesItem.svelte"
|
||||
import {setSpaceMembershipOrder} from "@app/core/commands"
|
||||
|
||||
type Props = {
|
||||
urls: string[]
|
||||
}
|
||||
|
||||
const {urls}: Props = $props()
|
||||
|
||||
const isSameOrder = (a: string[], b: string[]) =>
|
||||
a.length === b.length && a.every((url, index) => url === b[index])
|
||||
|
||||
const reorderSpaceUrls = (targetUrl: string) => {
|
||||
if (!draggedUrl) {
|
||||
return
|
||||
}
|
||||
|
||||
const sourceIndex = orderedUrls.indexOf(draggedUrl)
|
||||
const targetIndex = orderedUrls.indexOf(targetUrl)
|
||||
|
||||
if (sourceIndex === -1 || targetIndex === -1 || sourceIndex === targetIndex) {
|
||||
return
|
||||
}
|
||||
|
||||
orderedUrls = insertAt(
|
||||
targetIndex,
|
||||
orderedUrls[sourceIndex],
|
||||
removeAt(sourceIndex, orderedUrls),
|
||||
)
|
||||
}
|
||||
|
||||
const onDragStart = (e: DragEvent, url: string) => {
|
||||
draggedUrl = url
|
||||
dragStartOrder = [...orderedUrls]
|
||||
|
||||
if (e.dataTransfer) {
|
||||
e.dataTransfer.effectAllowed = "move"
|
||||
e.dataTransfer.setData("text/plain", url)
|
||||
}
|
||||
}
|
||||
|
||||
const onDragOver = (e: DragEvent, targetUrl: string) => {
|
||||
e.preventDefault()
|
||||
reorderSpaceUrls(targetUrl)
|
||||
}
|
||||
|
||||
const onDrop = (e: DragEvent, targetUrl: string) => {
|
||||
e.preventDefault()
|
||||
reorderSpaceUrls(targetUrl)
|
||||
draggedUrl = undefined
|
||||
|
||||
if (dragStartOrder && !isSameOrder(dragStartOrder, orderedUrls)) {
|
||||
void setSpaceMembershipOrder(orderedUrls).catch(console.error)
|
||||
}
|
||||
|
||||
dragStartOrder = undefined
|
||||
}
|
||||
|
||||
const onDragEnd = () => {
|
||||
draggedUrl = undefined
|
||||
dragStartOrder = undefined
|
||||
}
|
||||
|
||||
let orderedUrls = $state([...urls])
|
||||
let draggedUrl = $state<string | undefined>()
|
||||
let dragStartOrder = $state<string[] | undefined>()
|
||||
</script>
|
||||
|
||||
<div class="column menu gap-2 p-3" role="list">
|
||||
{#each orderedUrls as url (url)}
|
||||
<div
|
||||
class:opacity-60={draggedUrl === url}
|
||||
draggable="true"
|
||||
role="listitem"
|
||||
ondragstart={e => onDragStart(e, url)}
|
||||
ondragover={e => onDragOver(e, url)}
|
||||
ondrop={e => onDrop(e, url)}
|
||||
ondragend={onDragEnd}>
|
||||
<MenuSpacesItem {url} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
@@ -13,7 +13,7 @@
|
||||
</script>
|
||||
|
||||
<Link replaceState href={path}>
|
||||
<CardButton class="btn-neutral shadow-md bg-alt">
|
||||
<CardButton class="btn-neutral shadow-md bg-alt rounded-box border-none">
|
||||
{#snippet icon()}
|
||||
<RelayIcon {url} size={12} class="rounded-full" />
|
||||
{/snippet}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
import Divider from "@lib/components/Divider.svelte"
|
||||
import PrimaryNavItem from "@lib/components/PrimaryNavItem.svelte"
|
||||
import ChatEnable from "@app/components/ChatEnable.svelte"
|
||||
import MenuOtherSpaces from "@app/components/MenuOtherSpaces.svelte"
|
||||
import MenuSettings from "@app/components/MenuSettings.svelte"
|
||||
import PrimaryNavItemSpace from "@app/components/PrimaryNavItemSpace.svelte"
|
||||
import {userSpaceUrls, PLATFORM_RELAYS, PLATFORM_LOGO} from "@app/core/state"
|
||||
@@ -27,8 +26,6 @@
|
||||
|
||||
const {children}: Props = $props()
|
||||
|
||||
const showOtherSpacesMenu = () => pushModal(MenuOtherSpaces, {urls: $userSpaceUrls})
|
||||
|
||||
const showSettingsMenu = () => pushModal(MenuSettings)
|
||||
|
||||
const openChat = () => ($shouldUnwrap ? goto("/chat") : pushModal(ChatEnable, {next: "/chat"}))
|
||||
@@ -60,9 +57,9 @@
|
||||
<PrimaryNavItemSpace {url} />
|
||||
{/each}
|
||||
<PrimaryNavItem
|
||||
href="/spaces"
|
||||
title="All Spaces"
|
||||
class="tooltip-right"
|
||||
onclick={showOtherSpacesMenu}
|
||||
notification={otherSpaceNotifications}>
|
||||
<ImageIcon alt="All Spaces" src={Widget} size={8} />
|
||||
</PrimaryNavItem>
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
{/if}
|
||||
{/snippet}
|
||||
</PageBar>
|
||||
<PageContent class="cw-full flex flex-col gap-2 p-4 pt-6">
|
||||
<PageContent class="cw-full flex flex-col gap-2 p-2 pt-4">
|
||||
{#each PLATFORM_RELAYS as url (url)}
|
||||
<MenuSpacesItem {url} />
|
||||
{:else}
|
||||
|
||||
Reference in New Issue
Block a user