misskey-awawa/packages/client/src/widgets/rss-marquee.vue

130 lines
3.1 KiB
Vue
Raw Normal View History

2022-06-30 14:45:11 +00:00
<template>
<MkContainer :naked="widgetProps.transparent" :show-header="widgetProps.showHeader" class="mkw-rss-marquee">
<template #header><i class="fas fa-rss-square"></i>RSS</template>
<template #func><button class="_button" @click="configure"><i class="fas fa-cog"></i></button></template>
<div class="ekmkgxbk">
<MkLoading v-if="fetching"/>
<div v-else class="feed">
2022-06-30 14:53:58 +00:00
<MarqueeText :key="key" :duration="widgetProps.speed" :reverse="widgetProps.reverse">
2022-07-01 06:23:49 +00:00
<span v-for="item in items" class="item">
<a class="link" :href="item.link" rel="nofollow noopener" target="_blank" :title="item.title">{{ item.title }}</a><span class="divider"></span>
</span>
2022-06-30 14:45:11 +00:00
</MarqueeText>
</div>
</div>
</MkContainer>
</template>
<script lang="ts" setup>
import { onMounted, onUnmounted, ref, watch } from 'vue';
import MarqueeText from 'vue-marquee-text-component';
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
import { GetFormResultType } from '@/scripts/form';
import * as os from '@/os';
import MkContainer from '@/components/ui/container.vue';
import { useInterval } from '@/scripts/use-interval';
const name = 'rssMarquee';
const widgetPropsDef = {
url: {
type: 'string' as const,
default: 'http://feeds.afpbb.com/rss/afpbb/afpbbnews',
},
showHeader: {
type: 'boolean' as const,
default: false,
},
transparent: {
type: 'boolean' as const,
default: false,
},
speed: {
type: 'radio' as const,
default: 70,
options: [{
value: 170, label: 'very slow',
}, {
value: 100, label: 'slow',
}, {
value: 70, label: 'medium',
}, {
value: 40, label: 'fast',
}, {
value: 20, label: 'very fast',
}],
},
reverse: {
type: 'boolean' as const,
default: false,
},
};
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
const { widgetProps, configure } = useWidgetPropsManager(name,
widgetPropsDef,
props,
emit,
);
const items = ref([]);
const fetching = ref(true);
2022-06-30 14:53:58 +00:00
let key = $ref(0);
2022-06-30 14:45:11 +00:00
const tick = () => {
fetch(`/api/fetch-rss?url=${widgetProps.url}`, {}).then(res => {
2022-06-30 14:45:11 +00:00
res.json().then(feed => {
items.value = feed.items;
fetching.value = false;
2022-06-30 14:53:58 +00:00
key++;
2022-06-30 14:45:11 +00:00
});
});
};
watch(() => widgetProps.url, tick);
useInterval(tick, 60000, {
immediate: true,
afterMounted: true,
});
defineExpose<WidgetComponentExpose>({
name,
configure,
id: props.widget ? props.widget.id : null,
});
</script>
<style lang="scss" scoped>
.ekmkgxbk {
> .feed {
padding: 0;
font-size: 0.9em;
::v-deep(.item) {
2022-07-01 06:23:49 +00:00
display: inline-flex;
align-items: center;
vertical-align: bottom;
2022-06-30 14:45:11 +00:00
color: var(--fg);
2022-07-01 06:23:49 +00:00
margin: 12px 0;
> .divider {
display: inline-block;
width: 0.5px;
height: 16px;
margin: 0 1em;
background: var(--divider);
}
2022-06-30 14:45:11 +00:00
}
}
}
</style>