File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
web/src/apps/main/redux/reducers/settings Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 11import { allLanguages , LanguageEntity } from "@dzcode.io/models/dist/language" ;
2+ import { matchPath } from "react-router-dom" ;
3+ import { history } from "src/common/utils/history" ;
4+ import { urlLanguageRegEx } from "src/common/utils/language" ;
25
36export interface SettingsState {
47 darkMode : boolean ;
@@ -29,6 +32,27 @@ export const settings = (
2932 if ( action . payload . language ) {
3033 localStorage . setItem ( "languageCode" , action . payload . language . code ) ;
3134 document . body . setAttribute ( "dir" , action . payload . language . code === "ar" ? "rtl" : "ltr" ) ;
35+ const match = matchPath < { lang ?: LanguageEntity [ "code" ] } > ( history . location . pathname , {
36+ path : urlLanguageRegEx ,
37+ exact : false ,
38+ strict : false ,
39+ } ) ;
40+ console . log ( {
41+ payload : action . payload . language . code ,
42+ match : match ?. params . lang ,
43+ } ) ;
44+
45+ const langPrefix =
46+ action . payload . language . code === "en" ? "" : `/${ action . payload . language . code } ` ;
47+
48+ if ( match ?. params . lang || langPrefix ) {
49+ history . push ( {
50+ ...history . location ,
51+ pathname : match ?. params . lang
52+ ? history . location . pathname . replace ( `/${ match . params . lang } ` , langPrefix )
53+ : `${ langPrefix } ${ history . location . pathname } ` ,
54+ } ) ;
55+ }
3256 }
3357 return { ...state , ...action . payload } ;
3458 default :
You can’t perform that action at this time.
0 commit comments