Skip to content

Commit

Permalink
Merge branch 'HITK-TECH-Community:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BHS-Harish authored Aug 4, 2024
2 parents 74914d2 + 33a9c76 commit 320d8ed
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 38 deletions.
15 changes: 8 additions & 7 deletions frontend/src/pages/Broadcast/Component/Carousel/Carousel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ export function Carousel(props) {
const style = {
height: "13em",
backgroundSize: "cover",
backgroundPosition: "center",
backgroundBlendMode: "screen",
clipPath: "polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%)",
backgroundImage: `linear-gradient(45deg,rgba(255, 0, 90, 1) 0%,rgba(10, 24, 61, 1) 90%),url(${item.link})`,
backgroundImage: `linear-gradient(45deg,rgba(255, 0, 90, 1) 0%,
rgba(10, 24, 61, 1) 90%), url(${item.imageUrl[0]})`,
};
return style;
});
Expand All @@ -74,11 +75,11 @@ export function Carousel(props) {
const style = {
height: "13em",
backgroundSize: "cover",
backgroundPosition: "center",
backgroundBlendMode: "screen",
clipPath: "polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%)",
backgroundImage: `linear-gradient(45deg,
#4e4376 0%,
#2b5876 90%),url(${item.link})`,
#2b5876 90%),url(${item.imageUrl[0]})`,
};
return style;
});
Expand Down Expand Up @@ -149,13 +150,13 @@ export function Carousel(props) {
handleOpen(item.content, item.title, item.imageUrl[0], item?.link)
}
>
<div
<div
style={dark ? cardImageArrayDark[i] : cardImageArrayLight[i]}
></div>

<h3 className={style["card-head"]}>{item.title}</h3>
<div className={style["card-text"]}
dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(truncatedContent(item.content, 250)),}} />
dangerouslySetInnerHTML={{__html: DOMPurify.sanitize(truncatedContent(item.content, 170)),}} />
</div>
))}
</OwlCarousel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

.slide-card {
position: relative;
min-height: 31em;
height: 31em;
min-width: 20em;
border-radius: 15px;
margin: 30px;
Expand Down Expand Up @@ -65,7 +65,6 @@
.card-text {
line-height: 1.4;
padding: 1em;
padding-top: 2em;
text-align: justify;
text-justify: distribute-all-lines;
font-size: 14px;
Expand Down
92 changes: 92 additions & 0 deletions frontend/src/pages/Q&A/AnswerModel/AnswerModel.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useState } from "react";
import { Modal, Backdrop, Fade } from '@material-ui/core';
import { SimpleToast } from '../../../components/util/Toast'
import {postAnswer} from '../../../service/Faq'
import style from './AnswerModel.scss'

export function AnswerModel(props) {
const [answer, setAnswer] = useState("")
const [toast, setToast] = useState({
toastStatus: false,
toastType: "",
toastMessage: "",
});
const Tags = [
{ value: "ml" },
{ value: "open-source" },
{ value: "deap-learning" },
{ value: "cp" },
{ value: "block-chain" },
{ value: "mern" },
{ value: "android" },
{ value: "mean" },
{ value: "javascript" },
{ value: "java" },
{ value: "c++" },
{ value: "python" },
];
function handleSubmit(e) {
e.preventDefault()
if(answer!=""){
let data={question_id:props.data._id,answer,created_on:new Date(),created_by:"Anonymous"}
postAnswer(data,setToast)
setAnswer("")
props.handleClose(false)
}else{
setToast({toastStatus:true,toastMessage:"Please enter your answer",toastType:"error"})
}
}
return (
<div>
{toast.toastStatus && (
<SimpleToast
open={toast.toastStatus}
message={toast.toastMessage}
handleCloseToast={()=>{setToast({toastMessage:"",toastStatus:false,toastType:""})}}
severity={toast.toastType}
/>
)}
<Modal
aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description"
className="modal"
open={props.open}
onClose={props.handleClose}
closeAfterTransition
BackdropComponent={Backdrop}
BackdropProps={{
timeout: 500,
}}
>
<Fade in={props.open}>
<div className={"modal-container"}>
<div className="close-icon-container">
<span onClick={() => {
setAnswer("")
props.handleClose(false)
}}>
<i class="fas fa-times close-icon"></i>
</span>
</div>
<h2 className="ques-title">{props.data?.title}</h2>
<p className="ques-description">{props.data?.description}</p>
<div className="tag-container">
{
props && props.data?.tags?.map((tag, index) => {
if (tag)
return (
<p key={index}>#{Tags[index].value}</p>
)
})
}
</div>
<form className="answer-form" onSubmit={handleSubmit}>
<input className="answer-field" onChange={(e) => { setAnswer(e.target.value) }} value={answer} type="text" placeholder="Post your answer" />
<button className="post-answer-btn">Post</button>
</form>
</div>
</Fade>
</Modal>
</div>
)
}
84 changes: 84 additions & 0 deletions frontend/src/pages/Q&A/AnswerModel/AnswerModel.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
:root{
font-family: "Futura LT Book";
}
.modal-container {
width: 70%;
height: auto;
background-color: white;
outline: none !important;
padding: 20px 20px;
border-radius: 12px;
h2{
margin: 0;
}
}

.modal {
display: flex;
position: fixed;
align-items: center;
justify-content: center;
align-items: center;
overflow-y: scroll;
outline: none !important;
}
.close-icon-container{
display: flex;
justify-content: end;
}
.close-icon{
font-size: 24px;
padding-right: 20px;
cursor: pointer;
color:#243e74;
}
.ques-title{
color:#243e74;
}
.ques-description{
font-size: 16px;
margin: 10px auto;
}
.tag-container{
width: 100%;
display: flex;
gap: 8px;
flex-wrap: wrap;
}
.answer-form{
width: 100%;
margin: 14px auto;
display: flex;
justify-content: space-between;
gap: 8px;
}
.answer-field{
width: 85%;
padding: 10px 20px;
outline: none;
border: 1px solid #ccc;
border-radius: 8px;
}
.post-answer-btn{
width: 15%;
padding: 10px 20px;
background-color: #243e74;
border: none;
color: #fff;
border-radius: 8px;
outline: none;
}
@media screen and (max-width:768px) {
.modal-container{
width: 90%;
}
.close-icon{
padding-right: 5px;
}
.answer-field{
width: 70%;
}
.post-answer-btn{
width: 25%;
}
}
1 change: 1 addition & 0 deletions frontend/src/pages/Q&A/AnswerModel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './AnswerModel'
74 changes: 45 additions & 29 deletions frontend/src/pages/Q&A/Q&A.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
downvote,
} from "../../service/Faq";
import { showToast, hideToast } from "../../service/toastService";
import { AnswerModel } from './AnswerModel/index'

