Bug 39320: (QA follow-up): Use localStorage instead of vue-cookies

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Pedro Amorim 2025-10-17 09:36:45 +00:00 committed by Lucas Gass
parent fc73aea182
commit e491363020
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
3 changed files with 12 additions and 17 deletions

View File

@ -56,13 +56,12 @@
<script>
import { onMounted, ref, watch, inject } from "vue";
import WidgetPicker from "./WidgetPicker.vue";
import VueCookies from "vue-cookies";
import { $__ } from "@koha-vue/i18n";
import { VueDraggableNext } from "vue-draggable-next";
export default {
props: {
availableWidgets: Array
availableWidgets: Array,
},
setup(props) {
const availableWidgets = props.availableWidgets;
@ -186,9 +185,9 @@ export default {
};
onMounted(() => {
const storedWidgets = VueCookies.get("dashboard-widgets");
const storedWidgets = localStorage.getItem("dashboard-widgets");
if (storedWidgets) {
const { left, right } = storedWidgets;
const { left, right } = JSON.parse(storedWidgets);
left.forEach(widgetName => {
const widget = availableWidgets.find(
widget => widget.name === widgetName
@ -215,13 +214,12 @@ export default {
([left, right]) => {
const leftWidgetNames = left.map(widget => widget.name);
const rightWidgetNames = right.map(widget => widget.name);
VueCookies.set(
localStorage.setItem(
"dashboard-widgets",
JSON.stringify({
left: leftWidgetNames,
right: rightWidgetNames,
}),
"30d"
})
);
},
{ deep: true }

View File

@ -1,6 +1,5 @@
// composables/useBaseWidget.js
import { ref, computed, watch, provide, onMounted, onBeforeMount } from "vue";
import VueCookies from "vue-cookies";
export function useBaseWidget(widgetConfig, emit) {
const loading = ref(
@ -37,17 +36,17 @@ export function useBaseWidget(widgetConfig, emit) {
}));
const getWidgetSavedSettings = () => {
const cookie = VueCookies.get(
const savedSettings = localStorage.getItem(
"widget-" + widgetConfig.id + "-settings"
);
return cookie || null;
return savedSettings || null;
};
onBeforeMount(() => {
if (widgetConfig.display === "dashboard") {
const cookie = getWidgetSavedSettings();
if (cookie) {
settings.value = cookie;
const savedSettings = getWidgetSavedSettings();
if (savedSettings) {
settings.value = savedSettings;
}
}
});
@ -74,10 +73,9 @@ export function useBaseWidget(widgetConfig, emit) {
settings,
newSettings => {
if (widgetConfig.display === "dashboard" && newSettings !== null) {
VueCookies.set(
localStorage.setItem(
"widget-" + widgetConfig.id + "-settings",
JSON.stringify(newSettings),
"30d"
JSON.stringify(newSettings)
);
}
},

View File

@ -42,7 +42,6 @@
"sass": "^1.58.1",
"style-loader": "^3.3.1",
"vue": "^3.5.4",
"vue-cookies": "^1.8.6",
"vue-draggable-next": "^2.2.1",
"vue-flatpickr-component": "^9",
"vue-router": "^4.0.14",