2020-02-18 12:31:11 +02:00
|
|
|
<template>
|
2023-01-15 13:55:09 +02:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" :naked="widgetProps.transparent" class="mkw-activity data-cy-mkw-activity">
|
2023-01-15 01:30:29 +02:00
|
|
|
<template #icon><i class="ti ti-chart-line"></i></template>
|
|
|
|
<template #header>{{ i18n.ts._widgets.activity }}</template>
|
|
|
|
<template #func="{ buttonStyleClass }"><button class="_button" :class="buttonStyleClass" @click="toggleView()"><i class="ti ti-selector"></i></button></template>
|
2020-02-18 12:31:11 +02:00
|
|
|
|
2020-07-11 04:13:11 +03:00
|
|
|
<div>
|
2020-10-17 14:12:00 +03:00
|
|
|
<MkLoading v-if="fetching"/>
|
2020-07-11 04:13:11 +03:00
|
|
|
<template v-else>
|
2022-05-25 10:43:12 +03:00
|
|
|
<XCalendar v-show="widgetProps.view === 0" :activity="[].concat(activity)"/>
|
|
|
|
<XChart v-show="widgetProps.view === 1" :activity="[].concat(activity)"/>
|
2020-07-11 04:13:11 +03:00
|
|
|
</template>
|
|
|
|
</div>
|
2020-10-17 14:12:00 +03:00
|
|
|
</MkContainer>
|
2020-02-18 12:31:11 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2023-01-10 01:28:09 +02:00
|
|
|
import XCalendar from './WidgetActivity.calendar.vue';
|
|
|
|
import XChart from './WidgetActivity.chart.vue';
|
2022-06-25 12:26:31 +03:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
|
|
|
import * as os from '@/os';
|
2022-09-06 12:21:49 +03:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-01-08 13:30:01 +02:00
|
|
|
import { $i } from '@/account';
|
2022-07-20 16:24:26 +03:00
|
|
|
import { i18n } from '@/i18n';
|
2020-02-18 12:31:11 +02:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const name = 'activity';
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2022-01-08 13:30:01 +02:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-02-18 12:31:11 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02:00
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2020-02-18 12:31:11 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02:00
|
|
|
view: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 0,
|
|
|
|
hidden: true,
|
2020-02-18 12:31:11 +02:00
|
|
|
},
|
2022-01-08 13:30:01 +02: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 10:43:12 +03:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 13:30:01 +02: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 12:31:11 +02:00
|
|
|
}
|
2022-01-08 13:30:01 +02:00
|
|
|
save();
|
|
|
|
};
|
|
|
|
|
2022-06-25 12:26:31 +03:00
|
|
|
os.apiGet('charts/user/notes', {
|
2022-01-08 13:30:01 +02:00
|
|
|
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],
|
2022-06-25 12:26:31 +03:00
|
|
|
renotes: res.diffs.renote[i],
|
2022-01-08 13:30:01 +02:00
|
|
|
}));
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-02-18 12:31:11 +02:00
|
|
|
});
|
|
|
|
</script>
|