Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
fix: fix review selection with multiple languages (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKohler authored Nov 2, 2021
1 parent 96afece commit 05c9fa9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions web/src/components/language-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Link } from 'react-router-dom';
import { Localized } from '@fluent/react';

import { useLocaleUrl, getReviewUrl } from '../urls';
import { useLocaleUrl, useReviewUrl } from '../urls';

type Props = {
total: number;
Expand All @@ -22,7 +22,7 @@ const LanguageInfo = (props: Props) => {
const rejectedSentences = rejected;

const localizedAddUrl = useLocaleUrl('/add');
const localizedReviewUrl = getReviewUrl(language);
const localizedReviewUrl = useReviewUrl(language);

return (
<section>
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/review.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function Review() {

const onSelectLanguage = (language: string) => {
setLanguage(language);
history.push(getReviewUrl(language));
history.push(getReviewUrl(match.params.locale, language));
};

const onReviewed = (reviewedState: ReviewedState) => {
Expand Down
7 changes: 6 additions & 1 deletion web/src/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ import { useRouteMatch } from 'react-router-dom';

type LocaleMatch = { locale: string };

export const getReviewUrl = (language: string | undefined) => {
export const useReviewUrl = (language: string | undefined) => {
const match = useRouteMatch<LocaleMatch>();
const locale = match?.params?.locale;
const prefix = locale ? `/${locale}` : '';
const languageToReview = language || '';
return `${prefix}/review/${languageToReview}`;
};

export const getReviewUrl = (locale: string, language: string | undefined) => {
const languageToReview = language || '';
return `/${locale}/review/${languageToReview}`;
};

export const useLocaleUrl = (path: string) => {
const match = useRouteMatch<LocaleMatch>();
const locale = match?.params?.locale;
Expand Down

0 comments on commit 05c9fa9

Please sign in to comment.