-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mock data updates
- Loading branch information
Showing
65 changed files
with
893 additions
and
876 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...FilePreview/BaseRenderers/TXTRenderer.jsx → ...ileRenderer/BaseRenderers/TXTRenderer.jsx
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
src/components/FilePreview/components/FileRenderer/hooks.js
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useKeyedState, StrictDict } from '@edx/react-unit-test-utils'; | ||
|
||
import { errorStatuses, errorMessages, renderers } from '../constants'; | ||
import { getFileType } from '../utils'; | ||
import messages from './messages'; | ||
|
||
export const stateKeys = StrictDict({ | ||
errorStatus: 'errorStatus', | ||
isLoading: 'isLoading', | ||
}); | ||
|
||
/** | ||
* component hooks | ||
*/ | ||
export const useRenderData = ({ | ||
file, | ||
formatMessage, | ||
}) => { | ||
const [errorStatus, setErrorStatus] = useKeyedState(stateKeys.errorStatus, null); | ||
const [isLoading, setIsLoading] = useKeyedState(stateKeys.isLoading, true); | ||
|
||
const setState = (newState) => { | ||
setErrorStatus(newState.errorStatus); | ||
setIsLoading(newState.isLoading); | ||
}; | ||
|
||
const stopLoading = (status = null) => setState({ isLoading: false, errorStatus: status }); | ||
|
||
const errorMessage = ( | ||
errorMessages[errorStatus] || errorMessages[errorStatuses.serverError] | ||
); | ||
const errorAction = { | ||
id: 'retry', | ||
onClick: () => setState({ errorStatus: null, isLoading: true }), | ||
message: messages.retryButton, | ||
}; | ||
const error = { | ||
headerMessage: errorMessage, | ||
children: formatMessage(errorMessage), | ||
actions: [errorAction], | ||
}; | ||
|
||
const Renderer = renderers[getFileType(file.fileName)]; | ||
const rendererProps = { | ||
fileName: file.fileName, | ||
url: file.fileUrl, | ||
onError: stopLoading, | ||
onSuccess: () => stopLoading(), | ||
}; | ||
|
||
return { | ||
errorStatus, | ||
isLoading, | ||
error, | ||
Renderer, | ||
rendererProps, | ||
}; | ||
}; |
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
16 changes: 16 additions & 0 deletions
16
src/components/FilePreview/components/FileRenderer/messages.js
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { defineMessages } from '@edx/frontend-platform/i18n'; | ||
|
||
const messages = defineMessages({ | ||
fileInfo: { | ||
id: 'ora-grading.InfoPopover.fileInfo', | ||
defaultMessage: 'File info', | ||
description: 'Popover trigger button text for file preview card', | ||
}, | ||
retryButton: { | ||
id: 'ora-grading.ResponseDisplay.FileRenderer.retryButton', | ||
defaultMessage: 'Retry', | ||
description: 'Retry button for error in file renderer', | ||
}, | ||
}); | ||
|
||
export default messages; |
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { StrictDict } from '@edx/react-unit-test-utils'; | ||
|
||
import { | ||
PDFRenderer, | ||
ImageRenderer, | ||
TXTRenderer, | ||
} from './FileRenderer/BaseRenderers'; | ||
|
||
import messages from './messages'; | ||
|
||
export const errorStatuses = StrictDict({ | ||
badRequest: 400, | ||
unauthorized: 401, | ||
forbidden: 403, | ||
notFound: 404, | ||
conflict: 409, | ||
serverError: 500, | ||
}); | ||
|
||
export const fileTypes = StrictDict({ | ||
pdf: 'pdf', | ||
jpg: 'jpg', | ||
jpeg: 'jpeg', | ||
png: 'png', | ||
bmp: 'bmp', | ||
txt: 'txt', | ||
gif: 'gif', | ||
jfif: 'jfif', | ||
pjpeg: 'pjpeg', | ||
pjp: 'pjp', | ||
svg: 'svg', | ||
}); | ||
|
||
export const errorMessages = { | ||
[errorStatuses.notFound]: messages.fileNotFoundError, | ||
[errorStatuses.serverError]: messages.unknownError, | ||
}; | ||
|
||
/** | ||
* Config data | ||
*/ | ||
export const renderers = { | ||
[fileTypes.pdf]: PDFRenderer, | ||
[fileTypes.jpg]: ImageRenderer, | ||
[fileTypes.jpeg]: ImageRenderer, | ||
[fileTypes.bmp]: ImageRenderer, | ||
[fileTypes.png]: ImageRenderer, | ||
[fileTypes.txt]: TXTRenderer, | ||
[fileTypes.gif]: ImageRenderer, | ||
[fileTypes.jfif]: ImageRenderer, | ||
[fileTypes.pjpeg]: ImageRenderer, | ||
[fileTypes.pjp]: ImageRenderer, | ||
[fileTypes.svg]: ImageRenderer, | ||
}; | ||
|
||
export const supportedTypes = Object.keys(renderers); |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as FileRenderer } from './FileRenderer'; | ||
export { isSupported } from './utils'; |
10 changes: 0 additions & 10 deletions
10
src/components/FilePreview/messages.js → ...onents/FilePreview/components/messages.js
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
PDFRenderer, | ||
ImageRenderer, | ||
TXTRenderer, | ||
} from './FileRenderer/BaseRenderers'; | ||
|
||
import { supportedTypes } from './constants'; | ||
|
||
/** | ||
* Util methods and transforms | ||
*/ | ||
export const getFileType = (fileName) => fileName.split('.').pop()?.toLowerCase(); | ||
export const isSupported = ({ fileName }) => supportedTypes.includes( | ||
getFileType(fileName), | ||
); |
Oops, something went wrong.