client: disable unavailable visibilities

This commit is contained in:
Johann150 2023-01-01 21:02:55 +01:00
parent 3a9d283630
commit 338e898f56
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
2 changed files with 16 additions and 10 deletions

View file

@ -393,8 +393,8 @@ function setVisibility() {
}
os.popup(defineAsyncComponent(() => import('./visibility-picker.vue')), {
currentVisibility: visibility,
currentLocalOnly: localOnly,
parentVisibility: visibility,
parentLocalOnly: localOnly,
src: visibilityButton,
}, {
changeVisibility: v => {

View file

@ -1,28 +1,28 @@
<template>
<MkModal ref="modal" :z-priority="'high'" :src="src" @click="modal.close()" @closed="emit('closed')">
<div class="gqyayizv _popup">
<button key="public" class="_button" :class="{ active: v === 'public' }" data-index="1" @click="choose('public')">
<button key="public" :disabled="disabled['public']" class="_button" :class="{ active: v === 'public' }" data-index="1" @click="choose('public')">
<div><i class="fas fa-globe"></i></div>
<div>
<span>{{ i18n.ts._visibility.public }}</span>
<span>{{ i18n.ts._visibility.publicDescription }}</span>
</div>
</button>
<button key="home" class="_button" :class="{ active: v === 'home' }" data-index="2" @click="choose('home')">
<button key="home" :disabled="disabled['home']" class="_button" :class="{ active: v === 'home' }" data-index="2" @click="choose('home')">
<div><i class="fas fa-home"></i></div>
<div>
<span>{{ i18n.ts._visibility.home }}</span>
<span>{{ i18n.ts._visibility.homeDescription }}</span>
</div>
</button>
<button key="followers" class="_button" :class="{ active: v === 'followers' }" data-index="3" @click="choose('followers')">
<button key="followers" :disabled="disabled['followers']" class="_button" :class="{ active: v === 'followers' }" data-index="3" @click="choose('followers')">
<div><i class="fas fa-unlock"></i></div>
<div>
<span>{{ i18n.ts._visibility.followers }}</span>
<span>{{ i18n.ts._visibility.followersDescription }}</span>
</div>
</button>
<button key="specified" :disabled="localOnly" class="_button" :class="{ active: v === 'specified' }" data-index="4" @click="choose('specified')">
<button key="specified" :disabled="localOnly || disabled['specified']" class="_button" :class="{ active: v === 'specified' }" data-index="4" @click="choose('specified')">
<div><i class="fas fa-envelope"></i></div>
<div>
<span>{{ i18n.ts._visibility.specified }}</span>
@ -51,7 +51,8 @@ import { i18n } from '@/i18n';
const modal = $ref<InstanceType<typeof MkModal>>();
const props = withDefaults(defineProps<{
currentVisibility: typeof foundkey.noteVisibilities[number];
parentVisibility: foundkey.NoteVisibility;
parentLocalOnly: boolean;
currentLocalOnly: boolean;
src?: HTMLElement;
}>(), {
@ -63,14 +64,19 @@ const emit = defineEmits<{
(ev: 'closed'): void;
}>();
let v = $ref(props.currentVisibility);
let localOnly = $ref(props.currentLocalOnly);
let v = $ref(props.parentVisibility);
let localOnly = $ref(props.parentLocalOnly);
const disabled = foundkey.noteVisibilities.reduce((acc, visibility) => {
acc[visibility] = (visibility !== foundkey.minVisibility(visibility, props.parentVisibility));
return acc;
}, {});
watch($$(localOnly), () => {
emit('changeLocalOnly', localOnly);
});
function choose(visibility: typeof foundkey.noteVisibilities[number]): void {
function choose(visibility: typeof foundkey.NoteVisibility): void {
v = visibility;
emit('changeVisibility', visibility);
nextTick(() => {