Skip to content

Commit

Permalink
devonfw-forge#41: fixed bugs + cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahffm committed Dec 29, 2022
1 parent 63fd8a0 commit 89c9c98
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {

const [doVote, setDoVote] = useState<boolean>(true);

const task = findOpenTask();
const evaluatedTaskExists = findEvaluatedTask();
let averageComplexity = findEvaluatedTask()?.result?.complexityAverage;
const openTask = findOpenTask();
const evaluatedTask = findEvaluatedTask();
const averageComplexity = findEvaluatedTask()?.result?.complexityAverage;

let alreadyVoted = false;

if (task) {
alreadyVoted = userAlreadyVoted(userId as string, task.id);
if (openTask) {
alreadyVoted = userAlreadyVoted(userId as string, openTask.id);
}

useEffect(() => {
Expand Down Expand Up @@ -79,7 +79,7 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
const submitFinalResultToRestApi = async () => {
const evaluatedTask = findEvaluatedTask();

if (evaluatedTask) {
if (evaluatedTask && evaluatedTask.result !== undefined) {
let res = { amountOfVotes: 0, complexityAverage: averageComplexity, finalValue: evaluatedTask.result.finalValue };

const url = baseUrl + serviceUrl + id + "/task/status";
Expand Down Expand Up @@ -113,10 +113,10 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
const user = "me";

const renderVoting = () => {
if (task) {
if (openTask) {
if (doVote) {
return (
renderEstimationForTask(task)
renderEstimationForTask(openTask)
)
}
else {
Expand All @@ -125,7 +125,7 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
)
}
}
else if (evaluatedTaskExists) {
else if (evaluatedTask) {
return (
renderComplexityAverageAndFinalValueChoice()
)
Expand All @@ -144,9 +144,9 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
&apos;{findEvaluatedTask()?.title}&apos;: &nbsp;
</>
<strong>
{averageComplexity}
{`${averageComplexity}`}
</strong>
{role === Role.Admin ? renderFinalValueChoice(task) : <></>}
{(role === Role.Admin && evaluatedTask) ? renderFinalValueChoice(evaluatedTask) : <></>}
</div>
);

Expand Down Expand Up @@ -175,6 +175,7 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
// @ts-ignore
type={EstimationType[type] as EstimationType}
isFinal={false}
taskId={task.id}
/>
</div>
))}
Expand Down Expand Up @@ -217,6 +218,7 @@ export const Estimation: FunctionComponent<EstimationProps> = ({ id }) => {
// @ts-ignore
type={EstimationType["Complexity"] as EstimationType}
isFinal={true}
taskId={task.id}
/>
</div>
<div className="flex justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { EstimationValue } from "./EstimationButton";
import { useEstimationStore } from "../Stores/EstimationStore";
import { EstimationType } from "../../../../../Types/EstimationType";

export const EstimationBar: FunctionComponent<{ type: EstimationType; isFinal: boolean }> = ({
type, isFinal
export const EstimationBar: FunctionComponent<{ type: EstimationType; isFinal: boolean; taskId: String; }> = ({
type, isFinal, taskId
}) => {
const state = useEstimationStore();

Expand All @@ -29,6 +29,7 @@ export const EstimationBar: FunctionComponent<{ type: EstimationType; isFinal: b
isActive={item == state[type] ? true : false}
parentType={type}
isFinal={isFinal}
taskId={taskId}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export const EstimationValue: FunctionComponent<{
isActive: boolean;
parentType: EstimationType;
isFinal: boolean;
}> = ({ value, gridColumn, isActive, parentType, isFinal }) => {
taskId: String;
}> = ({ value, gridColumn, isActive, parentType, isFinal, taskId }) => {
const { setValue } = useEstimationStore();
const { setFinalComplexity } = useTaskStore();

Expand All @@ -30,7 +31,7 @@ export const EstimationValue: FunctionComponent<{
}}
onClick={() => {
if (isFinal) {
setFinalComplexity(value);
setFinalComplexity(taskId, value);
}
setValue(parentType, value);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ export const TaskCard: FunctionComponent<{
url?: String;
description?: String;
status: Status;
complexityAverage?: Number;
finalValue?: Number;
}> = ({ id, parentSession, title, url, description, status, complexityAverage, finalValue }) => {
}> = ({ id, parentSession, title, url, description, status, finalValue }) => {
const { isAdmin, userId, token } = useAuthStore();
const authHeaders = {
Accept: "application/json",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const TaskView: FunctionComponent<TaskViewProps> = ({ id }) => {
title={item.title}
description={item.description}
url={item.url}
complexityAverage={item.result?.complexityAverage}
finalValue={item.result?.finalValue}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface ISessionTaskState {
findOpenTask: () => ITask | undefined;
upsertEstimationToTask: (estimation: IEstimationDto) => void;
setAverageComplexity: (taskResultDto: ITaskResultDto) => void;
setFinalComplexity: (finalValue: number) => void;
setFinalComplexity: (taskId: String, finalValue: number) => void;
findEvaluatedTask: () => ITask | undefined;
}

Expand Down Expand Up @@ -125,11 +125,11 @@ export const useTaskStore = create<ISessionTaskState>()((set, get) => ({
})
);
},
setFinalComplexity: (finalValue: Number) => {
setFinalComplexity: (taskId: String, finalValue: number) => {
set(
produce((draft: ISessionTaskState) => {
draft.tasks.forEach((task) => {
if (task.status == Status.Evaluated) {
if (task.id === taskId && task.result !== undefined) {
task.result.finalValue = finalValue;
}
});
Expand Down
13 changes: 9 additions & 4 deletions client/pages/session/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function Session({ id, tasks, users, auth, inviteToken }: any) {
setCurrentUsers(users);
const { role, username, userId, token } = auth;
login(username, token, userId, role);
}, [auth, tasks, users]);
}, [auth, tasks, users, login, setCurrentTasks, setCurrentUsers]);

// process onUserConnect, onAnotherUserConnect, markTaskAsActive,
const processMessage = (message: IWebSocketMessage) => {
Expand Down Expand Up @@ -83,20 +83,25 @@ export default function Session({ id, tasks, users, auth, inviteToken }: any) {
console.log("TaskAverageAdded received.");

setAverageComplexity(payload);
break;
}
case Type.TaskFinalValueAdded: {
let { payload } = parsed as IMessage<ITaskResultDto>;
console.log("TaskFinalValueAdded received.");
console.log(payload);
console.log("TaskFinalValueAdded received: " + payload.finalValue);

if (payload.finalValue !== undefined) {
setFinalComplexity(payload.id, payload.finalValue.valueOf());
}

setFinalComplexity(payload.finalValue);
break;
}
case Type.UserJoined: {
let { payload } = parsed as IMessage<IUser>;

console.log(payload);

addUser(payload);
break;
}
default: {
break;
Expand Down

0 comments on commit 89c9c98

Please sign in to comment.