Skip to content

Commit db9fbc9

Browse files
authored
Merge pull request #30593 from nextcloud/bugfix/19048/fix-changedirectory-recommendations
Trigger "changeDirectory" event on URL change
2 parents 0d0fcd3 + 809e305 commit db9fbc9

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

apps/files/js/app.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@
316316
* Event handler for when an app notified that its directory changed
317317
*/
318318
_onDirectoryChanged: function(e) {
319-
if (e.dir) {
319+
if (e.dir && !e.changedThroughUrl) {
320320
this._changeUrl(this.navigation.getActiveItem(), e.dir, e.fileId);
321321
}
322322
},
@@ -386,9 +386,11 @@
386386
params.fileid = fileId;
387387
}
388388
var currentParams = OC.Util.History.parseUrlQuery();
389-
if (currentParams.dir === params.dir && currentParams.view === params.view && currentParams.fileid !== params.fileid) {
390-
// if only fileid changed or was added, replace instead of push
391-
OC.Util.History.replaceState(this._makeUrlParams(params));
389+
if (currentParams.dir === params.dir && currentParams.view === params.view) {
390+
if (currentParams.fileid !== params.fileid) {
391+
// if only fileid changed or was added, replace instead of push
392+
OC.Util.History.replaceState(this._makeUrlParams(params));
393+
}
392394
} else {
393395
OC.Util.History.pushState(this._makeUrlParams(params));
394396
}

apps/files/js/filelist.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@
794794
if( (this._currentDirectory || this.$el.find('#dir').val()) && currentDir === e.dir) {
795795
return;
796796
}
797-
this.changeDirectory(e.dir, false, true);
797+
this.changeDirectory(e.dir, true, true, undefined, true);
798798
}
799799
},
800800

@@ -2057,15 +2057,16 @@
20572057
* @param {boolean} [changeUrl=true] if the URL must not be changed (defaults to true)
20582058
* @param {boolean} [force=false] set to true to force changing directory
20592059
* @param {string} [fileId] optional file id, if known, to be appended in the URL
2060+
* @param {bool} [changedThroughUrl=false] true if the dir was set through a URL change
20602061
*/
2061-
changeDirectory: function(targetDir, changeUrl, force, fileId) {
2062+
changeDirectory: function(targetDir, changeUrl, force, fileId, changedThroughUrl) {
20622063
var self = this;
20632064
var currentDir = this.getCurrentDirectory();
20642065
targetDir = targetDir || '/';
20652066
if (!force && currentDir === targetDir) {
20662067
return;
20672068
}
2068-
this._setCurrentDir(targetDir, changeUrl, fileId);
2069+
this._setCurrentDir(targetDir, changeUrl, fileId, changedThroughUrl);
20692070

20702071
// discard finished uploads list, we'll get it through a regular reload
20712072
this._uploads = {};
@@ -2100,8 +2101,9 @@
21002101
* @param targetDir directory to display
21012102
* @param changeUrl true to also update the URL, false otherwise (default)
21022103
* @param {string} [fileId] file id
2104+
* @param {bool} changedThroughUrl true if the dir was set through a URL change
21032105
*/
2104-
_setCurrentDir: function(targetDir, changeUrl, fileId) {
2106+
_setCurrentDir: function(targetDir, changeUrl, fileId, changedThroughUrl) {
21052107
targetDir = targetDir.replace(/\\/g, '/');
21062108
if (!this._isValidPath(targetDir)) {
21072109
targetDir = '/';
@@ -2133,6 +2135,7 @@
21332135
if (fileId) {
21342136
params.fileId = fileId;
21352137
}
2138+
params.changedThroughUrl = changedThroughUrl
21362139
this.$el.trigger(jQuery.Event('changeDirectory', params));
21372140
}
21382141
this.breadcrumb.setDirectory(this.getCurrentDirectory());
@@ -2234,7 +2237,7 @@
22342237
if (status === 401) {
22352238
// We are not authentificated, so reload the page so that we get
22362239
// redirected to the login page while saving the current url.
2237-
location.reload();
2240+
location.reload();
22382241
}
22392242

22402243
// Firewall Blocked request?

0 commit comments

Comments
 (0)