2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-12 03:37:45 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-02-18 11:47:30 +01:00
|
|
|
<template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" :naked="widgetProps.transparent" :class="$style.root" :data-transparent="widgetProps.transparent ? true : null" data-cy-mkw-photos class="mkw-photos">
|
2023-01-15 00:30:29 +01:00
|
|
|
<template #icon><i class="ti ti-camera"></i></template>
|
|
|
|
<template #header>{{ i18n.ts._widgets.photos }}</template>
|
2020-02-18 11:47:30 +01:00
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
<div class="">
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkLoading v-if="fetching"/>
|
2020-07-11 03:13:11 +02:00
|
|
|
<div v-else :class="$style.stream">
|
2022-07-20 15:24:26 +02:00
|
|
|
<div
|
|
|
|
v-for="(image, i) in images" :key="i"
|
2020-07-11 03:13:11 +02:00
|
|
|
:class="$style.img"
|
|
|
|
:style="`background-image: url(${thumbnail(image)})`"
|
|
|
|
></div>
|
2020-02-18 11:47:30 +01:00
|
|
|
</div>
|
2020-07-11 03:13:11 +02:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkContainer>
|
2020-02-18 11:47:30 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 15:09:41 +01:00
|
|
|
import { onUnmounted, ref } from 'vue';
|
2023-12-26 06:19:35 +01:00
|
|
|
import * as Misskey from 'misskey-js';
|
2023-12-21 03:36:45 +01:00
|
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
|
|
|
import { useStream } from '@/stream.js';
|
|
|
|
import { getStaticImageUrl } from '@/scripts/media-proxy.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { defaultStore } from '@/store.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2020-02-18 11:47:30 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'photos';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-02-18 11:47:30 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2020-02-18 11:47:30 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-05-15 12:08:46 +02:00
|
|
|
const connection = useStream().useChannel('main');
|
2023-12-26 06:19:35 +01:00
|
|
|
const images = ref<Misskey.entities.DriveFile[]>([]);
|
2022-01-08 12:30:01 +01:00
|
|
|
const fetching = ref(true);
|
|
|
|
|
|
|
|
const onDriveFileCreated = (file) => {
|
|
|
|
if (/^image\/.+$/.test(file.type)) {
|
|
|
|
images.value.unshift(file);
|
|
|
|
if (images.value.length > 9) images.value.pop();
|
2020-02-18 11:47:30 +01:00
|
|
|
}
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const thumbnail = (image: any): string => {
|
|
|
|
return defaultStore.state.disableShowingAnimatedImages
|
2023-03-11 06:11:40 +01:00
|
|
|
? getStaticImageUrl(image.url)
|
2022-01-08 12:30:01 +01:00
|
|
|
: image.thumbnailUrl;
|
|
|
|
};
|
|
|
|
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/stream', {
|
2022-01-08 12:30:01 +01:00
|
|
|
type: 'image/*',
|
2022-07-20 15:24:26 +02:00
|
|
|
limit: 9,
|
2022-01-08 12:30:01 +01:00
|
|
|
}).then(res => {
|
|
|
|
images.value = res;
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
connection.on('driveFileCreated', onDriveFileCreated);
|
|
|
|
onUnmounted(() => {
|
|
|
|
connection.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-02-18 11:47:30 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
2020-07-11 03:13:11 +02:00
|
|
|
.root[data-transparent] {
|
2020-02-18 11:47:30 +01:00
|
|
|
.stream {
|
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.img {
|
|
|
|
border: solid 4px transparent;
|
|
|
|
border-radius: 8px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.stream {
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
.img {
|
|
|
|
flex: 1 1 33%;
|
|
|
|
width: 33%;
|
|
|
|
height: 80px;
|
|
|
|
box-sizing: border-box;
|
|
|
|
background-position: center center;
|
|
|
|
background-size: cover;
|
|
|
|
background-clip: content-box;
|
|
|
|
border: solid 2px transparent;
|
|
|
|
border-radius: 4px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|