feat(web): list the room's people and let the owner remove them
ci / checks (push) Successful in 54s
ci / test (push) Successful in 58s
ci / chart (push) Successful in 5s
ci / web (push) Successful in 21s
ci / docker (push) Successful in 11s
ci / publish-edge-image (push) Successful in 10s
ci / publish-edge-chart (push) Successful in 3s
ci / checks (push) Successful in 54s
ci / test (push) Successful in 58s
ci / chart (push) Successful in 5s
ci / web (push) Successful in 21s
ci / docker (push) Successful in 11s
ci / publish-edge-image (push) Successful in 10s
ci / publish-edge-chart (push) Successful in 3s
The invite dialog was reachable only from the invite button, and who was in the room showed only as avatars in the top bar. Selecting an avatar, the member count, or the People button now opens one dialog: a scrollable member list with the invite link below it. The owner removes a member from the row after a confirmation, and the top bar drops them without reloading the room. The server already refuses to remove the owner. Invite link creation is unchanged.
This commit is contained in:
1 parent
7d98b04d63
commit
880f4e2d87
5 files changed
+295
-100
No files matched your search
@@ -0,0 +1,175 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { Check, Copy, X } from 'lucide-vue-next'
|
||||
import type { Invite, Member, RoomDetailResponse } from '~/types'
|
||||
import { apiErrorMessage } from '~/utils/errors'
|
||||
import { formatDate } from '~/utils/format'
|
||||
import BaseDialog from '~/components/BaseDialog.vue'
|
||||
|
||||
const props = defineProps<{ roomId: string; roomName: string }>()
|
||||
const emit = defineEmits<{ close: []; removed: [memberId: string] }>()
|
||||
|
||||
const api = useApi()
|
||||
|
||||
const people = ref<Member[]>([])
|
||||
const me = ref<RoomDetailResponse['me'] | null>(null)
|
||||
const peopleLoading = ref(true)
|
||||
const peopleError = ref('')
|
||||
|
||||
const invite = ref<Invite | null>(null)
|
||||
const inviteLoading = ref(true)
|
||||
const inviteError = ref('')
|
||||
const copied = ref(false)
|
||||
|
||||
const confirming = ref('')
|
||||
const removing = ref('')
|
||||
const removeError = ref('')
|
||||
|
||||
const inviteUrl = computed(() => invite.value?.url ?? '')
|
||||
const isOwner = computed(() => me.value?.role === 'owner')
|
||||
|
||||
function avatarUrl(member: Member): string | null {
|
||||
if (!member.avatar_updated_at) return null
|
||||
return `/api/avatars/${member.account_id}?v=${member.avatar_updated_at}`
|
||||
}
|
||||
|
||||
async function loadPeople() {
|
||||
peopleLoading.value = true
|
||||
peopleError.value = ''
|
||||
try {
|
||||
const detail = await api.get<RoomDetailResponse>(`/rooms/${props.roomId}`)
|
||||
people.value = detail.members
|
||||
me.value = detail.me
|
||||
} catch (err) {
|
||||
peopleError.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
peopleLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function create() {
|
||||
inviteLoading.value = true
|
||||
inviteError.value = ''
|
||||
try {
|
||||
invite.value = await api.post<Invite>(`/rooms/${props.roomId}/invites`)
|
||||
} catch (err) {
|
||||
inviteError.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
inviteLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function copy() {
|
||||
if (!inviteUrl.value) return
|
||||
try {
|
||||
await navigator.clipboard.writeText(inviteUrl.value)
|
||||
copied.value = true
|
||||
window.setTimeout(() => {
|
||||
copied.value = false
|
||||
}, 1800)
|
||||
} catch {
|
||||
inviteError.value = 'The clipboard is not available. Select the link and copy it by hand.'
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(member: Member) {
|
||||
removing.value = member.id
|
||||
removeError.value = ''
|
||||
try {
|
||||
await api.del(`/rooms/${props.roomId}/members/${member.id}`)
|
||||
people.value = people.value.filter((person) => person.id !== member.id)
|
||||
confirming.value = ''
|
||||
emit('removed', member.id)
|
||||
} catch (err) {
|
||||
removeError.value = apiErrorMessage(err)
|
||||
} finally {
|
||||
removing.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
void loadPeople()
|
||||
void create()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BaseDialog title="People" @close="emit('close')">
|
||||
<div class="people-section">
|
||||
<p v-if="peopleLoading" class="meta">Loading people.</p>
|
||||
<p v-else-if="peopleError" class="form-error" role="alert">{{ peopleError }}</p>
|
||||
<ul v-else class="people-list">
|
||||
<li v-for="person in people" :key="person.id" class="person-row">
|
||||
<template v-if="confirming === person.id">
|
||||
<div class="confirm-line person-confirm">
|
||||
<span>Remove {{ person.display_name }} from the room?</span>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-quiet"
|
||||
:disabled="removing === person.id"
|
||||
@click="confirming = ''"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-danger"
|
||||
:disabled="removing === person.id"
|
||||
@click="remove(person)"
|
||||
>
|
||||
{{ removing === person.id ? 'Removing' : 'Remove' }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<AppAvatar
|
||||
:name="person.display_name"
|
||||
:color="person.color"
|
||||
:src="avatarUrl(person)"
|
||||
:offline="!person.online"
|
||||
size="sm"
|
||||
/>
|
||||
<span class="person-name">{{ person.display_name }}</span>
|
||||
<span v-if="person.role === 'owner'" class="person-role">Owner</span>
|
||||
<button
|
||||
v-else-if="isOwner"
|
||||
type="button"
|
||||
class="icon-btn"
|
||||
:aria-label="`Remove ${person.display_name} from the room`"
|
||||
:title="`Remove ${person.display_name} from the room`"
|
||||
@click="confirming = person.id"
|
||||
>
|
||||
<X :size="14" aria-hidden="true" />
|
||||
</button>
|
||||
</template>
|
||||
</li>
|
||||
</ul>
|
||||
<p v-if="removeError" class="form-error" role="alert">{{ removeError }}</p>
|
||||
</div>
|
||||
|
||||
<div class="form invite-section">
|
||||
<div class="field">
|
||||
<label class="field-label" for="invite-url">Invite link</label>
|
||||
<p v-if="inviteLoading" class="meta">Creating the link.</p>
|
||||
<p v-else-if="inviteError && !invite" class="form-error" role="alert">{{ inviteError }}</p>
|
||||
<div v-if="invite" class="key-line">
|
||||
<input id="invite-url" class="input mono" :value="inviteUrl" readonly>
|
||||
<button type="button" class="btn" aria-label="Copy invite link" title="Copy invite link" @click="copy">
|
||||
<component :is="copied ? Check : Copy" :size="14" aria-hidden="true" />
|
||||
{{ copied ? 'Copied' : 'Copy' }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p v-if="invite" class="form-note">
|
||||
Anyone with this link can join {{ roomName }}. It works once and expires {{ formatDate(invite.expires_at) }}.
|
||||
</p>
|
||||
|
||||
<p v-if="inviteError && invite" class="form-error" role="alert">{{ inviteError }}</p>
|
||||
</div>
|
||||
|
||||
<div class="dialog-actions">
|
||||
<button type="button" class="btn" @click="emit('close')">Done</button>
|
||||
</div>
|
||||
</BaseDialog>
|
||||
</template>
|
||||
Reference in new issue
Block a user