2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
2024-02-12 03:37:45 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2021-04-10 05:40:50 +02:00
|
|
|
<template>
|
2023-06-01 10:19:46 +02:00
|
|
|
<div>
|
|
|
|
<XWidgets :edit="editMode" :widgets="widgets" @addWidget="addWidget" @removeWidget="removeWidget" @updateWidget="updateWidget" @updateWidgets="updateWidgets" @exit="editMode = false"/>
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-12-19 11:01:30 +01:00
|
|
|
<button v-if="editMode" class="_textButton" style="font-size: 0.9em;" @click="editMode = false"><i class="ti ti-check"></i> {{ i18n.ts.editWidgetsExit }}</button>
|
2023-05-09 00:49:53 +02:00
|
|
|
<button v-else class="_textButton" data-cy-widget-edit :class="$style.edit" style="font-size: 0.9em;" @click="editMode = true"><i class="ti ti-pencil"></i> {{ i18n.ts.editWidgets }}</button>
|
2021-04-10 05:40:50 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-12-27 06:55:11 +01:00
|
|
|
<script lang="ts">
|
2023-12-07 06:42:09 +01:00
|
|
|
import { computed, ref } from 'vue';
|
|
|
|
const editMode = ref(false);
|
2022-12-27 06:55:11 +01:00
|
|
|
</script>
|
2022-03-20 19:11:14 +01:00
|
|
|
<script lang="ts" setup>
|
2022-08-30 17:24:33 +02:00
|
|
|
import XWidgets from '@/components/MkWidgets.vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-12-27 06:55:11 +01:00
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
// null = 全てのウィジェットを表示
|
|
|
|
// left = place: leftだけを表示
|
|
|
|
// right = rightとnullを表示
|
|
|
|
place?: 'left' | null | 'right';
|
|
|
|
}>(), {
|
|
|
|
place: null,
|
|
|
|
});
|
|
|
|
|
2023-12-07 06:42:09 +01:00
|
|
|
const widgets = computed(() => {
|
2022-12-27 06:55:11 +01:00
|
|
|
if (props.place === null) return defaultStore.reactiveState.widgets.value;
|
|
|
|
if (props.place === 'left') return defaultStore.reactiveState.widgets.value.filter(w => w.place === 'left');
|
|
|
|
return defaultStore.reactiveState.widgets.value.filter(w => w.place !== 'left');
|
|
|
|
});
|
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
function addWidget(widget) {
|
|
|
|
defaultStore.set('widgets', [{
|
|
|
|
...widget,
|
2022-12-27 06:55:11 +01:00
|
|
|
place: props.place,
|
2022-03-20 19:11:14 +01:00
|
|
|
}, ...defaultStore.state.widgets]);
|
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
function removeWidget(widget) {
|
2022-05-26 15:53:09 +02:00
|
|
|
defaultStore.set('widgets', defaultStore.state.widgets.filter(w => w.id !== widget.id));
|
2022-03-20 19:11:14 +01:00
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-03-20 19:11:14 +01:00
|
|
|
function updateWidget({ id, data }) {
|
|
|
|
defaultStore.set('widgets', defaultStore.state.widgets.map(w => w.id === id ? {
|
|
|
|
...w,
|
2022-05-26 15:53:09 +02:00
|
|
|
data,
|
2022-12-27 06:55:11 +01:00
|
|
|
place: props.place,
|
2022-03-20 19:11:14 +01:00
|
|
|
} : w));
|
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
|
2022-12-27 06:55:11 +01:00
|
|
|
function updateWidgets(thisWidgets) {
|
|
|
|
if (props.place === null) {
|
|
|
|
defaultStore.set('widgets', thisWidgets);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (props.place === 'left') {
|
|
|
|
defaultStore.set('widgets', [
|
|
|
|
...thisWidgets.map(w => ({ ...w, place: 'left' })),
|
|
|
|
...defaultStore.state.widgets.filter(w => w.place !== 'left' && !thisWidgets.some(t => w.id === t.id)),
|
|
|
|
]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
defaultStore.set('widgets', [
|
|
|
|
...defaultStore.state.widgets.filter(w => w.place === 'left' && !thisWidgets.some(t => w.id === t.id)),
|
|
|
|
...thisWidgets.map(w => ({ ...w, place: 'right' })),
|
|
|
|
]);
|
2022-03-20 19:11:14 +01:00
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
</script>
|
|
|
|
|
2023-01-10 03:15:29 +01:00
|
|
|
<style lang="scss" module>
|
2023-04-10 19:11:44 +02:00
|
|
|
.edit {
|
|
|
|
width: 100%;
|
|
|
|
}
|
2021-04-10 05:40:50 +02:00
|
|
|
</style>
|