Skip to content

Commit

Permalink
show mentor's answer (#101)
Browse files Browse the repository at this point in the history
* show mentor's answer

* double licence removed from history.spec.ts
  • Loading branch information
DilanRamirez authored Oct 6, 2021
1 parent f3c3632 commit fc51965
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 43 deletions.
16 changes: 13 additions & 3 deletions client/src/components/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
faveMentor,
mentorAnswerPlaybackStarted,
playIdleAfterReplay,
onVideoFinished,
onMentorDisplayAnswer,
} from "store/actions";
import { State, WebLink } from "types";
import "styles/video.css";
Expand All @@ -33,6 +33,9 @@ export interface VideoData {
function Video(args: { playing?: boolean }): JSX.Element {
const { playing = false } = args;
const dispatch = useDispatch();
const numberMentors = useSelector<State, number>((state) => {
return Object.keys(state.mentorsById).length;
});
const curMentor = useSelector<State, string>((state) => state.curMentor);
const video = useSelector<State, VideoData | null>((state) => {
if (state.chat.replay) {
Expand Down Expand Up @@ -149,11 +152,12 @@ function Video(args: { playing?: boolean }): JSX.Element {
setHideLinkLabel(true);
dispatch(playIdleAfterReplay(false));
dispatch(answerFinished());
dispatch(onVideoFinished(false));
}

function onPlay() {
setHideLinkLabel(false);
dispatch(onMentorDisplayAnswer(false, curMentor));

if (isIdle) {
setHideLinkLabel(true);
dispatch(answerFinished());
Expand Down Expand Up @@ -188,6 +192,7 @@ function Video(args: { playing?: boolean }): JSX.Element {
webLinks={webLinks}
hideLinkLabel={hideLinkLabel}
mentorName={mentorName ? mentorName?.name : ""}
numberMentors={numberMentors}
/>
<LoadingSpinner mentor={curMentor} />
<MessageStatus mentor={curMentor} />
Expand All @@ -207,6 +212,7 @@ interface VideoPlayerParams {
webLinks: WebLink[] | undefined;
hideLinkLabel: boolean;
mentorName: string;
numberMentors: number;
}

function VideoPlayer(args: VideoPlayerParams) {
Expand All @@ -222,6 +228,7 @@ function VideoPlayer(args: VideoPlayerParams) {
webLinks,
hideLinkLabel,
mentorName,
numberMentors,
} = args;

const webLinkJSX = webLinks?.map((wl, i) => {
Expand Down Expand Up @@ -265,7 +272,10 @@ function VideoPlayer(args: VideoPlayerParams) {
: false;

return (
<div className="video-player-wrapper">
<div
className="video-player-wrapper"
style={numberMentors > 1 ? { marginTop: 0 } : { marginTop: 50 }}
>
{!hideLinkLabel && shouldDiplayWebLinks ? answerLinkCard : null}
{mentorName ? mentorNameCard : null}
<ReactPlayer
Expand Down
36 changes: 21 additions & 15 deletions client/src/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface VideoFinishedAction {
type: typeof VIDEO_FINISHED;
payload: {
isVideoInProgress: boolean;
curMentor: string;
};
}

Expand Down Expand Up @@ -247,13 +248,14 @@ export type MentorClientAction =
export const MENTOR_SELECTION_TRIGGER_AUTO = "auto";
export const MENTOR_SELECTION_TRIGGER_USER = "user";

export const onVideoFinished =
(isVideoInProgress: boolean) =>
export const onMentorDisplayAnswer =
(isVideoInProgress: boolean, curMentor: string) =>
async (dispatch: ThunkDispatch<State, void, VideoFinishedAction>) => {
dispatch({
type: VIDEO_FINISHED,
payload: {
isVideoInProgress: isVideoInProgress,
isVideoInProgress,
curMentor,
},
});
};
Expand Down Expand Up @@ -282,14 +284,16 @@ export const feedbackSend =
});
} catch (err) {
console.error(err);
return dispatch({
type: FEEDBACK_SEND_FAILED,
payload: {
errors: [err.message],
feedback,
feedbackId,
},
});
if (err instanceof Error) {
return dispatch({
type: FEEDBACK_SEND_FAILED,
payload: {
errors: [err.message],
feedback,
feedbackId,
},
});
}
}
};

Expand All @@ -306,10 +310,12 @@ export const loadConfig =
});
} catch (err) {
console.error(err);
return dispatch({
type: CONFIG_LOAD_FAILED,
errors: [err.message],
});
if (err instanceof Error) {
return dispatch({
type: CONFIG_LOAD_FAILED,
errors: [err.message],
});
}
}
};

Expand Down
10 changes: 7 additions & 3 deletions client/src/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,17 @@ function findAskLinks(text: string): AskLink[] {
return askLinks;
}

function onVideoFinished(state: State, action: VideoFinishedAction): State {
function onMentorDisplayAnswer(
state: State,
action: VideoFinishedAction
): State {
return {
...state,
chat: {
...state.chat,
messages: state.chat.messages.map((m) => {
return m.isVideoInProgress !== action.payload.isVideoInProgress
return m.isVideoInProgress !== action.payload.isVideoInProgress &&
m.mentorId === action.payload.curMentor
? {
...m,
isVideoInProgress: action.payload.isVideoInProgress,
Expand Down Expand Up @@ -610,7 +614,7 @@ export default function reducer(
case PLAY_IDLE_AFTER_REPLAY_VIDEO:
return onPlayIdleAfterReplay(state, action);
case VIDEO_FINISHED:
return onVideoFinished(state, action);
return onMentorDisplayAnswer(state, action);
case QUESTION_ERROR:
return {
...state,
Expand Down
1 change: 0 additions & 1 deletion client/src/styles/video.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
.video-player-wrapper {
position: relative;
display: inline-block;
margin-top: 50px;
}

@media only screen and (max-width: 1200px) {
Expand Down
2 changes: 0 additions & 2 deletions cypress/cypress/integration/chat.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ describe("Chat", () => {
cy.intercept("**/questions/?mentor=*&query=*", {
fixture: "response_with_markdown.json",
});
cy.viewport("iphone-x");
cy.visit("/");
cy.get("[data-cy=chat-thread]").should("exist");
cy.get("[data-cy=input-field]").type("test");
Expand All @@ -97,7 +96,6 @@ describe("Chat", () => {
cy.intercept("**/questions/?mentor=covid&query=*", {
fixture: "response_with_feedback.json",
});
cy.viewport("iphone-x");
cy.visit("/");
cy.get("[data-cy=chat-thread]").should("exist");
cy.get("[data-cy=input-field]").type("test");
Expand Down
36 changes: 20 additions & 16 deletions cypress/cypress/integration/history.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Permission to use, copy, modify, and distribute this software and its documentat
The full terms of this copyright and license should always be found in the root directory of this software deliverable as "license.txt" and if these terms are not found with this software, please contact the USC Stevens Center for the full license.
*/

import {
visitAsGuestWithDefaultSetup,
mockDefaultSetup,
Expand Down Expand Up @@ -388,7 +389,7 @@ describe("Chat History (Video Mentors)", () => {
fixture: "video_response.mp4",
});
cy.visit("/");

cy.viewport(1200, 800);
cy.get("[data-cy=history-tab]").trigger("mouseover").click();
cy.get("[data-cy=history-chat]").should("exist");

Expand Down Expand Up @@ -428,22 +429,26 @@ describe("Chat History (Video Mentors)", () => {
cy.get("[data-cy=chat-msg-3]").should("not.be.visible");
// the answers for the last question are visible by default
// even if the show-all toggle is left unchecked
cy.get("[data-cy=chat-msg-5]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-6]").scrollIntoView().should("be.visible");

// show answers toggle
cy.get("[data-cy=visibility-switch]").find("input").check();
cy.get("[data-cy=chat-msg-2]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-3]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-5]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-6]").scrollIntoView().should("be.visible");

// the answers for the last question are visible by default
// even if the show-all toggle is left unchecked
cy.get("[data-cy=chat-msg-5]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-6]").scrollIntoView().should("be.visible");
// cy.get("[data-cy=chat-msg-5]").scrollIntoView();
cy.get("[data-cy=chat-msg-5]").should("be.visible");
cy.get("[data-cy=chat-msg-6]")
.scrollIntoView()
.should("not.be.visible");
});
});
cy.get("[data-cy=history-chat]").within(($hc) => {
// show answers toggle
cy.get("[data-cy=visibility-switch]").find("input").check();
cy.get("[data-cy=chat-msg-2]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-3]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-5]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-6]").scrollIntoView().should("be.visible");

// the answers for the last question are visible by default
// even if the show-all toggle is left unchecked
cy.get("[data-cy=chat-msg-5]").scrollIntoView().should("be.visible");
cy.get("[data-cy=chat-msg-6]").scrollIntoView().should("be.visible");
});
});

it("Question's answers can be toggled individually", () => {
Expand Down Expand Up @@ -770,7 +775,6 @@ describe("Chat History (Video Mentors)", () => {
fixture: "video_response.mp4",
});
cy.visit("/");
cy.viewport("macbook-11");
cy.get("[data-cy=history-tab]").trigger("mouseover").click();
cy.get("[data-cy=history-chat]").should("exist");
cy.get("[data-cy=history-chat]").should("exist");
Expand Down
2 changes: 0 additions & 2 deletions cypress/cypress/integration/questions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ describe("Questions list", () => {
apiResponse: "response_with_feedback.json",
});
cy.visit("/");
cy.viewport("macbook-11");
});

it("Do not show unanswered questions (subject)", () => {
Expand All @@ -219,6 +218,5 @@ describe("Questions list", () => {
apiResponse: "response_with_feedback.json",
});
cy.visit("/");
cy.viewport("macbook-11");
});
});
1 change: 0 additions & 1 deletion cypress/cypress/integration/video.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ describe("Video Mentor", () => {
});

cy.visit("/");
cy.viewport("macbook-11");

cy.get("[data-cy=header]").should("have.attr", "data-mentor", "carlos");
cy.get("[data-cy=header]").contains("Carlos Rios: Marine Logistician");
Expand Down

0 comments on commit fc51965

Please sign in to comment.