Skip to content

Commit

Permalink
fix: use Viewer state to determine current dir
Browse files Browse the repository at this point in the history
This is more relyable then parsing the window location query for dir:
* ?dir does not change when navigating between files right now
* ?dir is not present when the viewer is used from within other apps.

We used to fallback to the viewer state which solved the latter.
However it is easier and less error prone
to just rely on viewer state in the first place.

Signed-off-by: Azul <azul@riseup.net>
  • Loading branch information
azul committed Aug 11, 2020
1 parent 7d5f0db commit e955b5a
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/public.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/helpers/links.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ const domHref = function(node) {
const match = ref.match(/^([^?]*)\?fileId=(\d+)/)
if (match) {
const [, relPath, id] = match
const currentDir = OC.Util.History.parseUrlQuery().dir
|| basedir(OCA.Viewer.state.file)
const currentDir = basedir(OCA.Viewer.state.file)
const dir = absolutePath(currentDir, basedir(relPath))
return generateUrl(`/apps/files/?dir=${dir}&openfile=${id}#relPath=${relPath}`)
}
Expand Down
13 changes: 7 additions & 6 deletions src/tests/helpers/links.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { domHref, parseHref } from '../../helpers/links'

global.OC = {
Util: {
History: {
parseUrlQuery: () => ({
dir: '/Wiki',
}),
global.OCA = {
Viewer: {
state: {
file: '/Wiki/file.md',
},
},
}

global.OC = {
config: {modRewriteWorking: true},
webroot: ''
}
Expand Down

0 comments on commit e955b5a

Please sign in to comment.