Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add getFlagshipDownloadLink function
The aim of this function is to provide a link to the download page for the flagship application and its white-label versions
- Loading branch information
Showing
4 changed files
with
159 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,42 @@ | ||
import get from 'lodash/get' | ||
import { isAndroid, isIOS } from 'cozy-device-helper' | ||
import flag from 'cozy-flags' | ||
|
||
/** | ||
* Checks if a document has been updated by a specific app | ||
* | ||
* @param {object} doc - The document to check | ||
* @param {string} appSlug - The slug of the app to check | ||
* @returns {boolean} - True if the document has been updated by the app, false otherwise | ||
*/ | ||
export const hasBeenUpdatedByApp = (doc, appSlug) => { | ||
const updatedByApps = get(doc, 'cozyMetadata.updatedByApps') | ||
return Boolean(updatedByApps && updatedByApps.find(x => x.slug === appSlug)) | ||
} | ||
|
||
/** | ||
* Gets the app that created a document | ||
* | ||
* @param {object} doc - The document to check | ||
* @returns {string} - The slug of the app that created the document | ||
*/ | ||
export const getCreatedByApp = doc => get(doc, 'cozyMetadata.createdByApp') | ||
|
||
/** | ||
* Gets the download link for the Cozy Flagship app and his white-labels versions | ||
* | ||
* @param {string} lang - The language code for the download page | ||
* @returns {string} - The URL of the download page | ||
*/ | ||
export const getFlagshipDownloadLink = lang => { | ||
if (isAndroid()) { | ||
const id = flag('flagship.playstore_id') || 'io.cozy.flagship.mobile' | ||
return `https://play.google.com/store/apps/details?id=${id}&hl=${lang}` | ||
} | ||
if (isIOS()) { | ||
const id = flag('flagship.appstore_id') || 'id1600636174' | ||
return `https://apps.apple.com/${lang}/app/${id}` | ||
} | ||
|
||
return flag('flagship.download_link') || `https://cozy.io/${lang}/download` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export function hasBeenUpdatedByApp(doc: any, appSlug: any): boolean; | ||
export function getCreatedByApp(doc: any): any; | ||
export function hasBeenUpdatedByApp(doc: object, appSlug: string): boolean; | ||
export function getCreatedByApp(doc: object): string; | ||
export function getFlagshipDownloadLink(lang: string): string; |