mizzkey/packages/frontend/src/pages/settings/notifications.notification-config.vue

76 lines
2.1 KiB
Vue
Raw Normal View History

2023-09-29 11:29:54 +09:00
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
2023-09-29 11:29:54 +09:00
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<div class="_gaps_m">
<MkSelect v-model="type">
<option v-for="type in props.configurableTypes ?? notificationConfigTypes" :key="type" :value="type">{{ notificationConfigTypesI18nMap[type] }}</option>
2023-09-29 11:29:54 +09:00
</MkSelect>
<MkSelect v-if="type === 'list'" v-model="userListId">
<template #label>{{ i18n.ts.userList }}</template>
<option v-for="list in props.userLists" :key="list.id" :value="list.id">{{ list.name }}</option>
</MkSelect>
<div class="_buttons">
<MkButton inline primary :disabled="type === 'list' && userListId === null" @click="save"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
2023-09-29 11:29:54 +09:00
</div>
</div>
</template>
<script lang="ts">
const notificationConfigTypes = [
'all',
'following',
'follower',
'mutualFollow',
'followingOrFollower',
'list',
'never'
] as const;
export type NotificationConfig = {
type: Exclude<typeof notificationConfigTypes[number], 'list'>;
} | {
type: 'list';
userListId: string;
};
</script>
2023-09-29 11:29:54 +09:00
<script lang="ts" setup>
import * as Misskey from 'misskey-js';
import { ref } from 'vue';
2023-09-29 11:29:54 +09:00
import MkSelect from '@/components/MkSelect.vue';
import MkButton from '@/components/MkButton.vue';
import { i18n } from '@/i18n.js';
const props = defineProps<{
value: NotificationConfig;
2023-09-29 11:29:54 +09:00
userLists: Misskey.entities.UserList[];
configurableTypes?: NotificationConfig['type'][]; // If not specified, all types are configurable
2023-09-29 11:29:54 +09:00
}>();
const emit = defineEmits<{
(ev: 'update', result: NotificationConfig): void;
2023-09-29 11:29:54 +09:00
}>();
const notificationConfigTypesI18nMap: Record<typeof notificationConfigTypes[number], string> = {
all: i18n.ts.all,
following: i18n.ts.following,
follower: i18n.ts.followers,
mutualFollow: i18n.ts.mutualFollow,
followingOrFollower: i18n.ts.followingOrFollower,
list: i18n.ts.userList,
never: i18n.ts.none,
};
const type = ref(props.value.type);
const userListId = ref(props.value.type === 'list' ? props.value.userListId : null);
2023-09-29 11:29:54 +09:00
function save() {
emit('update', type.value === 'list' ? { type: type.value, userListId: userListId.value! } : { type: type.value });
2023-09-29 11:29:54 +09:00
}
</script>