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

user can now delete image in topic separately #9008

Merged
merged 14 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
mzparacha marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pluralizeWithoutNumberPrefix } from 'helpers';
import React, { useState } from 'react';
import React, { useMemo, useState } from 'react';
import Topic, { TopicAttributes } from '../../models/Topic';
import { useCommonNavigate } from '../../navigation/helpers';
import app from '../../state';
Expand Down Expand Up @@ -51,9 +51,18 @@ export const EditTopicModal = ({
featuredInSidebarProp,
);
const [name, setName] = useState<string>(nameProp);
const [image, setImage] = useState<string | null>(null);

const { isAddedToHomeScreen } = useAppStatus();

const markdownImageRegex = useMemo(() => /!\[image\]\((.*?)\)/, []);
Israellund marked this conversation as resolved.
Show resolved Hide resolved

//checks if there is an image in the description to show/delete separately in the modal
useMemo(() => {
Israellund marked this conversation as resolved.
Show resolved Hide resolved
const match = description.match(markdownImageRegex);
setImage(match ? match[1] : null);
}, [description, markdownImageRegex]);

const handleSaveChanges = async () => {
setIsSaving(true);

Expand Down Expand Up @@ -119,6 +128,15 @@ export const EditTopicModal = ({
});
};

function removeImageMarkdown(desc: string): string {
Israellund marked this conversation as resolved.
Show resolved Hide resolved
return desc.replace(markdownImageRegex, '').trim();
}

function onDeleteImageClick() {
Israellund marked this conversation as resolved.
Show resolved Hide resolved
setDescription(removeImageMarkdown(description));
setImage(null);
}

return (
<div className="EditTopicModal">
<CWModalHeader label="Edit topic" onModalClose={onModalClose} />
Expand Down Expand Up @@ -159,6 +177,9 @@ export const EditTopicModal = ({
setDescription(e.target.value);
}}
/>
{image && (
<img src={image} className="topic-image" alt="Image-description" />
)}
<CWCheckbox
label="Featured in Sidebar"
checked={featuredInSidebar}
Expand All @@ -179,6 +200,16 @@ export const EditTopicModal = ({
label="Delete topic"
/>
</div>
{image && (
<div>
<CWButton
buttonType="destructive"
buttonHeight="sm"
label="Remove image"
onClick={() => onDeleteImageClick()}
Israellund marked this conversation as resolved.
Show resolved Hide resolved
/>
</div>
)}
<CWButton
label="Cancel"
buttonType="secondary"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
@import '../shared';

.EditTopicModal {
.topic-image {
max-height: 200px;
height: auto;
width: auto;
max-width: 100%;
}

.EditTopicModalFooter {
display: flex;
flex-direction: column;
Expand Down
Loading