2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-02-18 11:31:11 +01:00
|
|
|
<template>
|
2023-05-19 09:20:53 +02:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" :naked="widgetProps.transparent" data-cy-mkw-activity class="mkw-activity">
|
2023-11-03 23:20:53 +01:00
|
|
|
<template #icon><i class="ph-chart-line ph-bold ph-lg"></i></template>
|
2023-01-15 00:30:29 +01:00
|
|
|
<template #header>{{ i18n.ts._widgets.activity }}</template>
|
2023-10-01 00:46:42 +02:00
|
|
|
<template #func="{ buttonStyleClass }"><button class="_button" :class="buttonStyleClass" @click="toggleView()"><i class="ph-caret-up-down ph-bold ph-lg"></i></button></template>
|
2020-02-18 11:31:11 +01:00
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
<div>
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkLoading v-if="fetching"/>
|
2020-07-11 03:13:11 +02:00
|
|
|
<template v-else>
|
2022-05-25 09:43:12 +02:00
|
|
|
<XCalendar v-show="widgetProps.view === 0" :activity="[].concat(activity)"/>
|
|
|
|
<XChart v-show="widgetProps.view === 1" :activity="[].concat(activity)"/>
|
2020-07-11 03:13:11 +02:00
|
|
|
</template>
|
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkContainer>
|
2020-02-18 11:31:11 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-02-16 15:09:41 +01:00
|
|
|
import { ref } from 'vue';
|
2023-09-29 04:22:59 +02:00
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-01-10 00:28:09 +01:00
|
|
|
import XCalendar from './WidgetActivity.calendar.vue';
|
|
|
|
import XChart from './WidgetActivity.chart.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
|
|
|
import * as os from '@/os.js';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { $i } from '@/account.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
2020-02-18 11:31:11 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'activity';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
2020-02-18 11:31:11 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
transparent: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: false,
|
2020-02-18 11:31:11 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
view: {
|
|
|
|
type: 'number' as const,
|
|
|
|
default: 0,
|
|
|
|
hidden: true,
|
2020-02-18 11:31:11 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
2023-05-19 09:20:53 +02:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 12:30:01 +01: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 11:31:11 +01:00
|
|
|
}
|
2022-01-08 12:30:01 +01:00
|
|
|
save();
|
|
|
|
};
|
|
|
|
|
2022-06-25 11:26:31 +02:00
|
|
|
os.apiGet('charts/user/notes', {
|
2022-01-08 12:30:01 +01: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 11:26:31 +02:00
|
|
|
renotes: res.diffs.renote[i],
|
2022-01-08 12:30:01 +01:00
|
|
|
}));
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-02-18 11:31:11 +01:00
|
|
|
});
|
|
|
|
</script>
|