2020-02-18 19:31:11 +09:00
|
|
|
<template>
|
2022-05-28 14:28:12 +09:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :naked="widgetProps.transparent" class="mkw-activity">
|
2021-04-20 23:22:59 +09:00
|
|
|
<template #header><i class="fas fa-chart-bar"></i>{{ $ts._widgets.activity }}</template>
|
2021-11-19 19:36:12 +09:00
|
|
|
<template #func><button class="_button" @click="toggleView()"><i class="fas fa-sort"></i></button></template>
|
2020-02-18 19:31:11 +09:00
|
|
|
|
2020-07-11 10:13:11 +09:00
|
|
|
<div>
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkLoading v-if="fetching"/>
|
2020-07-11 10:13:11 +09:00
|
|
|
<template v-else>
|
2022-05-25 16:43:12 +09:00
|
|
|
<XCalendar v-show="widgetProps.view === 0" :activity="[].concat(activity)"/>
|
|
|
|
<XChart v-show="widgetProps.view === 1" :activity="[].concat(activity)"/>
|
2020-07-11 10:13:11 +09:00
|
|
|
</template>
|
|
|
|
</div>
|
2020-10-17 20:12:00 +09:00
|
|
|
</MkContainer>
|
2020-02-18 19:31:11 +09:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
|
|
|
import * as os from '@/os';
|
2021-11-12 02:02:25 +09:00
|
|
|
import MkContainer from '@/components/ui/container.vue';
|
2020-02-18 19:31:11 +09:00
|
|
|
import XCalendar from './activity.calendar.vue';
|
|
|
|
import XChart from './activity.chart.vue';
|
2022-01-08 20:30:01 +09:00
|
|
|
import { $i } from '@/account';
|
2020-02-18 19:31:11 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const name = 'activity';
|
2020-10-17 20:12:00 +09:00
|
|
|
|
2022-01-08 20:30:01 +09:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-02-18 19:31:11 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2020-02-18 19:31:11 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
view: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 0,
|
|
|
|
hidden: true,
|
2020-02-18 19:31:11 +09:00
|
|
|
},
|
2022-01-08 20:30:01 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 16:43:12 +09:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 20:30:01 +09:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const activity = ref(null);
|
|
|
|
const fetching = ref(true);
|
|
|
|
|
|
|
|
const toggleView = () => {
|
|
|
|
if (widgetProps.view === 1) {
|
|
|
|
widgetProps.view = 0;
|
|
|
|
} else {
|
|
|
|
widgetProps.view++;
|
2020-02-18 19:31:11 +09:00
|
|
|
}
|
2022-01-08 20:30:01 +09:00
|
|
|
save();
|
|
|
|
};
|
|
|
|
|
|
|
|
os.api('charts/user/notes', {
|
|
|
|
userId: $i.id,
|
|
|
|
span: 'day',
|
|
|
|
limit: 7 * 21,
|
|
|
|
}).then(res => {
|
|
|
|
activity.value = res.diffs.normal.map((_, i) => ({
|
|
|
|
total: res.diffs.normal[i] + res.diffs.reply[i] + res.diffs.renote[i],
|
|
|
|
notes: res.diffs.normal[i],
|
|
|
|
replies: res.diffs.reply[i],
|
|
|
|
renotes: res.diffs.renote[i]
|
|
|
|
}));
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-02-18 19:31:11 +09:00
|
|
|
});
|
|
|
|
</script>
|