2018-02-23 11:46:09 -06:00
|
|
|
<template>
|
|
|
|
<div class="mkw-photo-stream" :class="$style.root" :data-melt="props.design == 2">
|
|
|
|
<mk-widget-container :show-header="props.design == 0" :naked="props.design == 2">
|
2018-04-14 11:04:40 -05:00
|
|
|
<template slot="header">%fa:camera%%i18n:@title%</template>
|
2018-02-23 11:46:09 -06:00
|
|
|
|
|
|
|
<p :class="$style.fetching" v-if="fetching">%fa:spinner .pulse .fw%%i18n:common.loading%<mk-ellipsis/></p>
|
|
|
|
<div :class="$style.stream" v-if="!fetching && images.length > 0">
|
2018-10-21 12:27:23 -05:00
|
|
|
<div v-for="image in images" :class="$style.img" :style="`background-image: url(${image.thumbnailUrl || image.url})`"></div>
|
2018-02-23 11:46:09 -06:00
|
|
|
</div>
|
2018-04-14 11:04:40 -05:00
|
|
|
<p :class="$style.empty" v-if="!fetching && images.length == 0">%i18n:@no-photos%</p>
|
2018-02-23 11:46:09 -06:00
|
|
|
</mk-widget-container>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2018-02-24 09:18:09 -06:00
|
|
|
import define from '../../../common/define-widget';
|
2018-02-23 11:46:09 -06:00
|
|
|
export default define({
|
|
|
|
name: 'photo-stream',
|
|
|
|
props: () => ({
|
|
|
|
design: 0
|
|
|
|
})
|
|
|
|
}).extend({
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
images: [],
|
|
|
|
fetching: true,
|
2018-10-06 21:06:17 -05:00
|
|
|
connection: null
|
2018-02-23 11:46:09 -06:00
|
|
|
};
|
|
|
|
},
|
|
|
|
mounted() {
|
2018-10-06 21:06:17 -05:00
|
|
|
this.connection = (this as any).os.stream.useSharedConnection('main');
|
2018-02-23 11:46:09 -06:00
|
|
|
|
2018-10-06 21:06:17 -05:00
|
|
|
this.connection.on('driveFileCreated', this.onDriveFileCreated);
|
2018-02-23 11:46:09 -06:00
|
|
|
|
|
|
|
(this as any).api('drive/stream', {
|
|
|
|
type: 'image/*',
|
|
|
|
limit: 9
|
|
|
|
}).then(images => {
|
|
|
|
this.images = images;
|
|
|
|
this.fetching = false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
2018-10-06 21:06:17 -05:00
|
|
|
this.connection.dispose();
|
2018-02-23 11:46:09 -06:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onDriveFileCreated(file) {
|
|
|
|
if (/^image\/.+$/.test(file.type)) {
|
|
|
|
this.images.unshift(file);
|
|
|
|
if (this.images.length > 9) this.images.pop();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
func() {
|
|
|
|
if (this.props.design == 2) {
|
|
|
|
this.props.design = 0;
|
|
|
|
} else {
|
|
|
|
this.props.design++;
|
|
|
|
}
|
2018-04-29 03:17:15 -05:00
|
|
|
|
|
|
|
this.save();
|
2018-02-23 11:46:09 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" module>
|
|
|
|
.root[data-melt]
|
|
|
|
.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
|
|
|
|
background-position center center
|
|
|
|
background-size cover
|
|
|
|
border solid 2px transparent
|
|
|
|
border-radius 4px
|
|
|
|
|
|
|
|
.fetching
|
|
|
|
.empty
|
|
|
|
margin 0
|
|
|
|
padding 16px
|
|
|
|
text-align center
|
|
|
|
color #aaa
|
|
|
|
|
|
|
|
> [data-fa]
|
|
|
|
margin-right 4px
|
|
|
|
|
|
|
|
</style>
|