From 3aa2ef8a2d6fcf10eca2484fe1d3f7c6ab780734 Mon Sep 17 00:00:00 2001 From: Yannick Chiron Date: Wed, 3 Aug 2022 17:27:57 +0200 Subject: [PATCH] fix: Call `openApp()` on note creation when in a mobile Flagship app 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 24af91284645c2eab42355ab402c868385f58326 implementation --- CHANGELOG.md | 1 + .../drive/Toolbar/components/CreateNoteItem.jsx | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d1c86c25e..8c4507d314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/drive/web/modules/drive/Toolbar/components/CreateNoteItem.jsx b/src/drive/web/modules/drive/Toolbar/components/CreateNoteItem.jsx index cd8e87b76b..90f240c47b 100644 --- a/src/drive/web/modules/drive/Toolbar/components/CreateNoteItem.jsx +++ b/src/drive/web/modules/drive/Toolbar/components/CreateNoteItem.jsx @@ -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, @@ -21,6 +24,7 @@ const CreateNoteItem = ({ client, t, displayedFolder }) => { capabilities, 'capabilities.data.attributes.flat_subdomains' ) + const webviewIntent = useWebviewIntent() let notesAppUrl = undefined let notesAppIsInstalled = true @@ -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 }