Skip to content

Issue #126 #150

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

Merged
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
3 changes: 2 additions & 1 deletion src/routers/challenge-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const App = () => {
return;
}

const params = utils.url.parseUrlQuery(location.search);
let search = location.href.split('?').length ? '?' + location.href.split('?')[1]: ''
const params = utils.url.parseUrlQuery(search);
const toUpdate = utils.challenge.createChallengeFilter(params);

if (!toUpdate.types) toUpdate.types = [];
Expand Down
2 changes: 1 addition & 1 deletion src/services/challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getService as getSubmissionsService } from "./submissions";
* @return {Array<Object>} challenges
*/
async function getChallenges(filter, cancellationSignal) {
const challengeQuery = util.buildQueryString(filter);
const challengeQuery = util.buildQueryString(filter, true);
return api.get(
`/challenges/${challengeQuery}`,
undefined,
Expand Down
12 changes: 9 additions & 3 deletions src/utils/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import qs from "qs";
* @params {Object<{[key: string]: any}>} params Query string parameters
* @return {String}
*/
export function buildQueryString(params) {
export function buildQueryString(params, disableEncode) {
params = _.omitBy(params, (p) => p == null || p === "" || p.length === 0);

if (!disableEncode) {
params.tags = _.map(params.tags, (t) => encodeURIComponent(t))
}
let queryString = qs.stringify(params, {
encode: false,
arrayFormat: "brackets",
Expand All @@ -28,7 +30,11 @@ export function buildQueryString(params) {
}

export function parseUrlQuery(queryString) {
return qs.parse(queryString, { ignoreQueryPrefix: true });
let params = qs.parse(queryString, { ignoreQueryPrefix: true });
if (params.tags) {
params.tags = _.map(params.tags, (t) => decodeURIComponent(t))
}
return params
}

export function updateQuery(params) {
Expand Down