2023-07-27 14:31:52 +09:00
|
|
|
<!--
|
2024-02-14 00:59:27 +09:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 14:31:52 +09:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-12-05 22:29:55 +09:00
|
|
|
<template>
|
2023-03-09 19:59:11 +09:00
|
|
|
<div data-cy-mkw-slideshow class="kvausudm _panel mkw-slideshow" :style="{ height: widgetProps.height + 'px' }">
|
2020-12-05 22:29:55 +09:00
|
|
|
<div @click="choose">
|
2022-01-08 20:30:01 +09:00
|
|
|
<p v-if="widgetProps.folderId == null">
|
2022-07-20 22:24:26 +09:00
|
|
|
{{ i18n.ts.folder }}
|
2020-12-05 22:29:55 +09:00
|
|
|
</p>
|
2024-01-20 08:11:59 +09:00
|
|
|
<p v-if="widgetProps.folderId != null && images.length === 0 && !fetching">{{ i18n.ts['no-image'] }}</p>
|
2020-12-05 22:29:55 +09:00
|
|
|
<div ref="slideA" class="slide a"></div>
|
|
|
|
<div ref="slideB" class="slide b"></div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 23:09:41 +09:00
|
|
|
import { onMounted, ref, shallowRef } from 'vue';
|
2023-12-26 14:19:35 +09:00
|
|
|
import * as Misskey from 'misskey-js';
|
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';
|
2024-01-04 18:32:46 +09:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 16:37:43 +09:00
|
|
|
import { useInterval } from '@/scripts/use-interval.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2020-12-05 22:29:55 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const name = 'slideshow';
|
2020-12-05 22:29:55 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const widgetPropsDef = {
|
|
|
|
height: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 300,
|
2020-12-05 22:29:55 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
folderId: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: null,
|
|
|
|
hidden: true,
|
2020-12-05 22:29:55 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
2023-12-26 14:19:35 +09:00
|
|
|
const images = ref<Misskey.entities.DriveFile[]>([]);
|
2022-01-08 20:30:01 +09:00
|
|
|
const fetching = ref(true);
|
2023-01-03 10:12:37 +09:00
|
|
|
const slideA = shallowRef<HTMLElement>();
|
|
|
|
const slideB = shallowRef<HTMLElement>();
|
2022-01-08 20:30:01 +09:00
|
|
|
|
|
|
|
const change = () => {
|
2022-05-25 16:43:12 +09:00
|
|
|
if (images.value.length === 0) return;
|
2022-01-08 20:30:01 +09:00
|
|
|
|
|
|
|
const index = Math.floor(Math.random() * images.value.length);
|
|
|
|
const img = `url(${ images.value[index].url })`;
|
|
|
|
|
|
|
|
slideB.value.style.backgroundImage = img;
|
|
|
|
|
|
|
|
slideB.value.classList.add('anime');
|
2022-01-16 10:14:14 +09:00
|
|
|
window.setTimeout(() => {
|
2022-01-08 20:30:01 +09:00
|
|
|
// 既にこのウィジェットがunmountされていたら要素がない
|
|
|
|
if (slideA.value == null) return;
|
|
|
|
|
|
|
|
slideA.value.style.backgroundImage = img;
|
|
|
|
|
|
|
|
slideB.value.classList.remove('anime');
|
|
|
|
}, 1000);
|
|
|
|
};
|
|
|
|
|
|
|
|
const fetch = () => {
|
|
|
|
fetching.value = true;
|
|
|
|
|
2024-01-04 18:32:46 +09:00
|
|
|
misskeyApi('drive/files', {
|
2022-01-08 20:30:01 +09:00
|
|
|
folderId: widgetProps.folderId,
|
|
|
|
type: 'image/*',
|
2022-06-26 03:12:58 +09:00
|
|
|
limit: 100,
|
2022-01-08 20:30:01 +09:00
|
|
|
}).then(res => {
|
|
|
|
images.value = res;
|
|
|
|
fetching.value = false;
|
|
|
|
slideA.value.style.backgroundImage = '';
|
|
|
|
slideB.value.style.backgroundImage = '';
|
|
|
|
change();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const choose = () => {
|
|
|
|
os.selectDriveFolder(false).then(folder => {
|
|
|
|
if (folder == null) {
|
|
|
|
return;
|
2020-12-05 22:29:55 +09:00
|
|
|
}
|
2022-01-08 20:30:01 +09:00
|
|
|
widgetProps.folderId = folder.id;
|
|
|
|
save();
|
|
|
|
fetch();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2022-06-26 03:12:58 +09:00
|
|
|
useInterval(change, 10000, {
|
|
|
|
immediate: false,
|
|
|
|
afterMounted: true,
|
|
|
|
});
|
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
onMounted(() => {
|
|
|
|
if (widgetProps.folderId != null) {
|
|
|
|
fetch();
|
2020-12-05 22:29:55 +09:00
|
|
|
}
|
2022-01-08 20:30:01 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-12-05 22:29:55 +09:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 18:29:39 +09:00
|
|
|
<style lang="scss" scoped>
|
2020-12-05 22:29:55 +09:00
|
|
|
.kvausudm {
|
|
|
|
position: relative;
|
|
|
|
|
|
|
|
> div {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
> p {
|
|
|
|
display: block;
|
|
|
|
margin: 1em;
|
|
|
|
text-align: center;
|
|
|
|
color: #888;
|
|
|
|
}
|
|
|
|
|
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .slide {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
background-size: cover;
|
|
|
|
background-position: center;
|
|
|
|
|
|
|
|
&.b {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.anime {
|
|
|
|
transition: opacity 1s;
|
|
|
|
opacity: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|