2023-07-27 14:31:52 +09:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2023-05-19 16:20:53 +09:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" :style="`height: ${widgetProps.height}px;`" :scrollable="true" data-cy-mkw-timeline class="mkw-timeline">
|
2023-01-15 08:30:29 +09:00
|
|
|
<template #icon>
|
|
|
|
<i v-if="widgetProps.src === 'home'" class="ti ti-home"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'local'" class="ti ti-planet"></i>
|
2023-09-29 15:14:18 +09:00
|
|
|
<i v-else-if="widgetProps.src === 'social'" class="ti ti-universe"></i>
|
2023-01-15 08:30:29 +09:00
|
|
|
<i v-else-if="widgetProps.src === 'global'" class="ti ti-whirl"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'list'" class="ti ti-list"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'antenna'" class="ti ti-antenna"></i>
|
|
|
|
</template>
|
2020-07-11 10:13:11 +09:00
|
|
|
<template #header>
|
2021-11-19 19:36:12 +09:00
|
|
|
<button class="_button" @click="choose">
|
2023-04-01 14:01:57 +09:00
|
|
|
<span>{{ widgetProps.src === 'list' ? widgetProps.list.name : widgetProps.src === 'antenna' ? widgetProps.antenna.name : i18n.t('_timelines.' + widgetProps.src) }}</span>
|
2022-12-19 19:01:30 +09:00
|
|
|
<i :class="menuOpened ? 'ti ti-chevron-up' : 'ti ti-chevron-down'" style="margin-left: 8px;"></i>
|
2020-07-11 10:13:11 +09:00
|
|
|
</button>
|
|
|
|
</template>
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-03-12 10:20:33 +09:00
|
|
|
<div v-if="(((widgetProps.src === 'local' || widgetProps.src === 'social') && !isLocalTimelineAvailable) || (widgetProps.src === 'global' && !isGlobalTimelineAvailable))" :class="$style.disabled">
|
|
|
|
<p :class="$style.disabledTitle">
|
|
|
|
<i class="ti ti-minus"></i>
|
|
|
|
{{ i18n.ts._disabledTimeline.title }}
|
|
|
|
</p>
|
|
|
|
<p :class="$style.disabledDescription">{{ i18n.ts._disabledTimeline.description }}</p>
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
2023-02-22 11:00:34 +09:00
|
|
|
<MkTimeline :key="widgetProps.src === 'list' ? `list:${widgetProps.list.id}` : widgetProps.src === 'antenna' ? `antenna:${widgetProps.antenna.id}` : widgetProps.src" :src="widgetProps.src" :list="widgetProps.list ? widgetProps.list.id : null" :antenna="widgetProps.antenna ? widgetProps.antenna.id : null"/>
|
2020-07-11 10:13:11 +09:00
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 23:09:41 +09:00
|
|
|
import { ref } from 'vue';
|
2023-12-21 11:36:45 +09:00
|
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
|
|
|
import * as os from '@/os.js';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-02-22 11:00:34 +09:00
|
|
|
import MkTimeline from '@/components/MkTimeline.vue';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { $i } from '@/account.js';
|
|
|
|
import { instance } from '@/instance.js';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const name = 'timeline';
|
2023-03-12 10:20:33 +09:00
|
|
|
const isLocalTimelineAvailable = (($i == null && instance.policies.ltlAvailable) || ($i != null && $i.policies.ltlAvailable));
|
|
|
|
const isGlobalTimelineAvailable = (($i == null && instance.policies.gtlAvailable) || ($i != null && $i.policies.gtlAvailable));
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
height: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 300,
|
|
|
|
},
|
|
|
|
src: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: 'home',
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
antenna: {
|
|
|
|
type: 'object' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
2020-01-30 04:37:25 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
list: {
|
|
|
|
type: 'object' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 16:20:53 +09:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 20:30:01 +09:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const menuOpened = ref(false);
|
|
|
|
|
|
|
|
const setSrc = (src) => {
|
|
|
|
widgetProps.src = src;
|
|
|
|
save();
|
|
|
|
};
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const choose = async (ev) => {
|
|
|
|
menuOpened.value = true;
|
|
|
|
const [antennas, lists] = await Promise.all([
|
|
|
|
os.api('antennas/list'),
|
2022-12-22 16:01:59 +09:00
|
|
|
os.api('users/lists/list'),
|
2022-01-08 20:30:01 +09:00
|
|
|
]);
|
|
|
|
const antennaItems = antennas.map(antenna => ({
|
|
|
|
text: antenna.name,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-antenna',
|
2022-01-08 20:30:01 +09:00
|
|
|
action: () => {
|
|
|
|
widgetProps.antenna = antenna;
|
|
|
|
setSrc('antenna');
|
2022-12-22 16:01:59 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
}));
|
|
|
|
const listItems = lists.map(list => ({
|
|
|
|
text: list.name,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-list',
|
2022-01-08 20:30:01 +09:00
|
|
|
action: () => {
|
|
|
|
widgetProps.list = list;
|
|
|
|
setSrc('list');
|
2022-12-22 16:01:59 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
}));
|
|
|
|
os.popupMenu([{
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.home,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-home',
|
2022-12-22 16:01:59 +09:00
|
|
|
action: () => { setSrc('home'); },
|
2022-01-08 20:30:01 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.local,
|
2022-12-31 20:40:47 +09:00
|
|
|
icon: 'ti ti-planet',
|
2022-12-22 16:01:59 +09:00
|
|
|
action: () => { setSrc('local'); },
|
2022-01-08 20:30:01 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.social,
|
2023-09-29 15:14:18 +09:00
|
|
|
icon: 'ti ti-universe',
|
2022-12-22 16:01:59 +09:00
|
|
|
action: () => { setSrc('social'); },
|
2022-01-08 20:30:01 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts._timelines.global,
|
2022-12-31 20:40:47 +09:00
|
|
|
icon: 'ti ti-whirl',
|
2022-12-22 16:01:59 +09:00
|
|
|
action: () => { setSrc('global'); },
|
2023-12-12 10:26:37 +09:00
|
|
|
}, antennaItems.length > 0 ? { type: 'divider' } : undefined, ...antennaItems, listItems.length > 0 ? { type: 'divider' } : undefined, ...listItems], ev.currentTarget ?? ev.target).then(() => {
|
2022-01-08 20:30:01 +09:00
|
|
|
menuOpened.value = false;
|
|
|
|
});
|
|
|
|
};
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
</script>
|
2023-03-12 10:20:33 +09:00
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.disabled {
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.disabledTitle {
|
|
|
|
margin: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.disabledDescription {
|
|
|
|
font-size: 90%;
|
|
|
|
}
|
|
|
|
</style>
|