Skip to content

Commit

Permalink
feat: Cache /apps/:slug/open request for offline support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ldoppea committed May 31, 2024
1 parent d726534 commit a3828ba
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/libs/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export {
callOnboardingInitClient
} from '/libs/clientHelpers/initClient'
export { call2FAInitClient } from '/libs/clientHelpers/twoFactorAuthentication'
import { CozyPersistedStorageKeys, getData } from '/libs/localStore/storage'
import { CozyPersistedStorageKeys, getData, storeData } from '/libs/localStore/storage'

Check failure on line 32 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Replace `·CozyPersistedStorageKeys,·getData,·storeData·` with `⏎··CozyPersistedStorageKeys,⏎··getData,⏎··storeData⏎`

Check failure on line 32 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

'storeData' is defined but never used
import { getLinks } from '/pouchdb/getPouchLinks'

const log = Minilog('LoginScreen')
Expand Down Expand Up @@ -110,6 +110,7 @@ export const fetchPublicData = async client => {
*/

export const fetchCozyDataForSlug = async (slug, client, cookie) => {
const cacheKey = `CozyData_${client.getStackClient().uri}_${slug}`
const stackClient = client.getStackClient()

const options = cookie
Expand All @@ -123,12 +124,26 @@ export const fetchCozyDataForSlug = async (slug, client, cookie) => {
}
: undefined

const result = await stackClient.fetchJSON(
'GET',
`/apps/${slug}/open`,
undefined,
options
)
try {

Check failure on line 127 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`
const result = await stackClient.fetchJSON(

Check failure on line 128 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`
'GET',

Check failure on line 129 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`
`/apps/${slug}/open`,

Check failure on line 130 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`
undefined,

Check failure on line 131 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`
options

Check failure on line 132 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`
)

Check failure on line 133 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`

cacheSet(cacheKey, result)

Check failure on line 135 in src/libs/client.js

View workflow job for this annotation

GitHub Actions / Quality Checks

Delete `··`

return result
} catch (err) {
const cachedResult = await cacheGet(cacheKey)

if (cachedResult) {
return cachedResult
}

throw err
}

return result
}
Expand Down

0 comments on commit a3828ba

Please sign in to comment.