Commit b54bb958 authored by Ekanayake P.M.D.P IT18013610's avatar Ekanayake P.M.D.P IT18013610

Merge branch 'it18013610' into 'master'

similar question finding model connected with the ui

See merge request !12
parents 3b9e6dee 64622521
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
pre { pre {
padding: 20px; padding: 20px;
background-color: var(black); background-color: var(black);
font-size: 16px;
font-family: 'Roboto Mono', monospace !important; font-family: 'Roboto Mono', monospace !important;
max-width: 780px; max-width: 780px;
} }
......
...@@ -5,8 +5,10 @@ const NoResource = ({ source, message }) => { ...@@ -5,8 +5,10 @@ const NoResource = ({ source, message }) => {
return ( return (
<div className={Styles.noresource}> <div className={Styles.noresource}>
<h1> <h1>
No resources found from <b>{source}</b> for this question. Please refer {message
the extra resouces section to find more info. ? message
: `No resources found from ${source} for this question. Please refer
the extra resouces section to find more info.`}
</h1> </h1>
</div> </div>
) )
......
...@@ -4,55 +4,57 @@ import { Title } from '../styled-text-spans/index' ...@@ -4,55 +4,57 @@ import { Title } from '../styled-text-spans/index'
import styles from './similar-question-suggestions.module.css' import styles from './similar-question-suggestions.module.css'
import useDebounce from '../../hooks/useDebounce' import useDebounce from '../../hooks/useDebounce'
import { Spinner } from '../icons' import { Spinner } from '../icons'
import Axios from 'axios'
import NoResource from '../no-resource/NoResource'
const SimilarQuestionSuggestions = ({ title, description, tags }) => { const SimilarQuestionSuggestions = ({ title, description, tags }) => {
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const [similarQuestions, setSimilarQuestions] = useState([])
const [similarQuestions, setSimilarQuestions] = useState([ const [error, setError] = useState({
{ isError: false,
url: 'https://dasunx.com', message: ''
title: 'How to center a div element vertically', })
author: { const getSimilarQuestions = async () => {
username: 'dasunx', console.log('getSimilarQuestions')
profilePhoto: const data = { question: title }
'https://secure.gravatar.com/avatar/608a987a8401796f68c4d11f?s=90&d=monsterid' const headers = {
}, 'Content-Type': 'application/json',
views: 240, 'Access-Control-Allow-Origin': '*'
comments: 12 }
}, try {
{ const response = await Axios.post(
url: 'https://dasunx.com', 'https://localhost:3002/',
title: data,
"I can center it horizontally, but the thing is I don't know how to center it vertically.I can center it horizontally, but the thing is I don't know how to center it vertically.", headers
author: { )
username: 'dasunx', if (response.status === 200) {
profilePhoto: setSimilarQuestions(response.data)
'https://secure.gravatar.com/avatar/608a987a8401796f68c4d11f?s=90&d=monsterid' } else {
}, setError({
views: 20, isError: true,
comments: 1 message:
}, 'Something went wrong while searching similar questions. Please try again'
{ })
url: 'https://dasunx.com', }
title: 'Test question 3', } catch (err) {
author: { console.log(err)
username: 'dasunx', setError({
profilePhoto: isError: true,
'https://secure.gravatar.com/avatar/608a987a8401796f68c4d11f?s=90&d=monsterid' message:
}, 'Similar question finding is not supported in this environment yet. Hopefully it will be available soon.'
views: 40, })
comments: 6
} }
]) setIsLoading(false)
}
useDebounce( useDebounce(
() => { async () => {
setIsLoading(false) await getSimilarQuestions()
}, },
1000, 1000,
[title] [title]
) )
const { isError, message } = error
return ( return (
<div className={styles.container}> <div className={styles.container}>
<h1> <h1>
...@@ -61,10 +63,14 @@ const SimilarQuestionSuggestions = ({ title, description, tags }) => { ...@@ -61,10 +63,14 @@ const SimilarQuestionSuggestions = ({ title, description, tags }) => {
</h1> </h1>
{isLoading ? ( {isLoading ? (
<Spinner className={styles.spinner} /> <Spinner className={styles.spinner} />
) : ( ) : isError ? (
<NoResource message={message} />
) : similarQuestions.length > 0 ? (
similarQuestions.map((question, index) => { similarQuestions.map((question, index) => {
return <SimilarQuestion question={question} key={index} /> return <SimilarQuestion question_prop={question} key={index} />
}) })
) : (
<NoResource message="No similar questions found for this question. Submit your question to get an answer generated in few seconds" />
)} )}
</div> </div>
) )
......
...@@ -3,28 +3,25 @@ import React from 'react' ...@@ -3,28 +3,25 @@ import React from 'react'
import { Bold, Title } from '../../styled-text-spans/index' import { Bold, Title } from '../../styled-text-spans/index'
import styles from './similar-question.module.css' import styles from './similar-question.module.css'
const SimilarQuestion = ({ question }) => { const SimilarQuestion = ({ question_prop }) => {
const { title, author, url, views, comments } = question const { id, question, description } = question_prop
return ( return (
<Link <Link href="/questions/[slug]" as={`/questions/${id}-${question}`}>
href="/questions/[slug]"
as={`/questions/6087be20b0c06a179059dfa8-how-to-center-a-div-element-vertically`}
>
<div className={styles.similarquestion}> <div className={styles.similarquestion}>
<Link href="/users/[user]" as={`/users/${author.username}`}> <Link href="/users/[user]" as={`/users/dasun97`}>
<div className={styles.userwrapper}> <div className={styles.userwrapper}>
<img <img
className={styles.profilephoto} className={styles.profilephoto}
src={author.profilePhoto} src="https://www.practiceportuguese.com/wp-content/uploads/2020/06/asking-questions.jpg"
alt={author.username} alt="dasun97"
/> />
<Bold text={`@${author.username}`} /> <Bold text={`@dasun97`} />
</div> </div>
</Link> </Link>
<div className={styles.questionwrapper}> <div className={styles.questionwrapper}>
<Title title={title} /> <Title title={question} />
<div> <div>
<Bold text={views} /> Views and <Bold text={comments} /> <Bold text={123} /> Views and <Bold text={2} />
Comments Comments
</div> </div>
</div> </div>
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
display: flex; display: flex;
flex-direction: row; flex-direction: row;
border-radius: 5px; border-radius: 5px;
cursor: pointer;
} }
.userwrapper { .userwrapper {
display: flex; display: flex;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment