Skip to content

Commit

Permalink
fix: Call openApp() on note creation when in a mobile Flagship app
Browse files Browse the repository at this point in the history
When in a mobile Flagship app we shouldn't rely on editing
`window.location.href` in order to trigger navigation

Instead we should call `openApp` from `cozy-intent` so the navigation
is handled on mobile app's native side

Based on 24af912 implementation
  • Loading branch information
Ldoppea authored and Crash-- committed Aug 4, 2022
1 parent 1172573 commit 3aa2ef8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## 🐛 Bug Fixes

* Improve cozy-bar implementation to fix UI bugs in Amirale
* Fix navigation through mobile Flagship on Note creation and opening

## 🔧 Tech

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react'
import get from 'lodash/get'

import { isFlagshipApp } from 'cozy-device-helper'
import { useWebviewIntent } from 'cozy-intent'

import {
withClient,
models,
Expand All @@ -21,6 +24,7 @@ const CreateNoteItem = ({ client, t, displayedFolder }) => {
capabilities,
'capabilities.data.attributes.flat_subdomains'
)
const webviewIntent = useWebviewIntent()

let notesAppUrl = undefined
let notesAppIsInstalled = true
Expand Down Expand Up @@ -55,11 +59,20 @@ const CreateNoteItem = ({ client, t, displayedFolder }) => {
dir_id: displayedFolder.id
})

window.location.href = await models.note.generatePrivateUrl(
const privateUrl = await models.note.generatePrivateUrl(
notesAppUrl,
file,
{ returnUrl }
)

/**
* Not using AppLinker here because it would require too much refactoring and would be risky
* Instead we use the webviewIntent programmatically to open the cozy-note app on the note href
*/
if (isFlagshipApp() && webviewIntent)
return webviewIntent.call('openApp', privateUrl, { slug: 'notes' })

window.location.href = privateUrl
} else {
window.location.href = notesAppUrl
}
Expand Down

0 comments on commit 3aa2ef8

Please sign in to comment.