Skip to content

Commit

Permalink
fix mock (MkPostForm, MkMediaImage)
Browse files Browse the repository at this point in the history
  • Loading branch information
taiyme committed May 2, 2024
1 parent eab973d commit b31e21a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 5 additions & 3 deletions packages/frontend/src/components/MkMediaImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</template>

<script lang="ts" setup>
import { computed, ref, watch } from 'vue';
import { computed, inject, ref, watch } from 'vue';
import * as Misskey from 'misskey-js';
import { $i, iAmModerator } from '@/account.js';
import { i18n } from '@/i18n.js';
Expand All @@ -125,6 +125,8 @@ const props = withDefaults(defineProps<{
controls: true,
});
const mock = inject<boolean>('mock', false);
const reactiveImage = ref(deepClone(props.image));
const hide = ref(true);
Expand Down Expand Up @@ -196,7 +198,7 @@ const getMenu = (): MenuItem[] => {
hide.value = true;
},
});
if (iAmOwner.value) {
if (!mock && iAmOwner.value) {
menu.push({ type: 'divider' });
menu.push({
type: 'link',
Expand All @@ -205,7 +207,7 @@ const getMenu = (): MenuItem[] => {
icon: 'ti ti-info-circle',
});
}
if (iAmModerator) {
if (!mock && iAmModerator) {
menu.push({ type: 'divider' });
menu.push({
type: 'label',
Expand Down
22 changes: 20 additions & 2 deletions packages/frontend/src/components/MkPostForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<div :class="$style.footerLeft">
<button v-tooltip="i18n.ts.attachFile" class="_button" :class="$style.footerButton" @click="chooseFileFrom"><i class="ti ti-photo-plus"></i></button>
<button v-tooltip="i18n.ts.poll" class="_button" :class="[$style.footerButton, { [$style.footerButtonActive]: poll }]" @click="togglePoll"><i class="ti ti-chart-arrows"></i></button>
<button v-tooltip="i18n.ts.useCw" class="_button" :class="[$style.footerButton, { [$style.footerButtonActive]: useCw }]" @click="useCw = !useCw"><i class="ti ti-eye-off"></i></button>
<button v-tooltip="i18n.ts.useCw" class="_button" :class="[$style.footerButton, { [$style.footerButtonActive]: useCw }]" @click="toggleUseCw"><i class="ti ti-eye-off"></i></button>
<button v-tooltip="i18n.ts.mention" class="_button" :class="$style.footerButton" @click="insertMention"><i class="ti ti-at"></i></button>
<button v-tooltip="i18n.ts.hashtags" class="_button" :class="[$style.footerButton, { [$style.footerButtonActive]: withHashtags }]" @click="withHashtags = !withHashtags"><i class="ti ti-hash"></i></button>
<button v-tooltip="i18n.ts.hashtags" class="_button" :class="[$style.footerButton, { [$style.footerButtonActive]: withHashtags }]" @click="toggleWithHashtags"><i class="ti ti-hash"></i></button>
<button v-if="postFormActions.length > 0" v-tooltip="i18n.ts.plugins" class="_button" :class="$style.footerButton" @click="showActions"><i class="ti ti-plug"></i></button>
<button v-tooltip="i18n.ts.emoji" :class="['_button', $style.footerButton]" @click="insertEmoji"><i class="ti ti-mood-happy"></i></button>
<button v-if="showAddMfmFunction" v-tooltip="i18n.ts.addMfmFunction" :class="['_button', $style.footerButton]" @click="insertMfmFunction"><i class="ti ti-palette"></i></button>
Expand Down Expand Up @@ -396,6 +396,7 @@ function addMissingMention() {
}
function togglePoll() {
if (props.mock) return;
if (poll.value) {
poll.value = null;
} else {
Expand Down Expand Up @@ -457,6 +458,7 @@ function upload(file: File, name?: string): void {
}
function setVisibility() {
if (props.mock) return;
if (props.channel) {
visibility.value = 'public';
localOnly.value = true; // TODO: チャンネルが連合するようになった折には消す
Expand All @@ -480,6 +482,7 @@ function setVisibility() {
}
async function toggleLocalOnly() {
if (props.mock) return;
if (props.channel) {
visibility.value = 'public';
localOnly.value = true; // TODO: チャンネルが連合するようになった折には消す
Expand Down Expand Up @@ -525,6 +528,7 @@ async function toggleLocalOnly() {
}
async function toggleReactionAcceptance() {
if (props.mock) return;
const select = await os.select({
title: i18n.ts.reactionAcceptance,
items: [
Expand All @@ -540,6 +544,16 @@ async function toggleReactionAcceptance() {
reactionAcceptance.value = select.result;
}
function toggleUseCw() {
if (props.mock) return;
useCw.value = !useCw.value;
}
function toggleWithHashtags() {
if (props.mock) return;
withHashtags.value = !withHashtags.value;
}
function pushVisibleUser(user: Misskey.entities.UserDetailed) {
if (!visibleUsers.value.some(u => u.username === user.username && u.host === user.host)) {
visibleUsers.value.push(user);
Expand Down Expand Up @@ -872,12 +886,14 @@ function cancel() {
}
function insertMention() {
if (props.mock) return;
os.selectUser({ localOnly: localOnly.value, includeSelf: true }).then(user => {
insertTextAtCursor(textareaEl.value, '@' + Misskey.acct.toString(user) + ' ');
});
}
async function insertEmoji(ev: MouseEvent) {
if (props.mock) return;
textAreaReadOnly.value = true;
const target = ev.currentTarget ?? ev.target;
if (target == null) return;
Expand All @@ -894,6 +910,7 @@ async function insertEmoji(ev: MouseEvent) {
}
async function insertMfmFunction(ev: MouseEvent) {
if (props.mock) return;
if (textareaEl.value == null) return;
mfmFunctionPicker(
ev.currentTarget ?? ev.target,
Expand All @@ -903,6 +920,7 @@ async function insertMfmFunction(ev: MouseEvent) {
}
function showActions(ev: MouseEvent) {
if (props.mock) return;
os.popupMenu(postFormActions.map(action => ({
text: action.title,
action: () => {
Expand Down

0 comments on commit b31e21a

Please sign in to comment.