Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): reload chapters sidebar when submission graded #551

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ProgressTag } from '../../../../../components/ProgressTag/ProgressTag';
import { ProgressBar } from '../../../../../components/ProgressBar/ProgressBar';
import { selectCourse } from '../../modules/courseSelectors';
import { PutCourseChapter } from '../chapters/modules/courseChapterReducer';
import { selectChapterProblemRefreshKey } from '../chapters/single/problems/single/modules/chapterProblemSelectors';
import * as courseChapterActions from '../chapters/modules/courseChapterActions';

import './CourseChaptersSidebar.scss';
Expand All @@ -21,11 +22,19 @@ class CourseChaptersSidebar extends Component {
};

async componentDidMount() {
const response = await this.props.onGetChapters(this.props.course.jid);
this.setState({ response });
await this.refreshChapters();
}

async componentDidUpdate(prevProps) {
if (this.props.chapterProblemRefreshKey !== prevProps.chapterProblemRefreshKey) {
await this.refreshChapters();
}
}

componentDidUpdate() {}
refreshChapters = async () => {
const response = await this.props.onGetChapters(this.props.course.jid);
this.setState({ response });
};

render() {
return (
Expand Down Expand Up @@ -176,6 +185,7 @@ class CourseChaptersSidebar extends Component {

const mapStateToProps = state => ({
course: selectCourse(state),
chapterProblemRefreshKey: selectChapterProblemRefreshKey(state),
});

const mapDispatchToProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ProblemType } from '../../../../../../../../../modules/api/sandalphon/p
import { selectCourse } from '../../../../../../modules/courseSelectors';
import { selectCourseChapter } from '../../../../modules/courseChapterSelectors';
import { selectCourseChapters } from '../../../../modules/courseChaptersSelectors';
import { selectChapterProblemKey } from '../modules/chapterProblemSelectors';
import { selectChapterProblemRefreshKey } from '../modules/chapterProblemSelectors';
import { selectStatementLanguage } from '../../../../../../../../../modules/webPrefs/webPrefsSelectors';
import * as chapterProblemActions from '../../modules/chapterProblemActions';
import * as breadcrumbsActions from '../../../../../../../../../modules/breadcrumbs/breadcrumbsActions';
Expand All @@ -33,7 +33,7 @@ export class ChapterProblemPage extends Component {
async componentDidUpdate(prevProps) {
if (
this.props.statementLanguage !== prevProps.statementLanguage ||
this.props.chapterProblemKey !== prevProps.chapterProblemKey ||
this.props.chapterProblemRefreshKey !== prevProps.chapterProblemRefreshKey ||
this.props.match.params.problemAlias !== prevProps.match.params.problemAlias
) {
await this.refreshProblem();
Expand Down Expand Up @@ -155,7 +155,7 @@ const mapStateToProps = state => ({
course: selectCourse(state),
chapter: selectCourseChapter(state),
chapters: selectCourseChapters(state),
chapterProblemKey: selectChapterProblemKey(state),
chapterProblemRefreshKey: selectChapterProblemRefreshKey(state),
statementLanguage: selectStatementLanguage(state),
});
const mapDispatchToProps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const initialState = {
value: undefined,
refreshKey: undefined,
};

export function RefreshChapterProblem(key) {
Expand All @@ -12,7 +12,7 @@ export function RefreshChapterProblem(key) {
export default function chapterProblemReducer(state = initialState, action) {
switch (action.type) {
case 'jerahmeel/chapterProblem/REFRESH':
return { ...state, value: action.payload };
return { ...state, refreshKey: action.payload };
default:
return state;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function selectChapterProblemKey(state) {
return state.jerahmeel.chapterProblem.value;
export function selectChapterProblemRefreshKey(state) {
return state.jerahmeel.chapterProblem.refreshKey;
}