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