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

Recrop option to disable if image is not from Grid #1698

Merged
merged 3 commits into from
Oct 17, 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
1 change: 1 addition & 0 deletions fronts-client/src/components/form/ChefMetaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const Form = ({
name="chefImageOverride"
component={InputImage}
criteria={squareImageCriteria}
defaultImageUrl={chef?.bylineImageUrl}
/>
</ImageCol>
</Row>
Expand Down
27 changes: 18 additions & 9 deletions fronts-client/src/components/inputs/InputImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ interface ComponentState {
const dragImage = new Image();
dragImage.src = imageDragIcon;

const regexToCheckGridImage: RegExp =
/^https?:\/\/(www\.)?media\.(?:dev-|)guim\.co\.uk\/([0-9a-fA-F]+)\//;

class InputImage extends React.Component<ComponentProps, ComponentState> {
private inputRef = React.createRef<HTMLInputElement>();

Expand Down Expand Up @@ -306,6 +309,10 @@ class InputImage extends React.Component<ComponentProps, ComponentState> {
);
}

const isImgFromGrid = defaultImageUrl
? regexToCheckGridImage.test(defaultImageUrl)
: false;

const hasImage = !useDefault && !!input.value && !!input.value.thumb;
const imageUrl =
!useDefault && input.value && input.value.thumb
Expand Down Expand Up @@ -411,15 +418,17 @@ class InputImage extends React.Component<ComponentProps, ComponentState> {
<AddImageIcon size="l" />
{!!small ? null : <Label size="sm">{message}</Label>}
</AddImageButton>
<AddImageButton
type="button"
onClick={this.openModal(true)}
small={small}
disabled={disabled}
>
<CropIcon size="l" fill={theme.colors.white} />
{!!small ? null : <Label size="sm">Recrop image</Label>}
</AddImageButton>
{isImgFromGrid && (
<AddImageButton
type="button"
onClick={this.openModal(true)}
small={small}
disabled={disabled}
>
<CropIcon size="l" fill={theme.colors.white} />
{!!small ? null : <Label size="sm">Recrop image</Label>}
</AddImageButton>
)}
</AddImageViaGridModalButton>
)}
{hasVideo && useDefault && (
Expand Down