Skip to content

Commit 8473b71

Browse files
author
Travis CI User
committed
publish: Merge pull request #281 from cozy/feat/add-translate-apps
generated from commit 7e07ec9
1 parent 6500c77 commit 8473b71

25 files changed

+1154
-1135
lines changed

en/cozy-apps-registry/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4336,7 +4336,7 @@ <h5 id="properties-meaning-reference">Properties meaning (reference)<a class="he
43364336
</tr>
43374337
<tr>
43384338
<td><code>offline_support</code></td>
4339-
<td>(Boolean) indicating if the app supports Offline mode when opened from our Flagship applicaiton. See <a href="https://github.com/cozy/cozy-flagship-app/blob/master/docs/how-to-make-cozy-app-offline-compatible.md">Flagship Offline mode</a> documentation</td>
4339+
<td>(Boolean) indicating if the app supports Offline mode when opened from our Flagship application. See <a href="https://github.com/cozy/cozy-flagship-app/blob/master/docs/how-to-make-cozy-app-offline-compatible.md">Flagship Offline mode</a> documentation</td>
43404340
</tr>
43414341
<tr>
43424342
<td><code>parameters</code></td>

en/cozy-client/api/cozy-stack-client/index.html

Lines changed: 65 additions & 40 deletions
Large diffs are not rendered by default.

