1
1
import React , { useState } from "react"
2
2
import styled from "@emotion/styled"
3
+ import { useLocation } from "@reach/router"
3
4
import { useIntl } from "react-intl"
4
5
5
6
import PageMetadata from "../components/PageMetadata"
@@ -68,12 +69,13 @@ const ResetIcon = styled(Icon)`
68
69
fill: ${ ( props ) => props . theme . colors . text } ;
69
70
`
70
71
71
- interface TranslatedLanguage extends Language {
72
- path : string
73
- }
74
-
75
72
const LanguagesPage = ( ) => {
76
73
const intl = useIntl ( )
74
+ const location = useLocation ( )
75
+ const redirectTo =
76
+ location . search . split ( "from=" ) . length > 1
77
+ ? location . search . split ( "from=" ) [ 1 ]
78
+ : "/"
77
79
const [ keyword , setKeyword ] = useState < string > ( "" )
78
80
const resetKeyword = ( e : React . MouseEvent < HTMLButtonElement > ) => {
79
81
e . preventDefault ( )
@@ -83,11 +85,10 @@ const LanguagesPage = () => {
83
85
"page-languages-filter-placeholder" ,
84
86
intl
85
87
)
86
- let translationsCompleted : Array < TranslatedLanguage > = [ ]
88
+ let translationsCompleted : Array < Language > = [ ]
87
89
for ( const lang in languageMetadata ) {
88
90
const langMetadata = {
89
91
...languageMetadata [ lang ] ,
90
- path : "/" ,
91
92
name : translateMessageId ( `language-${ lang } ` as TranslationKey , intl ) ,
92
93
}
93
94
@@ -147,7 +148,7 @@ const LanguagesPage = () => {
147
148
</ Form >
148
149
< LangContainer >
149
150
{ translationsCompleted . map ( ( lang ) => (
150
- < LangItem to = { lang . path } language = { lang . code } key = { lang [ "name" ] } >
151
+ < LangItem to = { redirectTo } language = { lang . code } key = { lang [ "name" ] } >
151
152
< LangTitle > { lang [ "name" ] } </ LangTitle >
152
153
< h4 > { lang . localName } </ h4 >
153
154
</ LangItem >
0 commit comments