mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-12-05 04:07:27 +00:00
fa9c4a19b9
* refactor(frontend): os.tsに引き込んだscripts/api.tsの再exportをやめる * fix * fix * renate to "misskeyApi" * rename file
98 lines
2.5 KiB
Vue
98 lines
2.5 KiB
Vue
<!--
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
-->
|
|
|
|
<template>
|
|
<MkContainer :showHeader="widgetProps.showHeader" :naked="widgetProps.transparent" data-cy-mkw-activity class="mkw-activity">
|
|
<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>
|
|
|
|
<div>
|
|
<MkLoading v-if="fetching"/>
|
|
<template v-else>
|
|
<XCalendar v-show="widgetProps.view === 0" :activity="activity ?? []"/>
|
|
<XChart v-show="widgetProps.view === 1" :activity="activity ?? []"/>
|
|
</template>
|
|
</div>
|
|
</MkContainer>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from 'vue';
|
|
import { useWidgetPropsManager, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget.js';
|
|
import XCalendar from './WidgetActivity.calendar.vue';
|
|
import XChart from './WidgetActivity.chart.vue';
|
|
import { GetFormResultType } from '@/scripts/form.js';
|
|
import { misskeyApiGet } from '@/scripts/misskey-api.js';
|
|
import MkContainer from '@/components/MkContainer.vue';
|
|
import { $i } from '@/account.js';
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
const name = 'activity';
|
|
|
|
const widgetPropsDef = {
|
|
showHeader: {
|
|
type: 'boolean' as const,
|
|
default: true,
|
|
},
|
|
transparent: {
|
|
type: 'boolean' as const,
|
|
default: false,
|
|
},
|
|
view: {
|
|
type: 'number' as const,
|
|
default: 0,
|
|
hidden: true,
|
|
},
|
|
};
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(name,
|
|
widgetPropsDef,
|
|
props,
|
|
emit,
|
|
);
|
|
|
|
const activity = ref<{
|
|
total: number;
|
|
notes: number;
|
|
replies: number;
|
|
renotes: number;
|
|
}[] | null>(null);
|
|
const fetching = ref(true);
|
|
|
|
const toggleView = () => {
|
|
if (widgetProps.view === 1) {
|
|
widgetProps.view = 0;
|
|
} else {
|
|
widgetProps.view++;
|
|
}
|
|
save();
|
|
};
|
|
|
|
misskeyApiGet('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,
|
|
});
|
|
</script>
|