Skip to content

Commit

Permalink
fix: get directory for current printing file (#1607)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas authored Feb 18, 2025
1 parent d428b91 commit a2db732
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
15 changes: 10 additions & 5 deletions src/components/widgets/filesystem/FileSystem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
:loading="filesLoading"
:headers="configurableHeaders"
@root-change="handleRootChange"
@refresh="refreshPath(currentPath)"
@refresh="handleRefresh"
@add-file="handleAddFileDialog"
@add-dir="handleAddDirDialog"
@upload="handleUpload"
Expand Down Expand Up @@ -590,15 +590,20 @@ export default class FileSystem extends Mixins(StateMixin, FilesMixin, ServicesM
loadFiles (path: string) {
if (!this.disabled) {
this.currentPath = path
if (this.files.length <= 0) {
this.refreshPath(path)
const directoryLoaded = path in this.$store.state.files.pathFiles
if (!directoryLoaded) {
this.handleRefresh()
}
}
}
// Refreshes a path by loading the directory.
refreshPath (path: string) {
if (path && !this.disabled) SocketActions.serverFilesGetDirectory(path)
handleRefresh () {
if (!this.disabled) {
SocketActions.serverFilesGetDirectory(this.currentPath)
}
}
// Handles a user filtering the data.
Expand Down
12 changes: 3 additions & 9 deletions src/store/files/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,10 @@ export const actions: ActionTree<FilesState, RootState> = {
}
},

async notifyMoveFile ({ commit }, payload: FileChange) {
const { item, source_item } = payload

const paths = getFilePaths(item.path, item.root)
async notifyMoveFile ({ commit, dispatch }, payload: FileChange) {
const { source_item } = payload

if (!paths.filtered) {
const file = itemAsMoonrakerFile(payload.item, paths)

commit('setFileUpdate', { paths, file })
}
dispatch('notifyCreateFile', payload)

if (source_item) {
const sourcePaths = getFilePaths(source_item.path, source_item.root)
Expand Down
13 changes: 9 additions & 4 deletions src/store/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SocketActions } from '@/api/socketActions'
import type { AppPushNotification } from './notifications/types'
import i18n from '@/plugins/i18n'
import type { KlipperPrinterState, KlippyApp, TmcKey } from './printer/types'
import getFilePaths from '@/util/get-file-paths'

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

Expand Down Expand Up @@ -70,9 +71,13 @@ export const handleCurrentFileChange = (payload: KlipperPrinterState, state: Roo
payload.print_stats?.filename &&
payload.print_stats.filename !== state.printer.printer.print_stats?.filename
) {
// This refreshes the metadata for the current file, which also
// ensures we update the printer file with the latest data via
// the files/onFileUpdate action.
SocketActions.serverFilesMetadata(payload.print_stats.filename)
const paths = getFilePaths(payload.print_stats.filename, 'gcodes')

const directoryLoaded = paths.rootPath in state.files.pathFiles

// Load the folder containing the currently printing file if we haven't done that already
if (!directoryLoaded) {
SocketActions.serverFilesGetDirectory(paths.rootPath)
}
}
}

0 comments on commit a2db732

Please sign in to comment.