0
0
switched/src/client/app/desktop/views/components/activity.vue

87 lines
1.9 KiB
Vue
Raw Normal View History

2018-02-19 23:37:09 +09:00
<template>
2018-04-20 03:56:58 +09:00
<div class="mk-activity">
<mk-widget-container :show-header="design == 0" :naked="design == 2">
<template slot="header"><fa icon="chart-bar"/>{{ $t('title') }}</template>
<button slot="func" :title="$t('toggle')" @click="toggle"><fa icon="sort"/></button>
2018-04-20 03:56:58 +09:00
<p :class="$style.fetching" v-if="fetching"><fa icon="spinner .pulse" fixed-width/>{{ $t('@.loading') }}<mk-ellipsis/></p>
2018-04-20 03:56:58 +09:00
<template v-else>
<x-calendar v-show="view == 0" :data="[].concat(activity)"/>
<x-chart v-show="view == 1" :data="[].concat(activity)"/>
</template>
</mk-widget-container>
2018-02-19 23:37:09 +09:00
</div>
</template>
<script lang="ts">
import Vue from 'vue';
import i18n from '../../../i18n';
2018-02-21 01:39:51 +09:00
import XCalendar from './activity.calendar.vue';
import XChart from './activity.chart.vue';
2018-02-19 23:37:09 +09:00
export default Vue.extend({
i18n: i18n('desktop/views/components/activity.vue'),
2018-02-19 23:37:09 +09:00
components: {
2018-02-21 01:39:51 +09:00
XCalendar,
XChart
2018-02-19 23:37:09 +09:00
},
props: {
design: {
default: 0
},
initView: {
default: 0
},
user: {
type: Object,
required: true
}
},
data() {
return {
fetching: true,
activity: null,
view: this.initView
};
},
mounted() {
2018-11-03 16:44:05 +09:00
(this as any).api('charts/user/notes', {
2018-03-29 14:48:47 +09:00
userId: this.user.id,
2018-11-03 16:44:05 +09:00
span: 'day',
limit: 7 * 20
2018-02-19 23:37:09 +09:00
}).then(activity => {
2018-11-03 16:44:05 +09:00
this.activity = activity.diffs.normal.map((_, i) => ({
total: activity.diffs.normal[i] + activity.diffs.reply[i] + activity.diffs.renote[i],
notes: activity.diffs.normal[i],
replies: activity.diffs.reply[i],
renotes: activity.diffs.renote[i]
}));
2018-02-19 23:37:09 +09:00
this.fetching = false;
});
},
methods: {
toggle() {
if (this.view == 1) {
this.view = 0;
this.$emit('viewChanged', this.view);
} else {
this.view++;
this.$emit('viewChanged', this.view);
}
}
}
});
</script>
2018-04-20 03:56:58 +09:00
<style lang="stylus" module>
.fetching
margin 0
padding 16px
text-align center
color #aaa
2018-02-19 23:37:09 +09:00
> [data-icon]
2018-04-20 03:56:58 +09:00
margin-right 4px
2018-02-19 23:37:09 +09:00
</style>