2020-02-18 11:31:11 +01:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<MkContainer
|
|
|
|
:show-header="widgetProps.showHeader"
|
|
|
|
:naked="widgetProps.transparent"
|
|
|
|
class="mkw-activity"
|
|
|
|
>
|
|
|
|
<template #header
|
|
|
|
><i class="ph-chart-bar ph-bold ph-lg"></i
|
|
|
|
>{{ i18n.ts._widgets.activity }}</template
|
|
|
|
>
|
|
|
|
<template #func
|
2023-04-26 03:21:15 +02:00
|
|
|
><button
|
|
|
|
v-if="!widgetProps.newStyle"
|
|
|
|
class="_button"
|
|
|
|
@click="toggleView()"
|
|
|
|
>
|
2023-04-08 02:01:42 +02:00
|
|
|
<i class="ph-sort-ascending ph-bold ph-lg"></i></button
|
|
|
|
></template>
|
2020-02-18 11:31:11 +01:00
|
|
|
|
2023-04-26 03:06:21 +02:00
|
|
|
<div v-if="widgetProps.newStyle">
|
2023-04-26 03:21:15 +02:00
|
|
|
<MkHeatmap src="my-notes" />
|
2023-04-26 03:06:21 +02:00
|
|
|
</div>
|
|
|
|
<div v-else>
|
2023-04-08 02:01:42 +02:00
|
|
|
<MkLoading v-if="fetching" />
|
|
|
|
<template v-else>
|
|
|
|
<XCalendar
|
|
|
|
v-show="widgetProps.view === 0"
|
|
|
|
:activity="[].concat(activity)"
|
|
|
|
/>
|
|
|
|
<XChart
|
|
|
|
v-show="widgetProps.view === 1"
|
|
|
|
:activity="[].concat(activity)"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</MkContainer>
|
2020-02-18 11:31:11 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { onMounted, onUnmounted, reactive, ref, watch } from "vue";
|
|
|
|
import {
|
|
|
|
useWidgetPropsManager,
|
|
|
|
Widget,
|
|
|
|
WidgetComponentEmits,
|
|
|
|
WidgetComponentExpose,
|
|
|
|
WidgetComponentProps,
|
|
|
|
} from "./widget";
|
|
|
|
import XCalendar from "./activity.calendar.vue";
|
|
|
|
import XChart from "./activity.chart.vue";
|
2023-04-26 03:06:21 +02:00
|
|
|
import MkHeatmap from "@/components/MkHeatmap.vue";
|
2023-04-08 02:01:42 +02:00
|
|
|
import { GetFormResultType } from "@/scripts/form";
|
|
|
|
import * as os from "@/os";
|
|
|
|
import MkContainer from "@/components/MkContainer.vue";
|
|
|
|
import { $i } from "@/account";
|
|
|
|
import { i18n } from "@/i18n";
|
2020-02-18 11:31:11 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const name = "activity";
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
2023-04-26 03:06:21 +02:00
|
|
|
newStyle: {
|
|
|
|
type: "boolean" as const,
|
|
|
|
default: true,
|
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
showHeader: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: true,
|
2020-02-18 11:31:11 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
transparent: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "boolean" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
default: false,
|
2020-02-18 11:31:11 +01:00
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
view: {
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "number" as const,
|
2022-01-08 12:30:01 +01:00
|
|
|
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>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
2023-04-08 02:01:42 +02:00
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps> }>();
|
|
|
|
const emit = defineEmits<{ (ev: "updateProps", props: WidgetProps) }>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const { widgetProps, configure, save } = useWidgetPropsManager(
|
|
|
|
name,
|
2022-01-08 12:30:01 +01:00
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
2023-04-08 02:01:42 +02:00
|
|
|
emit
|
2022-01-08 12:30:01 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
os.apiGet("charts/user/notes", {
|
2022-01-08 12:30:01 +01:00
|
|
|
userId: $i.id,
|
2023-04-08 02:01:42 +02:00
|
|
|
span: "day",
|
2022-01-08 12:30:01 +01:00
|
|
|
limit: 7 * 21,
|
2023-04-08 02:01:42 +02:00
|
|
|
}).then((res) => {
|
2022-01-08 12:30:01 +01:00
|
|
|
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>
|