fix: missing sidebar data after update

This commit is contained in:
Fabio Di Stasio 2022-11-29 18:18:56 +01:00
parent e7da5a7040
commit 0a1f50a9b9
2 changed files with 20 additions and 20 deletions

View File

@ -103,11 +103,11 @@ const settingsStore = useSettingsStore();
const { updateStatus } = storeToRefs(applicationStore);
const { getSelected: selectedWorkspace } = storeToRefs(workspacesStore);
const { getConnectionsOrder: connectionsOrder } = storeToRefs(connectionsStore);
const { connectionsOrder } = storeToRefs(connectionsStore);
const { disableScratchpad } = storeToRefs(settingsStore);
const { showSettingModal, showScratchpad } = applicationStore;
const { updateConnectionsOrder } = connectionsStore;
const { updateConnectionsOrder, initConnectionsOrder } = connectionsStore;
const { selectWorkspace } = workspacesStore;
const emit = defineEmits(['show-connections-modal']);
@ -150,6 +150,9 @@ watch(selectedWorkspace, (newVal, oldVal) => {
}, 150);
}
});
if (!connectionsArr.value.length)
initConnectionsOrder();
</script>
<style lang="scss">

View File

@ -56,23 +56,6 @@ export const useConnectionsStore = defineStore('connections', {
return connectionName;
},
getConnectionsOrder: state => {
if (state.connectionsOrder.length)
return state.connectionsOrder;
else {
const connectionsOrder = state.connections.map<SidebarElement>(conn => {
return {
isFolder: false,
uid: conn.uid,
client: conn.client,
icon: null,
name: null
};
});
persistentStore.set('connectionsOrder', connectionsOrder);
return connectionsOrder;
}
},
getConnectionOrderByUid: state => (uid:string) => state.connectionsOrder
.find(connection => connection.uid === uid),
getFolders: state => state.connectionsOrder.filter(conn => conn.isFolder),
@ -88,12 +71,14 @@ export const useConnectionsStore = defineStore('connections', {
isFolder: false,
uid: connection.uid,
client: connection.client,
icon: null
icon: null,
name: null
});
persistentStore.set('connectionsOrder', this.connectionsOrder);
},
addFolder (params: {after: string; connections: [string, string]}) {
const index = this.connectionsOrder.findIndex((conn: SidebarElement) => conn.uid === params.after);
this.connectionsOrder.splice(index, 0, {
isFolder: true,
uid: uidGen('F'),
@ -137,6 +122,18 @@ export const useConnectionsStore = defineStore('connections', {
this.connections = connections;
persistentStore.set('connections', this.connections);
},
initConnectionsOrder () {
this.connectionsOrder = (this.connections as ConnectionParams[]).map<SidebarElement>(conn => {
return {
isFolder: false,
uid: conn.uid,
client: conn.client,
icon: null,
name: null
};
});
persistentStore.set('connectionsOrder', this.connectionsOrder);
},
updateConnectionsOrder (connections: SidebarElement[]) {
const invalidElements = connections.reduce<{index: number; uid: string}[]>((acc, curr, i) => {
if (typeof curr === 'string')