Skip to content

Commit

Permalink
Fixing bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
krulis-martin committed Aug 21, 2023
1 parent 5020f45 commit cbf8a5e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
42 changes: 28 additions & 14 deletions src/pages/Exercise/Exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() };

Expand Down Expand Up @@ -184,31 +189,40 @@ class Exercise extends Component {
)}
</Button>
)}
<Link to={EXERCISE_REFERENCE_SOLUTIONS_URI_FACTORY(exercise.id)}>
<Button variant="primary">
<FormattedMessage
id="app.exercise.allRefSolutions"
defaultMessage="All Reference Solutions"
/>
</Button>
</Link>
{referenceSolutions && referenceSolutions.size > 0 && (
<Link to={EXERCISE_REFERENCE_SOLUTIONS_URI_FACTORY(exercise.id)}>
<Button variant="primary">
<FormattedMessage
id="app.exercise.allRefSolutions"
defaultMessage="All Reference Solutions"
/>
</Button>
</Link>
)}
</TheButtonGroup>
</div>
}>
<div>
<ResourceRenderer resource={referenceSolutions.toArray()} returnAsArray>
{referenceSolutions =>
referenceSolutions.length > 0 ? (
getPromotedReferenceSolutions(referenceSolutions).length > 0 ? (
<ReferenceSolutionsTable
referenceSolutions={referenceSolutions}
referenceSolutions={getPromotedReferenceSolutions(referenceSolutions)}
runtimeEnvironments={runtimes}
/>
) : (
<div className="text-center m-3 text-muted small">
<FormattedMessage
id="app.exercise.noPromotedReferenceSolutions"
defaultMessage="There are no promoted reference solutions for this exercise yet."
/>
{referenceSolutions.length === 0 ? (
<FormattedMessage
id="app.exercise.noReferenceSolutions"
defaultMessage="There are no reference solutions for this exercise yet."
/>
) : (
<FormattedMessage
id="app.exercise.noPromotedReferenceSolutions"
defaultMessage="There are no promoted reference solutions for this exercise yet."
/>
)}
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 });

Expand Down

0 comments on commit cbf8a5e

Please sign in to comment.