2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2022-05-28 08:28:12 +03:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :style="`height: ${widgetProps.height}px;`" :scrollable="true" class="mkw-timeline">
|
2020-07-11 04:13:11 +03:00
|
|
|
<template #header>
|
2021-11-19 12:36:12 +02:00
|
|
|
<button class="_button" @click="choose">
|
2022-01-08 13:30:01 +02:00
|
|
|
<i v-if="widgetProps.src === 'home'" class="fas fa-home"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'local'" class="fas fa-comments"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'social'" class="fas fa-share-alt"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'global'" class="fas fa-globe"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'list'" class="fas fa-list-ul"></i>
|
|
|
|
<i v-else-if="widgetProps.src === 'antenna'" class="fas fa-satellite"></i>
|
|
|
|
<span style="margin-left: 8px;">{{ widgetProps.src === 'list' ? widgetProps.list.name : widgetProps.src === 'antenna' ? widgetProps.antenna.name : $t('_timelines.' + widgetProps.src) }}</span>
|
2021-04-20 17:22:59 +03:00
|
|
|
<i :class="menuOpened ? 'fas fa-angle-up' : 'fas fa-angle-down'" style="margin-left: 8px;"></i>
|
2020-07-11 04:13:11 +03:00
|
|
|
</button>
|
|
|
|
</template>
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2020-07-11 04:13:11 +03:00
|
|
|
<div>
|
2022-01-08 13:30:01 +02:00
|
|
|
<XTimeline :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 04:13:11 +03:00
|
|
|
</div>
|
2020-10-17 14:12:00 +03:00
|
|
|
</MkContainer>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
|
|
|
import * as os from '@/os';
|
2021-11-11 19:02:25 +02:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
|
|
|
import XTimeline from '@/components/timeline.vue';
|
2022-01-08 13:30:01 +02:00
|
|
|
import { $i } from '@/account';
|
|
|
|
import { i18n } from '@/i18n';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const name = 'timeline';
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-01-29 21:37:25 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02: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 21:37:25 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02:00
|
|
|
list: {
|
|
|
|
type: 'object' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 10:43:12 +03:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 13:30:01 +02:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const menuOpened = ref(false);
|
|
|
|
|
|
|
|
const setSrc = (src) => {
|
|
|
|
widgetProps.src = src;
|
|
|
|
save();
|
|
|
|
};
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const choose = async (ev) => {
|
|
|
|
menuOpened.value = true;
|
|
|
|
const [antennas, lists] = await Promise.all([
|
|
|
|
os.api('antennas/list'),
|
|
|
|
os.api('users/lists/list')
|
|
|
|
]);
|
|
|
|
const antennaItems = antennas.map(antenna => ({
|
|
|
|
text: antenna.name,
|
|
|
|
icon: 'fas fa-satellite',
|
|
|
|
action: () => {
|
|
|
|
widgetProps.antenna = antenna;
|
|
|
|
setSrc('antenna');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
const listItems = lists.map(list => ({
|
|
|
|
text: list.name,
|
|
|
|
icon: 'fas fa-list-ul',
|
|
|
|
action: () => {
|
|
|
|
widgetProps.list = list;
|
|
|
|
setSrc('list');
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
os.popupMenu([{
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts._timelines.home,
|
2022-01-08 13:30:01 +02:00
|
|
|
icon: 'fas fa-home',
|
|
|
|
action: () => { setSrc('home') }
|
|
|
|
}, {
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts._timelines.local,
|
2022-01-08 13:30:01 +02:00
|
|
|
icon: 'fas fa-comments',
|
|
|
|
action: () => { setSrc('local') }
|
|
|
|
}, {
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts._timelines.social,
|
2022-01-08 13:30:01 +02:00
|
|
|
icon: 'fas fa-share-alt',
|
|
|
|
action: () => { setSrc('social') }
|
|
|
|
}, {
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts._timelines.global,
|
2022-01-08 13:30:01 +02:00
|
|
|
icon: 'fas fa-globe',
|
|
|
|
action: () => { setSrc('global') }
|
2022-01-28 04:53:12 +02:00
|
|
|
}, antennaItems.length > 0 ? null : undefined, ...antennaItems, listItems.length > 0 ? null : undefined, ...listItems], ev.currentTarget ?? ev.target).then(() => {
|
2022-01-08 13:30:01 +02:00
|
|
|
menuOpened.value = false;
|
|
|
|
});
|
|
|
|
};
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 21:37:25 +02:00
|
|
|
});
|
|
|
|
</script>
|