From cbf8a5e25bdde0ba2015f5c910189835e87e601d Mon Sep 17 00:00:00 2001 From: Martin Krulis Date: Sat, 19 Aug 2023 16:10:35 +0200 Subject: [PATCH] Fixing bugs. --- src/pages/Exercise/Exercise.js | 42 ++++++++++++------- .../ExerciseReferenceSolutions.js | 13 +++--- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/pages/Exercise/Exercise.js b/src/pages/Exercise/Exercise.js index 09bd0a4e9..d72ae0175 100644 --- a/src/pages/Exercise/Exercise.js +++ b/src/pages/Exercise/Exercise.js @@ -5,6 +5,7 @@ import { connect } from 'react-redux'; import { FormattedMessage, injectIntl } from 'react-intl'; import { Row, Col } from 'react-bootstrap'; import { Link } from 'react-router-dom'; +import { defaultMemoize } from 'reselect'; import SubmitSolutionContainer from '../../containers/SubmitSolutionContainer'; import CommentThreadContainer from '../../containers/CommentThreadContainer'; @@ -44,6 +45,10 @@ export const FORK_EXERCISE_FORM_INITIAL_VALUES = { groupId: '', }; +const getPromotedReferenceSolutions = defaultMemoize(referenceSolutions => + referenceSolutions.filter(rs => rs.visibility > 1) +); + class Exercise extends Component { state = { forkId: Math.random().toString() }; @@ -184,31 +189,40 @@ class Exercise extends Component { )} )} - - - + {referenceSolutions && referenceSolutions.size > 0 && ( + + + + )} }>
{referenceSolutions => - referenceSolutions.length > 0 ? ( + getPromotedReferenceSolutions(referenceSolutions).length > 0 ? ( ) : (
- + {referenceSolutions.length === 0 ? ( + + ) : ( + + )}
) } diff --git a/src/pages/ExerciseReferenceSolutions/ExerciseReferenceSolutions.js b/src/pages/ExerciseReferenceSolutions/ExerciseReferenceSolutions.js index 817749d12..896b92aad 100644 --- a/src/pages/ExerciseReferenceSolutions/ExerciseReferenceSolutions.js +++ b/src/pages/ExerciseReferenceSolutions/ExerciseReferenceSolutions.js @@ -49,7 +49,7 @@ import { referenceSolutionsSelector } from '../../redux/selectors/referenceSolut import { loggedInUserIdSelector } from '../../redux/selectors/auth'; import { getReadyUserSelector } from '../../redux/selectors/users'; -import { storageGetItem, storageSetItem } from '../../helpers/localStorage'; +import { storageGetItem, storageSetItem, storageRemoveItem } from '../../helpers/localStorage'; import { hasPermissions, safeGet, objectFilter } from '../../helpers/common'; import withLinks from '../../helpers/withLinks'; import withRouter, { withRouterProps } from '../../helpers/withRouter'; @@ -265,16 +265,19 @@ class ExerciseReferenceSolutions extends Component { ...INITIAL_FILTER_STATE, }; + openFilters = () => this.setState({ filtersOpen: true }); + closeFilters = () => this.setState({ filtersOpen: false }); + resetFilters = () => { + storageRemoveItem(LOCAL_STORAGE_STATE_KEY); + this.setState(INITIAL_FILTER_STATE); + }; + _setFilterState = newState => { const toSave = objectFilter({ ...this.state, ...newState }, (_, key) => INITIAL_FILTER_STATE[key]); storageSetItem(LOCAL_STORAGE_STATE_KEY, toSave); this.setState(newState); }; - openFilters = () => this.setState({ filtersOpen: true }); - closeFilters = () => this.setState({ filtersOpen: false }); - resetFilters = () => this.setState(INITIAL_FILTER_STATE); - toggleShowMine = () => this._setFilterState({ showMine: !this.state.showMine || !this.state.showOthers }); toggleShowOthers = () => this._setFilterState({ showOthers: !this.state.showMine || !this.state.showOthers });