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

Embed external images in Moments and Strategies editor #2205

Merged
merged 5 commits into from
Dec 8, 2022
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
6 changes: 6 additions & 0 deletions app/assets/stylesheets/core/containers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
width: 100%;
margin: 0;
}

.imageContainer {
img {
max-width: 100%;
}
}
2 changes: 1 addition & 1 deletion app/views/moments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>

<% if @moment.why.present? %>
<div class="smallMarginTop">
<div class="smallMarginTop imageContainer">
<% if @moment.fix.present? %>
<div class="label">
<%= label_tag t('moments.form.why_legacy') %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/strategies/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</div>

<% if @strategy.description.present? %>
<div class="smallMarginTop">
<div class="smallMarginTop imageContainer">
<%= sanitize(@strategy.description) %>
</div>
<% end %>
Expand Down
11 changes: 10 additions & 1 deletion client/app/components/Input/InputTextarea.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { sanitize } from 'dompurify';
import ReactDOMServer from 'react-dom/server';
import { init, exec } from 'pell';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faLink } from '@fortawesome/free-solid-svg-icons';
import { faImage, faLink } from '@fortawesome/free-solid-svg-icons';
import css from './InputTextarea.scss';
import inputCss from './Input.scss';

Expand All @@ -16,6 +16,11 @@ const handleResult = (type: string) => {
if (url) exec('createLink', url);
break;
}
case 'image': {
const src = window.prompt('Please provide a link to your image.');
if (src) exec('insertImage', src);
break;
}
case 'olist':
exec('insertOrderedList');
break;
Expand Down Expand Up @@ -45,6 +50,10 @@ const actions = [
...action('link'),
icon: ReactDOMServer.renderToString(<FontAwesomeIcon icon={faLink} />),
},
{
...action('image'),
icon: ReactDOMServer.renderToString(<FontAwesomeIcon icon={faImage} />),
},
];

const classes = {
Expand Down
4 changes: 4 additions & 0 deletions client/app/components/Input/InputTextarea.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
p {
margin: $size-0;
}

img {
max-width: 100%;
}
}

.dark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ describe('InputTextarea', () => {
{ title: 'Bold', expectedArgs: ['bold'] },
// overridden actions
{ title: 'Link', expectedArgs: ['createLink', sampleUrl] },
{ title: 'Image', expectedArgs: ['insertImage', sampleUrl] },
{ title: 'Ordered List', expectedArgs: ['insertOrderedList'] },
{ title: 'Unordered List', expectedArgs: ['insertUnorderedList'] },
];
Expand Down