Skip to content

Commit

Permalink
feat: added endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
PauliusPreiksaCode committed May 27, 2024
1 parent 1490bc9 commit ce3c5e9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 20 deletions.
49 changes: 29 additions & 20 deletions GUI/front-end/src/components/displays/chat/ChatDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ChatInstance from './ChatInstance';
import { AccountCircle as AccountCircleIcon } from '@mui/icons-material';
import { useApplicationContext } from '../../../contexts';
import { KathLogo } from '../../svgs';
import { useSendRequest } from '../../../hooks';

interface Props {}

Expand All @@ -13,37 +14,45 @@ export const ChatDisplay: React.FC<Props> = () => {
const [isInputDisabled, setIsInputDisabled] = React.useState(false);

const applicationContext = useApplicationContext();
const sendRequest = useSendRequest();

// Array of mock-up texts
const mockUpTexts = [
'Gene frequencies can change over time due to natural selection, mutation, genetic drift, and gene flow.',
'The BRCA1 gene, linked to breast cancer, is a subject of extensive research.',
'Genome-wide association studies (GWAS) have identified numerous genetic variants associated with complex diseases.',
'In the field of genetics, the concept of gene frequency is of paramount importance. It refers to the frequency with which a particular gene variant occurs in a population. This frequency can change over time due to various evolutionary forces such as natural selection, mutation, genetic drift, and gene flow. For instance, if a gene variant confers a survival advantage, its frequency may increase in the population over generations due to natural selection.',
'One of the most researched genes in human genetics is the BRCA1 gene. This gene produces a protein that helps suppress the growth of tumors. Mutations in the BRCA1 gene can lead to a significantly increased risk for breast and ovarian cancer. Researchers are continually studying this gene to understand its function better and develop effective therapies for individuals carrying BRCA1 mutations.',
'Genome-wide association studies (GWAS) have revolutionized our understanding of the genetic basis of complex diseases. These studies involve scanning the genomes of thousands of individuals to identify genetic variants associated with a particular disease. For example, GWAS have identified numerous genetic variants associated with diseases such as diabetes, heart disease, and various forms of cancer. However, most of these variants only slightly increase the risk of disease, indicating that these diseases are influenced by a combination of genetic, environmental, and lifestyle factors.',
'The study of gene frequencies, also known as population genetics, is a fascinating and complex field that seeks to understand how genetic variation occurs within and between populations. This field of study is critical for understanding evolution, genetic diseases, and biodiversity. Gene frequencies can change over time due to several factors, including natural selection, mutation, genetic drift, and gene flow. Natural selection is the process by which certain traits become more or less common in a population based on the survival and reproductive success of individuals with those traits. Mutations, which are changes in the DNA sequence, can introduce new genetic variants into a population. Genetic drift is a random process that can cause gene frequencies to change from one generation to the next, particularly in small populations. Gene flow, which is the transfer of genetic variation from one population to another, can also affect gene frequencies.\n\nOne area of intense research in human genetics is the study of specific genes associated with diseases. For example, the BRCA1 and BRCA2 genes are known to be associated with a higher risk of breast and ovarian cancer. These genes produce proteins that help repair damaged DNA, and when these genes are mutated, the DNA repair process may not function correctly, leading to the development of cancer. Extensive research is being conducted to better understand these genes and develop effective therapies for individuals carrying these mutations.\n\nAnother important area of research is genome-wide association studies (GWAS), which aim to identify genetic variants associated with specific diseases. These studies involve scanning the genomes of thousands of individuals to identify genetic variants that are more common in individuals with a particular disease compared to healthy individuals. GWAS have identified numerous genetic variants associated with a wide range of diseases, including diabetes, heart disease, and various forms of cancer. However, most of these variants only slightly increase the risk of disease, indicating that these diseases are influenced by a combination of genetic, environmental, and lifestyle factors.Despite the significant advances in our understanding of human genetics, there is still much to learn. For example, many of the genetic variants identified by GWAS explain only a small fraction of the heritability of complex diseases, suggesting that there are likely many more genetic variants to be discovered. Furthermore, the role of rare genetic variants, which are not well captured by GWAS, is an area of active research. There is also increasing interest in understanding the role of non-coding regions of the genome, which do not code for proteins but may play important roles in regulating gene expression. As our understanding of human genetics continues to evolve, it is clear that this field of research will continue to provide important insights into human health and disease.\n\nPlease note that this is a simplified explanation and the actual research in genetics is much more complex and nuanced. For accurate and up-to-date information, please refer to scientific literature or consult a genetics professional.',
];
// const mockUpTexts = [
// 'Gene frequencies can change over time due to natural selection, mutation, genetic drift, and gene flow.',
// 'The BRCA1 gene, linked to breast cancer, is a subject of extensive research.',
// 'Genome-wide association studies (GWAS) have identified numerous genetic variants associated with complex diseases.',
// 'In the field of genetics, the concept of gene frequency is of paramount importance. It refers to the frequency with which a particular gene variant occurs in a population. This frequency can change over time due to various evolutionary forces such as natural selection, mutation, genetic drift, and gene flow. For instance, if a gene variant confers a survival advantage, its frequency may increase in the population over generations due to natural selection.',
// 'One of the most researched genes in human genetics is the BRCA1 gene. This gene produces a protein that helps suppress the growth of tumors. Mutations in the BRCA1 gene can lead to a significantly increased risk for breast and ovarian cancer. Researchers are continually studying this gene to understand its function better and develop effective therapies for individuals carrying BRCA1 mutations.',
// 'Genome-wide association studies (GWAS) have revolutionized our understanding of the genetic basis of complex diseases. These studies involve scanning the genomes of thousands of individuals to identify genetic variants associated with a particular disease. For example, GWAS have identified numerous genetic variants associated with diseases such as diabetes, heart disease, and various forms of cancer. However, most of these variants only slightly increase the risk of disease, indicating that these diseases are influenced by a combination of genetic, environmental, and lifestyle factors.',
// 'The study of gene frequencies, also known as population genetics, is a fascinating and complex field that seeks to understand how genetic variation occurs within and between populations. This field of study is critical for understanding evolution, genetic diseases, and biodiversity. Gene frequencies can change over time due to several factors, including natural selection, mutation, genetic drift, and gene flow. Natural selection is the process by which certain traits become more or less common in a population based on the survival and reproductive success of individuals with those traits. Mutations, which are changes in the DNA sequence, can introduce new genetic variants into a population. Genetic drift is a random process that can cause gene frequencies to change from one generation to the next, particularly in small populations. Gene flow, which is the transfer of genetic variation from one population to another, can also affect gene frequencies.\n\nOne area of intense research in human genetics is the study of specific genes associated with diseases. For example, the BRCA1 and BRCA2 genes are known to be associated with a higher risk of breast and ovarian cancer. These genes produce proteins that help repair damaged DNA, and when these genes are mutated, the DNA repair process may not function correctly, leading to the development of cancer. Extensive research is being conducted to better understand these genes and develop effective therapies for individuals carrying these mutations.\n\nAnother important area of research is genome-wide association studies (GWAS), which aim to identify genetic variants associated with specific diseases. These studies involve scanning the genomes of thousands of individuals to identify genetic variants that are more common in individuals with a particular disease compared to healthy individuals. GWAS have identified numerous genetic variants associated with a wide range of diseases, including diabetes, heart disease, and various forms of cancer. However, most of these variants only slightly increase the risk of disease, indicating that these diseases are influenced by a combination of genetic, environmental, and lifestyle factors.Despite the significant advances in our understanding of human genetics, there is still much to learn. For example, many of the genetic variants identified by GWAS explain only a small fraction of the heritability of complex diseases, suggesting that there are likely many more genetic variants to be discovered. Furthermore, the role of rare genetic variants, which are not well captured by GWAS, is an area of active research. There is also increasing interest in understanding the role of non-coding regions of the genome, which do not code for proteins but may play important roles in regulating gene expression. As our understanding of human genetics continues to evolve, it is clear that this field of research will continue to provide important insights into human health and disease.\n\nPlease note that this is a simplified explanation and the actual research in genetics is much more complex and nuanced. For accurate and up-to-date information, please refer to scientific literature or consult a genetics professional.',
// ];
/////////////////////////

const handleSubmit = (content: string) => {
const handleSubmit = async (content: string) => {
setIsInputDisabled(true);
setChatInstances((prevInstances) => [
...prevInstances,
<ChatInstance icon={<AccountCircleIcon />} author='User' content={content} />,
]);

const responseResult = await sendRequest.mutateAsync(content);

setChatInstances((prevInstances) => [
...prevInstances,
<ChatInstance icon={<KathLogo />} author={applicationContext.name} content={responseResult} />,
]);

// Temporary mock up response
setTimeout(() => {
const randomIndex = Math.floor(Math.random() * mockUpTexts.length);
const randomMockUpText = mockUpTexts[randomIndex];

setChatInstances((prevInstances) => [
...prevInstances,
<ChatInstance icon={<KathLogo />} author={applicationContext.name} content={randomMockUpText} />,
]);
setIsInputDisabled(false);
}, 1000);
// setTimeout(() => {
// const randomIndex = Math.floor(Math.random() * mockUpTexts.length);
// const randomMockUpText = mockUpTexts[randomIndex];

// setChatInstances((prevInstances) => [
// ...prevInstances,
// <ChatInstance icon={<KathLogo />} author={applicationContext.name} content={randomMockUpText} />,
// ]);
// setIsInputDisabled(false);
// }, 1000);
///////////////////////////////////////
};

Expand Down
1 change: 1 addition & 0 deletions GUI/front-end/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { useGetUsers } from './user/userHook';
export { useSendRequest } from './request/requestHook';
13 changes: 13 additions & 0 deletions GUI/front-end/src/hooks/request/requestHook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useMutation, useQueryClient } from "@tanstack/react-query"
import { sendRequest } from "../../services";

export const useSendRequest = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: sendRequest,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['request']});
},
});
};
1 change: 1 addition & 0 deletions GUI/front-end/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { getUsers } from './user/userService';
export { sendRequest } from './request/requestService';
12 changes: 12 additions & 0 deletions GUI/front-end/src/services/request/requestService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ENDPOINTS } from "../../types/constants";
import httpClient from "../httpClient";


export async function sendRequest(request: string) {
return await httpClient
.post(ENDPOINTS.REQUEST, request)
.then((res) => res.data)
.catch((err) => {
console.error(err);
});
}
1 change: 1 addition & 0 deletions GUI/front-end/src/types/constants/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
export const ENDPOINTS = {
USERS: `/users`,
PROFILES: `/profiles`,
REQUEST: '/request',
};

0 comments on commit ce3c5e9

Please sign in to comment.