function Ques(props) {
let dark = props.theme;
Expand All @@ -36,6 +37,8 @@ function Ques(props) {
const [checkedState, setCheckedState] = useState(
new Array(Tags.length).fill(false)
);
const [open, setOpen] = useState(false)
const [currentQuestion, setCurrentQuestion] = useState({})
const [toast, setToast] = useState({
toastStatus: false,
toastType: "",
Expand All @@ -59,8 +62,17 @@ function Ques(props) {
);

setCheckedState(updatedCheckedState);
formdata.tags.length = 0;
formdata.tags.push(checkedState);

const selectedTags = updatedCheckedState
.map((currentState, index) => {
if (currentState === true) {
return Tags[index].value;
}
return null;
})
.filter((item) => item !== null);

setFormData({ ...formdata, tags: selectedTags });
};

const schema = {
Expand Down Expand Up @@ -122,14 +134,15 @@ function Ques(props) {
}
};

const filterApprovedQuestions = (questions) => {
return questions.filter((question) => question.isApproved == true)
}

const [getQuestions, setQuestions] = useState([]);
const fetchQuestions = () => {
getAllQuestion(setToast).then((data) => {
setLoading(false);
data = data.map((item) => {
return { ...item, tags: item.tags[0] };
});
setQuestions(data);
setLoading(true);
setQuestions(filterApprovedQuestions(data));
});
};

Expand All @@ -144,6 +157,7 @@ function Ques(props) {
};

useEffect(() => {
setLoading(false)
fetchQuestions();
}, []);

Expand All @@ -152,33 +166,32 @@ function Ques(props) {
className="popup-creator"
style={{ background: dark ? "#171717" : "white" }}
>
{getQuestions.length <= 0 ? (
<Loader />
) : (
<div className="question-cards">
{getQuestions?.map((item, key) => {
let tags = [...Object.values(item.tags)];
return (
<AnswerModel theme={dark} open={open} data={currentQuestion} handleClose={setOpen} />
{
!loading ?
<Loader /> :
getQuestions.length == 0 ?
<div>
<h1 className="py-5 text-center">No Questions Found !</h1>
</div>
:
<div className="question-cards">
{getQuestions?.map((item, key) => (
<div className="question-card" key={key}>
<div className="card-up">
<p>{item.title}</p>
<p>{item.description}</p>
<div className="tags-container">
{tags.map((i, index) => {
if (i == true)
return (
<span className="tag-space" key={index}>
{i === true ? `#${Tags[index].value}` : ""}
</span>
);
})}
{item.tags.map((tag, index) => (
<span className="tag-space" key={index}>
#{tag}
</span>
))}
</div>
</div>
<div className="card-down">
<div>
<p>
Created At {new Date(item.createdAt).toLocaleString()}
</p>
<p>Created At {new Date(item.createdAt).toLocaleString()}</p>
</div>
<div>
<button
Expand All @@ -195,12 +208,15 @@ function Ques(props) {
</button>
</div>
</div>
<button className="answer-btn" onClick={() => {
setCurrentQuestion(item)
setOpen(true)
}}>Answers</button>
</div>
);
})}
)
)};
</div>
)}

}
{toast.toastStatus && (
<SimpleToast
open={toast.toastStatus}
Expand Down
Loading

0 comments on commit 320d8ed

Please sign in to comment.