paricafe/packages/frontend/src/ui/_common_/statusbar-rss.vue

93 lines
2 KiB
Vue
Raw Normal View History

<template>
<span v-if="!fetching" class="xbhtxfms">
<template v-if="display === 'marquee'">
2022-12-29 22:37:14 -06:00
<Transition name="change" mode="default">
<MarqueeText :key="key" :duration="marqueeDuration" :reverse="marqueeReverse">
<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>
</MarqueeText>
2022-12-29 22:37:14 -06:00
</Transition>
</template>
<template v-else-if="display === 'oneByOne'">
<!-- TODO -->
</template>
</span>
</template>
<script lang="ts" setup>
import { ref } from 'vue';
import MarqueeText from '@/components/MkMarquee.vue';
import { useInterval } from '@/scripts/use-interval';
import { shuffle } from '@/scripts/shuffle';
const props = defineProps<{
url?: string;
shuffle?: boolean;
display?: 'marquee' | 'oneByOne';
marqueeDuration?: number;
marqueeReverse?: boolean;
oneByOneInterval?: number;
refreshIntervalSec?: number;
}>();
const items = ref([]);
const fetching = ref(true);
let key = $ref(0);
const tick = () => {
window.fetch(`/api/fetch-rss?url=${props.url}`, {}).then(res => {
res.json().then(feed => {
if (props.shuffle) {
shuffle(feed.items);
}
items.value = feed.items;
fetching.value = false;
key++;
});
});
};
useInterval(tick, Math.max(5000, props.refreshIntervalSec * 1000), {
immediate: true,
afterMounted: true,
});
</script>
<style lang="scss" scoped>
.change-enter-active, .change-leave-active {
position: absolute;
top: 0;
transition: all 1s ease;
}
.change-enter-from {
opacity: 0;
transform: translateY(-100%);
}
.change-leave-to {
opacity: 0;
transform: translateY(100%);
}
.xbhtxfms {
display: inline-block;
position: relative;
::v-deep(.item) {
display: inline-flex;
align-items: center;
vertical-align: bottom;
margin: 0;
> .divider {
display: inline-block;
width: 0.5px;
height: var(--height);
2022-07-07 03:28:21 -05:00
margin: 0 3em;
background: currentColor;
2022-07-03 02:36:13 -05:00
opacity: 0.3;
}
}
}
</style>