en/cozy-home/manifest.webapp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"version": "1.85.0",
1515
"licence": "AGPL-3.0",
16+
"offline_support": true,
1617
"permissions": {
1718
"home": {
1819
"description": "Required to manage default redirection update",

en/cozy-home/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"dependencies": {
3737
"@sentry/react": "7.119.0",
3838
"cozy-client": "^51.6.0",
39-
"cozy-dataproxy-lib": "^2.3.0",
39+
"cozy-dataproxy-lib": "^3.4.1",
4040
"cozy-device-helper": "3.7.1",
4141
"cozy-devtools": "^1.2.1",
4242
"cozy-doctypes": "1.83.8",
@@ -47,6 +47,7 @@
4747
"cozy-keys-lib": "^6.1.1",
4848
"cozy-logger": "1.10.4",
4949
"cozy-minilog": "^3.3.1",
50+
"cozy-pouch-link": "^54.0.0",
5051
"cozy-realtime": "^5.0.4",
5152
"cozy-stack-client": "^51.6.0",
5253
"cozy-tsconfig": "1.2.0",

en/cozy-home/src/components/AppHighlightAlert/AppHighlightAlertWrapper.jsx

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,52 @@ import React, { useEffect, useState } from 'react'
22

33
import { getAvailableAppHighlightAlerts } from 'components/AppHighlightAlert/helpers'
44
import { useClient } from 'cozy-client'
5+
import log from 'cozy-logger'
56

67
const AppHighlightAlertWrapper = ({ apps }) => {
78
const [appHighlightAlerts, setAppHighlightAlerts] = useState([])
9+
const [isAppHighlightAlertsError, setIsAppHighlightAlertsError] =
10+
useState(false)
811
const client = useClient()
912

1013
useEffect(() => {
1114
const getAppHighlightAlerts = async () => {
12-
const availableAppHighlightAlerts = await getAvailableAppHighlightAlerts(
13-
client,
14-
apps
15-
)
16-
17-
setAppHighlightAlerts(availableAppHighlightAlerts)
15+
try {
16+
const availableAppHighlightAlerts =
17+
await getAvailableAppHighlightAlerts(client, apps)
18+
19+
setAppHighlightAlerts(availableAppHighlightAlerts)
20+
} catch (error) {
21+
log('error', `App highlight error: ${error}`)
22+
setIsAppHighlightAlertsError(true)
23+
}
1824
}
1925

20-
if (apps && appHighlightAlerts.length === 0) {
26+
if (apps && !isAppHighlightAlertsError && appHighlightAlerts.length === 0) {
2127
getAppHighlightAlerts()
2228
}
23-
}, [client, apps, appHighlightAlerts.length])
29+
}, [client, apps, isAppHighlightAlertsError, appHighlightAlerts.length])
2430

25-
useEffect(() => {
31+
if (appHighlightAlerts && appHighlightAlerts?.length > 0) {
2632
appHighlightAlerts.forEach(component => {
27-
if (component.displayed) {
28-
component.onDisplayed()
29-
} else {
30-
component.onNotDisplayed()
33+
if (component) {
34+
component.displayed
35+
? component.onDisplayed()
36+
: component.onNotDisplayed()
3137
}
3238
})
39+
}
40+
41+
useEffect(() => {
42+
if (appHighlightAlerts && appHighlightAlerts?.length > 0) {
43+
appHighlightAlerts.forEach(component => {
44+
if (component) {
45+
component.displayed
46+
? component.onDisplayed()
47+
: component.onNotDisplayed()
48+
}
49+
})
50+
}
3351
}, [appHighlightAlerts])
3452

3553
return (

en/cozy-home/src/components/AppWrapper.jsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
import React, { createContext } from 'react'
1+
import React, { createContext, useEffect, useState } from 'react'
22
import { Provider as ReduxProvider } from 'react-redux'
33
import memoize from 'lodash/memoize'
44

55
import flag from 'cozy-flags'
6-
import CozyClient, { CozyProvider, RealTimeQueries } from 'cozy-client'
6+
import CozyClient, {
7+
CozyProvider,
8+
RealTimeQueries,
9+
WebFlagshipLink
10+
} from 'cozy-client'
711
import CozyDevtools from 'cozy-devtools'
12+
import { useWebviewIntent } from 'cozy-intent'
813
import I18n from 'cozy-ui/transpiled/react/providers/I18n'
914
import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme'
1015
import { BreakpointsProvider } from 'cozy-ui/transpiled/react/providers/Breakpoints'
@@ -14,7 +19,7 @@ import { useCozyTheme } from 'cozy-ui/transpiled/react/providers/CozyTheme'
1419

1520
import configureStore from 'store/configureStore'
1621
import { RealtimePlugin } from 'cozy-realtime'
17-
// import { isFlagshipApp } from 'cozy-device-helper'
22+
import { isFlagshipApp, isFlagshipOfflineSupported } from 'cozy-device-helper'
1823

1924
import { DataProxyProvider } from 'cozy-dataproxy-lib'
2025
import { useWallpaperContext } from 'hooks/useWallpaperContext'
@@ -32,12 +37,19 @@ export const AppContext = createContext()
3237
*
3338
* Is memoized to avoid several clients in case of hot-reload
3439
*/
35-
export const setupAppContext = memoize(() => {
40+
export const setupAppContext = memoize(intent => {
3641
const lang = document.documentElement.getAttribute('lang') || 'en'
3742
const context = window.context || 'cozy'
3843
const root = document.querySelector('[role=application]')
3944
const data = root.dataset
4045

46+
const shouldUseWebFlagshipLink =
47+
isFlagshipApp() && isFlagshipOfflineSupported()
48+
49+
const links = shouldUseWebFlagshipLink
50+
? [new WebFlagshipLink({ webviewIntent: intent })]
51+
: null
52+
4153
// New improvements must be done with CozyClient
4254
const cozyClient = new CozyClient({
4355
uri: `${window.location.protocol}//${data.cozyDomain}`,
@@ -48,7 +60,8 @@ export const setupAppContext = memoize(() => {
4860
'home.store.persist'
4961
)
5062
? true
51-
: false
63+
: false,
64+
links
5265
})
5366

5467
cozyClient.registerPlugin(flag.plugin)
@@ -103,7 +116,21 @@ const ThemeProvider = ({ children }) => {
103116
* for an app
104117
*/
105118
const AppWrapper = ({ children }) => {
106-
const appContext = setupAppContext()
119+
const webviewIntent = useWebviewIntent()
120+
const [appContext, setAppContext] = useState(undefined)
121+
122+
useEffect(() => {
123+
if (isFlagshipApp() && !webviewIntent) return
124+
125+
const newAppContext = setupAppContext(webviewIntent)
126+
127+
setAppContext(newAppContext)
128+
}, [webviewIntent])
129+
130+
if (!appContext) {
131+
return null
132+
}
133+
107134
const { store, cozyClient, context, lang, persistor } = appContext
108135

109136
return (

en/cozy-home/src/components/DefaultRedirectionSnackbar/DefaultRedirectionSnackbar.jsx

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react'
22

3-
import { useClient, useQuery } from 'cozy-client'
3+
import { useSettings } from 'cozy-client'
44
import { useWebviewIntent } from 'cozy-intent'
55
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
66
import { makeStyles } from 'cozy-ui/transpiled/react/styles'
@@ -10,13 +10,12 @@ import Button from 'cozy-ui/transpiled/react/Buttons'
1010
import Icon from 'cozy-ui/transpiled/react/Icon'
1111
import LightbulbIcon from 'cozy-ui/transpiled/react/Icons/Lightbulb'
1212

13-
import { instanceSettingsConn, homeSettingsConn } from 'queries'
1413
import {
15-
shouldShowDefaultRedirectionSnackbar,
16-
disableDefaultRedirectionSnackbar,
17-
setDefaultRedirectionToHome
18-
} from './helpers'
14+
HOME_DEFAULT_REDIRECTION,
15+
useShouldShowDefaultRedirectionSnackbar
16+
} from './useShouldShowDefaultRedirectionSnackbar'
1917
import useIncrementDefaultRedirectionViewCount from './useIncrementDefaultRedirectionViewCount'
18+
import { isFlagshipApp } from 'cozy-device-helper'
2019

2120
const useStyles = makeStyles(theme => ({
2221
snackbar: {
@@ -29,39 +28,39 @@ const useStyles = makeStyles(theme => ({
2928

3029
const DefaultAppSnackbar = () => {
3130
const { t } = useI18n()
32-
const client = useClient()
3331
const classes = useStyles()
3432
const [isOpen, setIsOpen] = useState(true)
3533

3634
const webviewIntent = useWebviewIntent()
3735

38-
const instanceSettingsResult = useQuery(
39-
instanceSettingsConn.query,
40-
instanceSettingsConn
41-
)
36+
const { save: saveHome } = useSettings('home', [
37+
'default_redirection_snackbar_disabled'
38+
])
4239

43-
const homeSettingsResult = useQuery(homeSettingsConn.query, homeSettingsConn)
40+
const { save: saveGlobal } = useSettings('instance', ['default_redirection'])
4441

45-
useIncrementDefaultRedirectionViewCount(
46-
instanceSettingsResult,
47-
homeSettingsResult
48-
)
42+
useIncrementDefaultRedirectionViewCount()
4943

50-
const showDefaultAppSnackbar = shouldShowDefaultRedirectionSnackbar(
51-
instanceSettingsResult,
52-
homeSettingsResult,
53-
isOpen
54-
)
44+
const showDefaultAppSnackbar = useShouldShowDefaultRedirectionSnackbar(isOpen)
5545

5646
const onRefuse = () => {
5747
setIsOpen(false)
58-
disableDefaultRedirectionSnackbar(client, homeSettingsResult)
48+
saveHome({
49+
default_redirection_snackbar_disabled: true
50+
})
5951
}
6052

6153
const onAccept = () => {
6254
setIsOpen(false)
63-
disableDefaultRedirectionSnackbar(client, homeSettingsResult)
64-
setDefaultRedirectionToHome(client, instanceSettingsResult, webviewIntent)
55+
saveHome({
56+
default_redirection_snackbar_disabled: true
57+
})
58+
saveGlobal({
59+
default_redirection: HOME_DEFAULT_REDIRECTION
60+
})
61+
if (isFlagshipApp()) {
62+
webviewIntent.call('setDefaultRedirection', HOME_DEFAULT_REDIRECTION)
63+
}
6564
}
6665

6766
return (
Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import React from 'react'
22
import { render, fireEvent } from '@testing-library/react'
33

4+
import { useSettings } from 'cozy-client'
5+
46
import CozyTheme from 'cozy-ui/transpiled/react/providers/CozyTheme'
57

68
import AppLike from 'test/AppLike'
79
import DefaultRedirectionSnackbar from './DefaultRedirectionSnackbar'
8-
import {
9-
shouldShowDefaultRedirectionSnackbar,
10-
disableDefaultRedirectionSnackbar,
11-
setDefaultRedirectionToHome
12-
} from './helpers'
10+
import { useShouldShowDefaultRedirectionSnackbar } from './useShouldShowDefaultRedirectionSnackbar'
1311

1412
jest.mock('cozy-client', () => ({
1513
...jest.requireActual('cozy-client'),
1614
useQuery: jest.fn(),
17-
useClient: jest.fn()
15+
useClient: jest.fn(),
16+
useSettings: jest.fn()
1817
}))
19-
jest.mock('./helpers')
18+
jest.mock('./useShouldShowDefaultRedirectionSnackbar')
2019
jest.mock('./useIncrementDefaultRedirectionViewCount')
2120

2221
const setup = () => {
@@ -36,7 +35,26 @@ describe('DefaultRedirectionSnackbar', () => {
3635
})
3736

3837
it('should display default redirection snackbar', () => {
39-
shouldShowDefaultRedirectionSnackbar.mockReturnValue(true)
38+
useShouldShowDefaultRedirectionSnackbar.mockReturnValue(true)
39+
const mockSaveInstance = jest.fn()
40+
const mockSaveHome = jest.fn()
41+
useSettings.mockImplementation((...args) => {
42+
if (args[0] === 'instance') {
43+
return {
44+
values: {
45+
default_redirection: 'drive/#/folder'
46+
},
47+
save: mockSaveInstance
48+
}
49+
} else if (args[0] === 'home') {
50+
return {
51+
values: {
52+
default_redirection_view_count: 4
53+
},
54+
save: mockSaveHome
55+
}
56+
}
57+
})
4058

4159
const { root } = setup()
4260

@@ -45,24 +63,70 @@ describe('DefaultRedirectionSnackbar', () => {
4563
})
4664

4765
it('should disable default redirection snackbar and set default redirection to home when accepting', () => {
48-
shouldShowDefaultRedirectionSnackbar.mockReturnValue(true)
66+
useShouldShowDefaultRedirectionSnackbar.mockReturnValue(true)
67+
68+
const mockSaveInstance = jest.fn()
69+
const mockSaveHome = jest.fn()
70+
useSettings.mockImplementation((...args) => {
71+
if (args[0] === 'instance') {
72+
return {
73+
values: {
74+
default_redirection: 'drive/#/folder'
75+
},
76+
save: mockSaveInstance
77+
}
78+
} else if (args[0] === 'home') {
79+
return {
80+
values: {
81+
default_redirection_view_count: 4
82+
},
83+
save: mockSaveHome
84+
}
85+
}
86+
})
4987

5088
const { root } = setup()
5189

5290
fireEvent.click(root.queryByText('OK'))
5391

54-
expect(disableDefaultRedirectionSnackbar).toHaveBeenCalled()
55-
expect(setDefaultRedirectionToHome).toHaveBeenCalled()
92+
expect(mockSaveInstance).toHaveBeenCalledWith({
93+
default_redirection: 'home/'
94+
})
95+
expect(mockSaveHome).toHaveBeenCalledWith({
96+
default_redirection_snackbar_disabled: true
97+
})
5698
})
5799

58100
it('should disable default redirection snackbar when refusing', () => {
59-
shouldShowDefaultRedirectionSnackbar.mockReturnValue(true)
101+
useShouldShowDefaultRedirectionSnackbar.mockReturnValue(true)
102+
103+
const mockSaveInstance = jest.fn()
104+
const mockSaveHome = jest.fn()
105+
useSettings.mockImplementation((...args) => {
106+
if (args[0] === 'instance') {
107+
return {
108+
values: {
109+
default_redirection: 'drive/#/folder'
110+
},
111+
save: mockSaveInstance
112+
}
113+
} else if (args[0] === 'home') {
114+
return {
115+
values: {
116+
default_redirection_view_count: 4
117+
},
118+
save: mockSaveHome
119+
}
120+
}
121+
})
60122

61123
const { root } = setup()
62124

63125
fireEvent.click(root.queryByText('No, thank you'))
64126

65-
expect(disableDefaultRedirectionSnackbar).toHaveBeenCalled()
66-
expect(setDefaultRedirectionToHome).not.toHaveBeenCalled()
127+
expect(mockSaveHome).toHaveBeenCalledWith({
128+
default_redirection_snackbar_disabled: true
129+
})
130+
expect(mockSaveInstance).not.toHaveBeenCalled()
67131
})
68132
})

0 commit comments

Comments
 (0)