-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IIIF #5 - Adding resources index and edit pages
- Loading branch information
1 parent
56e87e1
commit b0d3ac5
Showing
14 changed files
with
291 additions
and
28 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
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
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
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
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,84 @@ | ||
// @flow | ||
|
||
import { FileInputButton, LazyImage } from '@performant-software/semantic-components'; | ||
import React, { type ComponentType, useEffect } from 'react'; | ||
import { withTranslation } from 'react-i18next'; | ||
import { useParams } from 'react-router-dom'; | ||
import { Button, Form } from 'semantic-ui-react'; | ||
import _ from 'underscore'; | ||
import ResourcesService from '../services/Resources'; | ||
import withEditPage from '../hooks/EditPage'; | ||
import SimpleEditPage from '../components/SimpleEditPage'; | ||
|
||
const ProjectForm = withTranslation()((props) => { | ||
const { projectId } = useParams(); | ||
|
||
useEffect(() => { | ||
props.onSetState({ project_id: projectId }); | ||
}, [projectId]); | ||
|
||
return ( | ||
<SimpleEditPage | ||
{...props} | ||
> | ||
<SimpleEditPage.Tab | ||
key='details' | ||
name={props.t('Common.tabs.details')} | ||
> | ||
<Form.Input | ||
label={props.t('Resource.labels.content')} | ||
> | ||
<LazyImage | ||
preview={props.item.content_url} | ||
src={props.item.content_url} | ||
size='medium' | ||
> | ||
{ !props.item.content_url && ( | ||
<FileInputButton | ||
color='green' | ||
content={props.t('Common.buttons.upload')} | ||
icon='cloud upload' | ||
onSelection={(files) => { | ||
const file = _.first(files); | ||
props.onSetState({ content: file, content_url: URL.createObjectURL(file) }); | ||
}} | ||
/> | ||
)} | ||
{ props.item.content_url && ( | ||
<Button | ||
color='red' | ||
content={props.t('Common.buttons.remove')} | ||
icon='times' | ||
onClick={() => props.onSetState({ content: null, content_url: null, content_remove: true })} | ||
/> | ||
)} | ||
</LazyImage> | ||
</Form.Input> | ||
<Form.Input | ||
error={props.isError('name')} | ||
label={props.t('Project.labels.name')} | ||
onChange={props.onTextInputChange.bind(this, 'name')} | ||
required={props.isRequired('name')} | ||
value={props.item.name} | ||
/> | ||
</SimpleEditPage.Tab> | ||
</SimpleEditPage> | ||
); | ||
}); | ||
|
||
const Resource: ComponentType<any> = withEditPage(ProjectForm, { | ||
id: 'resourceId', | ||
onInitialize: ( | ||
(id) => ResourcesService | ||
.fetchOne(id) | ||
.then(({ data }) => data.resource) | ||
), | ||
onSave: ( | ||
(resource) => ResourcesService | ||
.save(resource) | ||
.then(({ data }) => data.resource) | ||
), | ||
required: ['name'] | ||
}); | ||
|
||
export default Resource; |
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,34 @@ | ||
// @flow | ||
|
||
import { ItemList, LazyImage } from '@performant-software/semantic-components'; | ||
import React, { type ComponentType } from 'react'; | ||
import { useNavigate, useParams } from 'react-router-dom'; | ||
import ResourcesService from '../services/Resources'; | ||
|
||
const Resources: ComponentType<any> = () => { | ||
const navigate = useNavigate(); | ||
const { projectId } = useParams(); | ||
|
||
return ( | ||
<ItemList | ||
actions={[{ | ||
name: 'edit', | ||
onClick: (item) => navigate(item.id.toString()) | ||
}, { | ||
name: 'delete' | ||
}]} | ||
addButton={{ | ||
location: 'top', | ||
onClick: () => navigate('new') | ||
}} | ||
collectionName='resources' | ||
onLoad={(params) => ResourcesService.fetchAll({ ...params, project_id: projectId })} | ||
onDelete={(resource) => ResourcesService.delete(resource)} | ||
renderHeader={(resource) => resource.name} | ||
renderImage={(resource) => <LazyImage src={resource.content_url} />} | ||
renderMeta={() => ''} | ||
/> | ||
); | ||
}; | ||
|
||
export default Resources; |
Oops, something went wrong.