Skip to content

Commit

Permalink
impl. function to show cloesd tasks ratings + accept finalValue from …
Browse files Browse the repository at this point in the history
…sockets
  • Loading branch information
dkars2s committed Dec 20, 2022
1 parent f747e7c commit 5714a7f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from "axios";
import { FunctionComponent } from "react";
import { FunctionComponent, useState } from "react";
import {
Status,
convertStatusToNumber,
Expand All @@ -10,6 +10,7 @@ import {
import { useTaskStore } from "../Stores/TaskStore";
import { baseUrl, serviceUrl } from "../../../../../Constants/url";


export const TaskCard: FunctionComponent<{
id: String;
parentSession: String;
Expand Down Expand Up @@ -80,8 +81,14 @@ export const TaskCard: FunctionComponent<{
</button>
);
case Status.Ended:

return (

renderFinalValueOnClosedTasks()

);
default:
return <></>;
return <></>
}
})()}
<button
Expand All @@ -94,6 +101,28 @@ export const TaskCard: FunctionComponent<{
);
};

const colorStyle = {
color: '#2ADF6C',
fontWeight: 'bold',
};

/*
function UseUpdateFinalValue() {
const [value, setValue] = useState(0);
return () => setValue(value => value + 1)
}
const forceUpdate = UseUpdateFinalValue()
*/

const renderFinalValueOnClosedTasks = () => (
<>
<div style= {colorStyle} >
Rated: {finalValue}
</div>
</>
);

return (
<>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const useTaskStore = create<ISessionTaskState>()((set, get) => ({
})
);
},
//sets average complexity of the open task & changes it to evaluated
//sets the averageComplexity value for each task
setAverageComplexity: (taskResultDto: ITaskResultDto) => {
set(
produce((draft: ISessionTaskState) => {
Expand All @@ -128,9 +128,11 @@ export const useTaskStore = create<ISessionTaskState>()((set, get) => ({
setFinalComplexity: (finalValue: Number) => {
set(
produce((draft: ISessionTaskState) => {
const evaluatedTask = get().tasks.find((task) => task.status == Status.Evaluated);
draft.tasks.forEach((task) => {
if (task.status == Status.Evaluated) {
if (task.id == evaluatedTask.id) {
task.finalValue = finalValue;
console.log("finalValue updated: " + task.finalValue);
}
});
})
Expand All @@ -139,7 +141,8 @@ export const useTaskStore = create<ISessionTaskState>()((set, get) => ({
//returns the task thats currently in evaluation
findEvaluatedTask: () => {
return get().tasks.find((task) => task.status == Status.Evaluated);
}
},

}));

const sortTasks = (tasks: ITask[]) => {
Expand Down
13 changes: 11 additions & 2 deletions client/pages/session/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@ import { dummyUsers } from "../../app/Components/Globals/DummyData";
import { IEstimationDto } from "../../app/Interfaces/IEstimationDto";
import { ITaskResultDto } from "../../app/Interfaces/ITaskResultDto";



export default function Session({ id, data }: any) {
const { setCurrentTasks } = useTaskStore();
const { setCurrentUsers } = useSessionUserStore();



useEffect(() => {
const { tasks } = data;

setCurrentTasks(tasks);
setCurrentUsers(dummyUsers);

}, [data, dummyUsers]);

// process onUserConnect, onAnotherUserConnect, markTaskAsActive,
Expand Down Expand Up @@ -79,6 +83,11 @@ export default function Session({ id, data }: any) {
let { payload } = parsed as IMessage<ITaskResultDto>;
console.log("TaskFinalValueAdded received.");
console.log(payload);
console.log(" finalval von PAYLOAD ***" + payload.finalValue);

let final = payload.finalValue;
console.log(" finalval von final ***" + final);
setFinalComplexity(final);
// TODO
}
default: {
Expand All @@ -87,7 +96,7 @@ export default function Session({ id, data }: any) {
}
};

const { upsertTask, changeStatusOfTask, deleteTask, upsertEstimationToTask, setAverageComplexity } =
const { upsertTask, changeStatusOfTask, deleteTask, upsertEstimationToTask, setAverageComplexity, setFinalComplexity } =
useTaskStore();

const { sendMessage, getWebSocket } = useWebSocket(
Expand Down

0 comments on commit 5714a7f

Please sign in to comment.