💄 Better join realm
This commit is contained in:
@@ -7,7 +7,9 @@
|
|||||||
:style="pageStyle"
|
:style="pageStyle"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="relative flex items-center justify-center min-h-layout px-4">
|
<div
|
||||||
|
class="relative flex items-center justify-center min-h-layout overflow-auto p-4"
|
||||||
|
>
|
||||||
<n-card
|
<n-card
|
||||||
:class="[
|
:class="[
|
||||||
'w-full',
|
'w-full',
|
||||||
@@ -74,6 +76,7 @@
|
|||||||
block
|
block
|
||||||
size="large"
|
size="large"
|
||||||
:loading="isJoining"
|
:loading="isJoining"
|
||||||
|
:disabled="isMember"
|
||||||
@click="handleJoin"
|
@click="handleJoin"
|
||||||
>
|
>
|
||||||
<template #icon>
|
<template #icon>
|
||||||
@@ -81,6 +84,21 @@
|
|||||||
</template>
|
</template>
|
||||||
Join Realm
|
Join Realm
|
||||||
</n-button>
|
</n-button>
|
||||||
|
|
||||||
|
<n-alert
|
||||||
|
v-if="isMember"
|
||||||
|
type="info"
|
||||||
|
title="Already Joined"
|
||||||
|
class="mt-4"
|
||||||
|
>
|
||||||
|
You already joined this realm,
|
||||||
|
<nuxt-link
|
||||||
|
:to="`/realms/${route.params.slug}`"
|
||||||
|
class="underline font-bold"
|
||||||
|
>
|
||||||
|
go to the realm page instead.
|
||||||
|
</nuxt-link>
|
||||||
|
</n-alert>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div v-else-if="notFound" class="flex justify-center p-8">
|
<div v-else-if="notFound" class="flex justify-center p-8">
|
||||||
@@ -160,6 +178,21 @@
|
|||||||
>
|
>
|
||||||
<verification-status-card :mark="realm.verification" />
|
<verification-status-card :mark="realm.verification" />
|
||||||
</n-card>
|
</n-card>
|
||||||
|
|
||||||
|
<div v-if="realm.isPublic && !isMember">
|
||||||
|
<n-button
|
||||||
|
type="primary"
|
||||||
|
block
|
||||||
|
size="large"
|
||||||
|
:loading="isJoining"
|
||||||
|
@click="handleJoin"
|
||||||
|
>
|
||||||
|
<template #icon>
|
||||||
|
<n-icon :component="UserPlus" />
|
||||||
|
</template>
|
||||||
|
Join Realm
|
||||||
|
</n-button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<!-- Filter Section -->
|
<!-- Filter Section -->
|
||||||
@@ -309,6 +342,8 @@ const api = useSolarNetwork()
|
|||||||
const notFound = ref<boolean>(false)
|
const notFound = ref<boolean>(false)
|
||||||
const realm = ref<SnRealm | null>(null)
|
const realm = ref<SnRealm | null>(null)
|
||||||
const isJoining = ref(false)
|
const isJoining = ref(false)
|
||||||
|
const isMember = ref(false)
|
||||||
|
const checkingMembership = ref(false)
|
||||||
|
|
||||||
// Check if we're in invite mode
|
// Check if we're in invite mode
|
||||||
const isInviteMode = computed(() => {
|
const isInviteMode = computed(() => {
|
||||||
@@ -433,6 +468,24 @@ const cycleIncludeReplies = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check membership status
|
||||||
|
async function checkMembership() {
|
||||||
|
if (!realm.value) return
|
||||||
|
|
||||||
|
checkingMembership.value = true
|
||||||
|
try {
|
||||||
|
await api(`/id/realms/${realm.value.slug}/members/me`, {
|
||||||
|
method: "GET"
|
||||||
|
})
|
||||||
|
isMember.value = true
|
||||||
|
} catch (err) {
|
||||||
|
// 404 means not a member
|
||||||
|
isMember.value = false
|
||||||
|
} finally {
|
||||||
|
checkingMembership.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle join realm
|
// Handle join realm
|
||||||
async function handleJoin() {
|
async function handleJoin() {
|
||||||
if (!realm.value) return
|
if (!realm.value) return
|
||||||
@@ -443,8 +496,11 @@ async function handleJoin() {
|
|||||||
method: "POST"
|
method: "POST"
|
||||||
})
|
})
|
||||||
message.success(`Successfully joined ${realm.value.name}!`)
|
message.success(`Successfully joined ${realm.value.name}!`)
|
||||||
// Redirect to the realm page without invite query
|
isMember.value = true
|
||||||
await navigateTo(`/realms/${realm.value.slug}`)
|
// Redirect to the realm page without invite query if in invite mode
|
||||||
|
if (isInviteMode.value) {
|
||||||
|
await navigateTo(`/realms/${realm.value.slug}`)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
message.error(err instanceof Error ? err.message : String(err))
|
message.error(err instanceof Error ? err.message : String(err))
|
||||||
} finally {
|
} finally {
|
||||||
@@ -452,6 +508,13 @@ async function handleJoin() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check membership on mount
|
||||||
|
onMounted(() => {
|
||||||
|
if (realm.value) {
|
||||||
|
checkMembership()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
title: "Realms",
|
title: "Realms",
|
||||||
alias: ["/r/:slug()"]
|
alias: ["/r/:slug()"]
|
||||||
|
|||||||
Reference in New Issue
Block a user