Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hooks): Add useClientErrors from cozy-client #2710

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/styleguide.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path')

const webpackMerge = require('webpack-merge')

Check warning on line 3 in docs/styleguide.config.js

View workflow job for this annotation

GitHub Actions / build

'webpack-merge' should be listed in the project's dependencies. Run 'npm i -S webpack-merge' to add it

module.exports = {
title: 'Cozy UI React components',
Expand Down Expand Up @@ -95,8 +95,7 @@
'../react/SquareAppIcon',
'../react/QualificationGrid',
'../react/QualificationItem',
'../react/UploadQueue',
'../react/Viewer'
'../react/UploadQueue'
]
},
{
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@
"svgo": "2.8.0",
"svgstore-cli": "1.3.2",
"url-loader": "1.1.2",
"webpack": "4.39.3"
"webpack": "4.39.3",
"whatwg-fetch": "3.5.0"
},
"dependencies": {
"@babel/runtime": "^7.3.4",
Expand Down Expand Up @@ -210,4 +211,4 @@
"browserslist": [
"extends browserslist-config-cozy"
]
}
}
69 changes: 66 additions & 3 deletions react/FileImageLoader/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,77 @@
A component to get the image in `links` prop of a file, according to its class (could be `image` or `pdf`).

```jsx
import DemoProvider from 'cozy-ui/transpiled/react/Viewer/docs/DemoProvider'

import DemoProvider from 'cozy-ui/transpiled/react/providers/DemoProvider'
import FileImageLoader from 'cozy-ui/transpiled/react/FileImageLoader'
import Icon from 'cozy-ui/transpiled/react/Icon'
import FileDuotoneIcon from "cozy-ui/transpiled/react/Icons/FileDuotone"
import BankIcon from "cozy-ui/transpiled/react/Icons/Bank"
import CloudWallpaper from 'cozy-ui/docs/cloud-wallpaper.jpg'

const demoTextFileResponse = {
text: () => new Promise(resolve => resolve('Hello World !'))
}

const demoFilesByClass = {
pdf: 'https://raw.githubusercontent.com/rospdf/pdf-php/2ccf7591fc2f18e63342ebfedad7997b08c34ed2/readme.pdf',
audio: 'https://viewerdemo.cozycloud.cc/Z.mp3',
video: 'https://viewerdemo.cozycloud.cc/Nextcloud.mp4',
text: 'https://viewerdemo.cozycloud.cc/notes.md'
}

const mockClient = {
plugins: {
realtime: {
subscribe: () => {},
unsubscribe: () => {},
unsubscribeAll: () => {}
}
},
on: () => {},
collection: () => ({
getDownloadLinkById: id =>
new Promise(resolve => resolve(demoFilesByClass[id])),
download: () =>
alert(
"This is a demo, there's no actual Cozy to download the file from ¯\\_(ツ)_/¯"
),
get: () =>
new Promise(resolve =>
resolve({
data: {
links: {
large: CloudWallpaper
}
}
})
)
}),
getStackClient: () => ({
uri: '',
fetch: () => new Promise(resolve => resolve(demoTextFileResponse))
}),
getClient: () => mockClient,
store: {
getState: () => {},
subscribe: () => {},
unsubscribe: () => {}
},
getQueryFromState: queryName => {
if (queryName === 'io.cozy.files/parent_folder') {
return {
data: {
_id: 'parent_id',
path: '/Parent'
}
}
}
},
query: () => ({
data: [{ attributes: { slug: 'mespapiers' }, links: { related: '' } }]
}),
getInstanceOptions: () => ({ app: { slug: 'mespapiers' }, subdomain: 'flat' })
}

const file = {
_id: 'image',
class: 'image',
Expand All @@ -31,7 +94,7 @@ const FallbackComp = () => {

;

<DemoProvider>
<DemoProvider client={mockClient}>
<FileImageLoader
file={file}
linkType="large"
Expand Down
6 changes: 3 additions & 3 deletions react/FileImageLoader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types'
import { Component } from 'react'

import { withClient } from 'cozy-client'
import { isEncrypted } from 'cozy-client/dist/models/file'
import logger from 'cozy-logger'

const PENDING = 'PENDING'
Expand All @@ -12,8 +13,7 @@ const FAILED = 'FAILED'
const GET_LINK = 'GET_LINK'

import { checkImageSource } from './checkImageSource'
import { isFileEncrypted } from '../Viewer/helpers'
import { EncryptedContext } from '../Viewer/providers/EncryptedProvider'
import { EncryptedContext } from '../providers/Encrypted'

export class FileImageLoader extends Component {
state = {
Expand Down Expand Up @@ -60,7 +60,7 @@ export class FileImageLoader extends Component {

loadNextSrc(lastError = null) {
const { file } = this.props
if (isFileEncrypted(file)) {
if (isEncrypted(file)) {
// No link available for encrypted files
return
}
Expand Down
2 changes: 1 addition & 1 deletion react/FileImageLoader/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import logger from 'cozy-logger'

import { FileImageLoader } from '.'
import { checkImageSource } from './checkImageSource'
import EncryptedProvider from '../Viewer/providers/EncryptedProvider'
import EncryptedProvider from '../providers/Encrypted'

jest.mock('./checkImageSource', () => ({
...jest.requireActual('./checkImageSource'),
Expand Down
29 changes: 0 additions & 29 deletions react/Viewer/Footer/BottomSheetContent.jsx

This file was deleted.

67 changes: 0 additions & 67 deletions react/Viewer/Footer/DownloadButton.jsx

This file was deleted.

22 changes: 0 additions & 22 deletions react/Viewer/Footer/FooterActionButtons.jsx

This file was deleted.

30 changes: 0 additions & 30 deletions react/Viewer/Footer/FooterActionButtons.spec.jsx

This file was deleted.

Loading
Loading