Skip to content

Commit

Permalink
Fixed: Bugs In Broadcasts
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamgaur99 committed Jul 28, 2024
1 parent 0a946e5 commit f7dac7b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions backend/app/routes/broadcast/getBroadcasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const getBroadcastsAggregate = (startIndex, match) => {
expiresOn: 1,
createdAt: 1,
updatedAt: 1,
isApproved: 1,
year: { $year: '$createdAt' },
month: { $month: '$createdAt' },
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ export function Card(props) {
const sanitizedContent = DOMPurify.sanitize(props.project.content);

const truncatedContent =
sanitizedContent.length > 400
? sanitizedContent.substring(0, 400) + "..."
sanitizedContent.length > 250
? sanitizedContent.substring(0, 250) + "..."
: sanitizedContent;

return (
Expand Down Expand Up @@ -167,17 +167,16 @@ export function Card(props) {
>
View Details
</button>

<div className={style["button-group"]}>
<button
className={
!props?.project?.isApproved
? style["button-approve"]
: style["button-info"]
}
onClick={!props?.project?.isApproved && handleApprove}
>
{props?.project?.isApproved ? "Approved" : "Approve"}
</button>
{!props?.project?.isApproved && (
<button
className={style["button-approve"]}
onClick={handleApprove}
>
Approve
</button>
)}
<button
className={style["button-delete"]}
onClick={() => deleteCard(props.id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
text-align: center;
font-size: 1.2rem;
width: 100%;
word-wrap: break-word;
}

.card-item-light:hover {
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/pages/Broadcast/Component/Carousel/Carousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { Modals } from "./Modal/index.js";
import Loader from "../../../../components/util/Loader";
import { boardcast } from "../../../../service/Broadcast.jsx";
import { SimpleToast } from "../../../../components/util/Toast/Toast.jsx";
import DOMPurify from "dompurify";

export function Carousel(props) {
const head = props.head;
let dark = props.theme;
Expand Down Expand Up @@ -87,7 +89,8 @@ export function Carousel(props) {
const getData = async () => {
setLoaded(false);
const result = await boardcast(setToast,toast)
setDataa(result);
const approvedBroadcasts = result.filter(broadcast => broadcast.isApproved);
setDataa(approvedBroadcasts);
setLoaded(true);
}
const handleCloseToast = (event,reason) => {
Expand All @@ -96,6 +99,14 @@ export function Carousel(props) {
}
setToast({ ...toast, toastStatus: false });
};

const truncatedContent = (content, maxLength) => {
if (content.length > maxLength) {
return content.substring(0, maxLength) + '...';
}
return content;
};

return !isLoaded ? (
<Loader />
) : (
Expand Down Expand Up @@ -143,7 +154,8 @@ export function Carousel(props) {
></div>

<h3 className={style["card-head"]}>{item.title}</h3>
<div className={style["card-text"]} dangerouslySetInnerHTML={{__html: item.content}} />
<div className={style["card-text"]}
dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(truncatedContent(item.content, 250)),}} />
</div>
))}
</OwlCarousel>
Expand Down

0 comments on commit f7dac7b

Please sign in to comment.