Skip to content

Commit 6cd44ce

Browse files
authored
Merge pull request #48 from cjdhein/feature/directory-persistence
Add storage and retrieval of the last used directory
2 parents af6e32e + 6028d08 commit 6cd44ce

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

LegendsViewer.Frontend/legends-viewer-frontend/src/stores/fileSystemStore.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { components } from '../generated/api-schema'; // Import from the OpenAPI
44

55
export type FilesAndSubdirectories = components['schemas']['FilesAndSubdirectoriesDto'];
66

7+
export const dfDirectoryStorageKey = 'df-directory'
8+
79
export const useFileSystemStore = defineStore('fileSystem', {
810
state: () => ({
911
filesAndSubdirectories: {} as FilesAndSubdirectories,
@@ -68,13 +70,22 @@ export const useFileSystemStore = defineStore('fileSystem', {
6870
}
6971
},
7072

71-
async getRoot() {
73+
async initialize() {
7274
// Set loading state to true
7375
this.loading = true;
7476

7577
try {
78+
// Fetch from the stored path if there is one, else filesystem root
79+
const storedPath = localStorage.getItem(dfDirectoryStorageKey)
7680
// Fetch directory info from the backend
77-
const { data, error } = await client.GET('/api/FileSystem');
81+
// @ts-ignore
82+
const { data, error } = await client.GET(`/api/FileSystem/{path}`, {
83+
params: {
84+
path : {
85+
path: storedPath ? encodeURIComponent(storedPath) : ""
86+
}
87+
}
88+
});
7889

7990
if (error) {
8091
console.error(error);

LegendsViewer.Frontend/legends-viewer-frontend/src/views/WorldOverview.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
<!--suppress ALL -->
12
<script setup lang="ts">
2-
import { computed, ref } from 'vue';
3+
import {computed, onUnmounted, ref} from 'vue';
34
import { useBookmarkStore } from '../stores/bookmarkStore';
4-
import { useFileSystemStore } from '../stores/fileSystemStore';
5+
import {dfDirectoryStorageKey, useFileSystemStore} from '../stores/fileSystemStore';
56
67
const bookmarkStore = useBookmarkStore()
78
const fileSystemStore = useFileSystemStore()
89
bookmarkStore.getAll()
9-
fileSystemStore.getRoot();
10+
fileSystemStore.initialize();
11+
12+
const unsubscribe = fileSystemStore.$subscribe((_, state) => {
13+
const newStateCurrentDirectory = state.filesAndSubdirectories.currentDirectory
14+
if (newStateCurrentDirectory) {
15+
localStorage.setItem(dfDirectoryStorageKey, newStateCurrentDirectory);
16+
}
17+
})
18+
19+
onUnmounted(() => {
20+
unsubscribe()
21+
})
1022
1123
const fileName = ref<string>('')
1224

0 commit comments

Comments
 (0)