Skip to content

Commit a1bf9b5

Browse files
committed
Save chat window position and size to local storage
1 parent 426ad1d commit a1bf9b5

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

src/components/channel/MessageGroupItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
}
7676
7777
:deep(.message-content) {
78-
word-break: break-all;
78+
word-break: break-word;
7979
8080
.screenshot {
8181
object-fit: contain;

src/components/layout/DraggableWindow.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@
2626
</template>
2727

2828
<script setup lang="ts">
29-
import { onClickOutside, useDraggable, useEventListener } from '@vueuse/core';
29+
import {
30+
onClickOutside,
31+
type Position,
32+
useDraggable,
33+
useEventListener,
34+
useLocalStorage,
35+
} from '@vueuse/core';
3036
import { computed, type CSSProperties, ref } from 'vue';
3137
3238
const handles = ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'] as const;
@@ -38,16 +44,25 @@
3844
const headerRef = ref<HTMLDivElement>();
3945
const isActive = ref(false);
4046
const isResizing = ref(false);
41-
const width = ref(400);
42-
const height = ref(300);
47+
const width = useLocalStorage('chat_windowWidth', 400);
48+
const height = useLocalStorage('chat_windowHeight', 300);
49+
const initialPosition = useLocalStorage<Position>(
50+
'chat_windowPosition',
51+
{ x: 0, y: 0 },
52+
{ mergeDefaults: true },
53+
);
4354
4455
onClickOutside(containerRef, () => {
4556
isActive.value = false;
4657
});
4758
4859
const { x, y } = useDraggable(containerRef, {
49-
initialValue: { x: 100, y: 100 },
60+
initialValue: initialPosition,
5061
handle: headerRef,
62+
onEnd(endPosition) {
63+
// Save position to localStorage
64+
Object.assign(initialPosition.value, endPosition);
65+
},
5166
});
5267
5368
let currentHandle: Handle | null = null;
@@ -116,6 +131,9 @@
116131
isResizing.value = false;
117132
currentHandle = null;
118133
positionStart = null;
134+
// Save position to localStorage
135+
initialPosition.value.x = x.value;
136+
initialPosition.value.y = y.value;
119137
cleanupMove?.();
120138
cleanupEnd?.();
121139
}

0 commit comments

Comments
 (0)