mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-15 02:03:09 +02:00
708fba989a
* test(e2e): add baseline for widget tests * chore(repo): enable test running in branch * fix(e2e): set viewport for widget tests * fix(client): add widget identifier classes to widgets * test(e2e): add memo widget test * fix(tests): force select value * fix(tests): force button press for widget addition * fix(tests): invoke select value differently * fix(tests): adjust widget submit * fix(tests): don't explicitly navigate for widget test * fix(tests): click label to hide select popup * fix(tests): just click modal background * fix(tests): adjust modal background selector * fix(tests): click all modal backgrounds * feat(e2e): add test for adding timeline widget * fix(client): add more widget identifier classes * feat(tests): add method abstraction for test cases * fix(tests): force-click overlays * fix(tests): force widget button press * fix(tests): remove timeout from final widget check * feat(tests): add widget removal test case * fix(client): use mk instead of msky as class prefix * fix(tests): check widgets for existence rather than visibility * chore(meta): don't run tests for specific feature branch
121 lines
2.9 KiB
Vue
121 lines
2.9 KiB
Vue
<template>
|
|
<MkContainer :show-header="widgetProps.showHeader" :naked="widgetProps.transparent" :class="$style.root" :data-transparent="widgetProps.transparent ? true : null" class="mkw-photos">
|
|
<template #header><i class="fas fa-camera"></i>{{ $ts._widgets.photos }}</template>
|
|
|
|
<div class="">
|
|
<MkLoading v-if="fetching"/>
|
|
<div v-else :class="$style.stream">
|
|
<div v-for="(image, i) in images" :key="i"
|
|
:class="$style.img"
|
|
:style="`background-image: url(${thumbnail(image)})`"
|
|
></div>
|
|
</div>
|
|
</div>
|
|
</MkContainer>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { onMounted, onUnmounted, reactive, ref } from 'vue';
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
|
import { stream } from '@/stream';
|
|
import { getStaticImageUrl } from '@/scripts/get-static-image-url';
|
|
import * as os from '@/os';
|
|
import MkContainer from '@/components/ui/container.vue';
|
|
import { defaultStore } from '@/store';
|
|
|
|
const name = 'photos';
|
|
|
|
const widgetPropsDef = {
|
|
showHeader: {
|
|
type: 'boolean' as const,
|
|
default: true,
|
|
},
|
|
transparent: {
|
|
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 connection = stream.useChannel('main');
|
|
const images = ref([]);
|
|
const fetching = ref(true);
|
|
|
|
const onDriveFileCreated = (file) => {
|
|
if (/^image\/.+$/.test(file.type)) {
|
|
images.value.unshift(file);
|
|
if (images.value.length > 9) images.value.pop();
|
|
}
|
|
};
|
|
|
|
const thumbnail = (image: any): string => {
|
|
return defaultStore.state.disableShowingAnimatedImages
|
|
? getStaticImageUrl(image.thumbnailUrl)
|
|
: image.thumbnailUrl;
|
|
};
|
|
|
|
os.api('drive/stream', {
|
|
type: 'image/*',
|
|
limit: 9
|
|
}).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,
|
|
});
|
|
</script>
|
|
|
|
<style lang="scss" module>
|
|
.root[data-transparent] {
|
|
.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>
|