Skip to content

Commit a2db732

Browse files
authored
fix: get directory for current printing file (#1607)
Signed-off-by: Pedro Lamas <[email protected]>
1 parent d428b91 commit a2db732

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/components/widgets/filesystem/FileSystem.vue

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
:loading="filesLoading"
2020
:headers="configurableHeaders"
2121
@root-change="handleRootChange"
22-
@refresh="refreshPath(currentPath)"
22+
@refresh="handleRefresh"
2323
@add-file="handleAddFileDialog"
2424
@add-dir="handleAddDirDialog"
2525
@upload="handleUpload"
@@ -590,15 +590,20 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
590590
loadFiles (path: string) {
591591
if (!this.disabled) {
592592
this.currentPath = path
593-
if (this.files.length <= 0) {
594-
this.refreshPath(path)
593+
594+
const directoryLoaded = path in this.$store.state.files.pathFiles
595+
596+
if (!directoryLoaded) {
597+
this.handleRefresh()
595598
}
596599
}
597600
}
598601
599602
// Refreshes a path by loading the directory.
600-
refreshPath (path: string) {
601-
if (path && !this.disabled) SocketActions.serverFilesGetDirectory(path)
603+
handleRefresh () {
604+
if (!this.disabled) {
605+
SocketActions.serverFilesGetDirectory(this.currentPath)
606+
}
602607
}
603608
604609
// Handles a user filtering the data.

src/store/files/actions.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,10 @@ export const actions: ActionTree<FilesState, RootState> = {
125125
}
126126
},
127127

128-
async notifyMoveFile ({ commit }, payload: FileChange) {
129-
const { item, source_item } = payload
130-
131-
const paths = getFilePaths(item.path, item.root)
128+
async notifyMoveFile ({ commit, dispatch }, payload: FileChange) {
129+
const { source_item } = payload
132130

133-
if (!paths.filtered) {
134-
const file = itemAsMoonrakerFile(payload.item, paths)
135-
136-
commit('setFileUpdate', { paths, file })
137-
}
131+
dispatch('notifyCreateFile', payload)
138132

139133
if (source_item) {
140134
const sourcePaths = getFilePaths(source_item.path, source_item.root)

src/store/helpers.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { SocketActions } from '@/api/socketActions'
44
import type { AppPushNotification } from './notifications/types'
55
import i18n from '@/plugins/i18n'
66
import type { KlipperPrinterState, KlippyApp, TmcKey } from './printer/types'
7+
import getFilePaths from '@/util/get-file-paths'
78

89
const isTmc = (item: string): item is TmcKey => /^tmc\d{4} /.test(item)
910

@@ -70,9 +71,13 @@ export const handleCurrentFileChange = (payload: KlipperPrinterState, state: Roo
7071
payload.print_stats?.filename &&
7172
payload.print_stats.filename !== state.printer.printer.print_stats?.filename
7273
) {
73-
// This refreshes the metadata for the current file, which also
74-
// ensures we update the printer file with the latest data via
75-
// the files/onFileUpdate action.
76-
SocketActions.serverFilesMetadata(payload.print_stats.filename)
74+
const paths = getFilePaths(payload.print_stats.filename, 'gcodes')
75+
76+
const directoryLoaded = paths.rootPath in state.files.pathFiles
77+
78+
// Load the folder containing the currently printing file if we haven't done that already
79+
if (!directoryLoaded) {
80+
SocketActions.serverFilesGetDirectory(paths.rootPath)
81+
}
7782
}
7883
}

0 commit comments

Comments
 (0)