2023-07-27 08:31:52 +03:00
|
|
|
<!--
|
2024-02-13 17:59:27 +02:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 08:31:52 +03:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-02-18 12:31:11 +02:00
|
|
|
<template>
|
2023-05-19 10:20:53 +03:00
|
|
|
<MkContainer :showHeader="widgetProps.showHeader" :naked="widgetProps.transparent" data-cy-mkw-activity class="mkw-activity">
|
2023-11-04 00:20:53 +02:00
|
|
|
<template #icon><i class="ph-chart-line ph-bold ph-lg"></i></template>
|
2023-01-15 01:30:29 +02:00
|
|
|
<template #header>{{ i18n.ts._widgets.activity }}</template>
|
2023-10-01 01:46:42 +03: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 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>
|
2023-12-26 07:19:35 +02:00
|
|
|
<XCalendar v-show="widgetProps.view === 0" :activity="activity ?? []"/>
|
|
|
|
<XChart v-show="widgetProps.view === 1" :activity="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>
|
2023-02-16 16:09:41 +02:00
|
|
|
import { ref } from 'vue';
|
2023-12-21 04:36:45 +02:00
|
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
2023-01-10 01:28:09 +02:00
|
|
|
import XCalendar from './WidgetActivity.calendar.vue';
|
|
|
|
import XChart from './WidgetActivity.chart.vue';
|
2023-09-19 10:37:43 +03:00
|
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
2024-01-04 11:32:46 +02:00
|
|
|
import { misskeyApiGet } from '@/scripts/misskey-api.js';
|
2022-09-06 12:21:49 +03:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2023-09-19 10:37:43 +03:00
|
|
|
import { $i } from '@/account.js';
|
|
|
|
import { i18n } from '@/i18n.js';
|
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>;
|
|
|
|
|
2023-05-19 10:20:53 +03:00
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2022-01-08 13:30:01 +02:00
|
|
|
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
2023-12-26 07:19:35 +02:00
|
|
|
const activity = ref<{
|
|
|
|
total: number;
|
|
|
|
notes: number;
|
|
|
|
replies: number;
|
|
|
|
renotes: number;
|
|
|
|
}[] | null>(null);
|
2022-01-08 13:30:01 +02:00
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2024-01-04 11:32:46 +02:00
|
|
|
misskeyApiGet('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>
|