Skip to content

Commit

Permalink
implement redux functionality and update the "predict" page UI
Browse files Browse the repository at this point in the history
  • Loading branch information
chandima2000 committed Aug 15, 2024
1 parent 4e468b0 commit 9a6f9de
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 69 deletions.
6 changes: 6 additions & 0 deletions Frontend/app/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { configureStore } from '@reduxjs/toolkit'
import feedbackReducer from '../features/feedback/feedbackSlice'

export const store = configureStore({
reducer: feedbackReducer,
})
21 changes: 21 additions & 0 deletions Frontend/features/feedback/feedbackSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { createSlice} from '@reduxjs/toolkit'

// Initial state
const initialState = {
feedbacks: '',
}

export const feedbackSlice = createSlice({
name: 'feedback',
initialState,
reducers: {
feedbackState:(state,action) => {
state.feedbacks = action.payload;
}
}
})


export const {feedbackState} = feedbackSlice.actions;

export default feedbackSlice.reducer;
86 changes: 86 additions & 0 deletions Frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"@material-tailwind/react": "^2.1.9",
"@react-three/drei": "^9.105.6",
"@react-three/fiber": "^8.16.5",
"@reduxjs/toolkit": "^2.2.7",
"@types/regenerator-runtime": "^0.13.6",
"framer-motion": "^11.1.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.2.1",
"react-redux": "^9.1.2",
"react-router-dom": "^6.23.0",
"react-speech-recognition": "^3.10.0",
"react-type-animation": "^3.2.0",
Expand Down
Binary file removed Frontend/public/robot2.jpeg
Binary file not shown.
Binary file removed Frontend/public/robot3.jpeg
Binary file not shown.
51 changes: 40 additions & 11 deletions Frontend/src/components/feedbackForm/Feedback.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React, { useState } from "react";
import { useState } from "react";
import { useDispatch } from "react-redux";
import { feedbackState } from "../../features/feedback/feedbackSlice";
import { TypeAnimation } from "react-type-animation";

const FeedbackForm = () => {
const [feedback, setFeedback] = useState("");
const [sentiment, setSentiment] = useState(null);
const dispatch = useDispatch();

const handleSubmit = async (event) => {
event.preventDefault();
Expand All @@ -13,9 +17,12 @@ const FeedbackForm = () => {
},
body: JSON.stringify({ text: feedback }),
});

const data = await response.json();
console.log(data);

setSentiment(data.prediction);

dispatch(feedbackState(sentiment));
};

return (
Expand All @@ -39,16 +46,38 @@ const FeedbackForm = () => {
</div>

{sentiment == 1 ? (
<p className="mt-4 text-center font-semibold text-2xl">
It seems like you are satisfied with the prediction. <br /> If you
want more clarifications?<br/> Please get help from our personal Assistants.
</p>
) : sentiment == 0 ? (
<div>
<TypeAnimation
sequence={[
"It seems like you are satisfied with the prediction.If you want more clarifications? Please get help from our personal Assistants.",
]}
speed={50}
repeat={0}
className="mt-4 text-center font-semibold text-2xl bg-slate-500"
style={{
height: 'auto',
width: '700px',
display: 'block',

}}
/>
</div>
) :
sentiment == 0 ? (
<div className="items-center">
<p className="mt-4 text-center font-semibold text-2xl">
It seems like you are not satisfied with the prediction. <br/>Plz Get
help from our personal Assistants.
</p>
<TypeAnimation
sequence={[
"It seems like you are not satisfied with the prediction.Plz Get help from our personal Assistants.",
]}
speed={50}
repeat={0}
className="mt-4 text-center font-semibold text-2xl bg-slate-500"
style={{
height: 'auto',
width: '700px',
display: 'block',
}}
/>
</div>
) : (
<div></div>
Expand Down
Loading

0 comments on commit 9a6f9de

Please sign in to comment.