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

Display image instead of a preview #1544

Merged
merged 15 commits into from
Oct 13, 2023
4 changes: 3 additions & 1 deletion apps/sensenet/src/components/content/Explore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { DocumentViewer } from '../document-viewer'
import { EditBinary } from '../edit/edit-binary'
import { FullScreenLoader } from '../full-screen-loader'
import TreeWithData from '../tree/tree-with-data'
import { BrowseView, EditView, NewView, PermissionView, VersionView } from '../view-controls'
import { BrowseView, EditView, ImageView, NewView, PermissionView, VersionView } from '../view-controls'
import WopiPage from '../wopi-page'

const useStyles = makeStyles((theme: Theme) => {
Expand Down Expand Up @@ -152,6 +152,8 @@ export function Explore({
return <VersionView key={activeContent} contentPath={`${rootPath}${activeContent}`} />
case 'setpermissions':
return <PermissionView key={activeContent} contentPath={`${rootPath}${activeContent}`} />
case 'image':
return <ImageView key={activeContent} contentPath={`${rootPath}${activeContent}`} />
case 'preview':
return <DocumentViewer key={activeContent} contentPath={`${rootPath}${activeContent}`} />
case 'edit-binary':
Expand Down
110 changes: 110 additions & 0 deletions apps/sensenet/src/components/view-controls/image-view.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* @module ViewControls
*/
import { Button, createStyles, makeStyles } from '@material-ui/core'
import { GenericContent } from '@sensenet/default-content-types'
import { useRepository } from '@sensenet/hooks-react'
import React, { ReactElement, useEffect, useState } from 'react'
import { useHistory, useRouteMatch } from 'react-router-dom'
import { useGlobalStyles } from '../../globalStyles'
import { useLocalization } from '../../hooks'
import { navigateToAction } from '../../services'

const useStyles = makeStyles(() => {
return createStyles({
imageViewContainer: {
width: 'auto',
overflow: 'auto',
margin: '0 24px',
},
titleContainer: {
display: 'flex',
justifyContent: 'space-between',
marginTop: '30px',
marginBottom: '20px',
alignItems: 'center',
},
title: {
fontSize: '20px',
paddingRight: '10px',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
},
contentName: {
fontWeight: 500,
},
imageContainer: {
width: '90%',
display: 'flex',
flexDirection: 'column',
flexWrap: 'nowrap',
alignItems: 'flex-start',
},
image: {
maxWidth: '100%',
},
buttonWrapper: {
padding: '20px 0',
width: '90%',
display: 'flex',
flexDirection: 'column',
flexWrap: 'nowrap',
alignItems: 'flex-end',
},
})
})

export interface ImageViewProps {
renderIcon?: (name: string) => ReactElement
handleCancel?: () => void
contentPath: string
}

export const ImageView: React.FC<ImageViewProps> = (props) => {
const repository = useRepository()
const formLocalization = useLocalization().forms
const globalClasses = useGlobalStyles()
const classes = useStyles()
const { contentPath } = props
const [currentContent, setCurrentContent] = useState<GenericContent>()
const history = useHistory()
const routeMatch = useRouteMatch<{ browseType: string; action?: string }>()

useEffect(() => {
async function getCurrentContent() {
const result = await repository.load({
idOrPath: props.contentPath,
})
setCurrentContent(result.d)
}
getCurrentContent()
}, [props.contentPath, repository])

return (
<div className={classes.imageViewContainer}>
<div className={classes.titleContainer}>
<div className={classes.title}>
<span data-test={'image-view-title'} className={classes.contentName}>
{currentContent?.DisplayName}
</span>
</div>
</div>
<div className={classes.imageContainer}>
<img className={classes.image} src={`${repository.configuration.repositoryUrl}${contentPath}`} alt="" />
</div>
<div className={classes.buttonWrapper}>
<Button
aria-label={formLocalization.close}
color="default"
className={globalClasses.cancelButton}
onClick={() => {
navigateToAction({ history, routeMatch })
props.handleCancel?.()
}}>
{formLocalization.close}
</Button>
</div>
</div>
)
}
1 change: 1 addition & 0 deletions apps/sensenet/src/components/view-controls/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './browse-view'
export * from './edit-view'
export * from './image-view'
export * from './new-view'
export * from './permission-view'
export * from './version-view'
4 changes: 4 additions & 0 deletions apps/sensenet/src/services/content-context-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export function getPrimaryActionUrl({
return getUrlForContent({ content, uiSettings, location, action: 'edit-binary', snRoute, removePath })
}

if (content.Type === 'Image' || repository.schemas.isContentFromType<ContentType>(content, 'Image')) {
return getUrlForContent({ content, uiSettings, location, action: 'image', snRoute, removePath })
}

if (
(content as any).Binary &&
(content as any).Binary.__mediaresource.content_type !== 'application/x-javascript' &&
Expand Down
Loading