summaryrefslogtreecommitdiff
path: root/packages/frontend/src/ui/universal.widgets.vue
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2022-12-27 14:36:33 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2022-12-27 14:36:33 +0900
commit9384f5399da39e53855beb8e7f8ded1aa56bf72e (patch)
treece5959571a981b9c4047da3c7b3fd080aa44222c /packages/frontend/src/ui/universal.widgets.vue
parentwip: retention for dashboard (diff)
downloadmisskey-9384f5399da39e53855beb8e7f8ded1aa56bf72e.tar.gz
misskey-9384f5399da39e53855beb8e7f8ded1aa56bf72e.tar.bz2
misskey-9384f5399da39e53855beb8e7f8ded1aa56bf72e.zip
rename: client -> frontend
Diffstat (limited to 'packages/frontend/src/ui/universal.widgets.vue')
-rw-r--r--packages/frontend/src/ui/universal.widgets.vue71
1 files changed, 71 insertions, 0 deletions
diff --git a/packages/frontend/src/ui/universal.widgets.vue b/packages/frontend/src/ui/universal.widgets.vue
new file mode 100644
index 0000000000..33fb492836
--- /dev/null
+++ b/packages/frontend/src/ui/universal.widgets.vue
@@ -0,0 +1,71 @@
+<template>
+<div class="efzpzdvf">
+ <XWidgets :edit="editMode" :widgets="defaultStore.reactiveState.widgets.value" @add-widget="addWidget" @remove-widget="removeWidget" @update-widget="updateWidget" @update-widgets="updateWidgets" @exit="editMode = false"/>
+
+ <button v-if="editMode" class="_textButton" style="font-size: 0.9em;" @click="editMode = false"><i class="ti ti-check"></i> {{ i18n.ts.editWidgetsExit }}</button>
+ <button v-else class="_textButton mk-widget-edit" style="font-size: 0.9em;" @click="editMode = true"><i class="ti ti-pencil"></i> {{ i18n.ts.editWidgets }}</button>
+</div>
+</template>
+
+<script lang="ts" setup>
+import { onMounted } from 'vue';
+import XWidgets from '@/components/MkWidgets.vue';
+import { i18n } from '@/i18n';
+import { defaultStore } from '@/store';
+
+const emit = defineEmits<{
+ (ev: 'mounted', el: Element): void;
+}>();
+
+let editMode = $ref(false);
+let rootEl = $ref<HTMLDivElement>();
+
+onMounted(() => {
+ emit('mounted', rootEl);
+});
+
+function addWidget(widget) {
+ defaultStore.set('widgets', [{
+ ...widget,
+ place: null,
+ }, ...defaultStore.state.widgets]);
+}
+
+function removeWidget(widget) {
+ defaultStore.set('widgets', defaultStore.state.widgets.filter(w => w.id !== widget.id));
+}
+
+function updateWidget({ id, data }) {
+ defaultStore.set('widgets', defaultStore.state.widgets.map(w => w.id === id ? {
+ ...w,
+ data,
+ } : w));
+}
+
+function updateWidgets(widgets) {
+ defaultStore.set('widgets', widgets);
+}
+</script>
+
+<style lang="scss" scoped>
+.efzpzdvf {
+ position: sticky;
+ height: min-content;
+ min-height: 100vh;
+ padding: var(--margin) 0;
+ box-sizing: border-box;
+
+ > * {
+ margin: var(--margin) 0;
+ width: 300px;
+
+ &:first-child {
+ margin-top: 0;
+ }
+ }
+
+ > .add {
+ margin: 0 auto;
+ }
+}
+</style>