Skip to content

Commit

Permalink
Use selected lang global state to persist language selection (#3032)
Browse files Browse the repository at this point in the history
  • Loading branch information
agalin920 authored Oct 25, 2024
1 parent 39d8d4e commit 672046b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { useGetUsersQuery } from "../../../../../../shell/services/accounts";
import { useParams as useRouterParams } from "react-router";
import { CascadingMenuItem } from "../../../../../../shell/components/CascadingMenuItem";
import { TableSortContext } from "./TableSortProvider";
import { selectLang } from "../../../../../../shell/store/user";
import { useDispatch } from "react-redux";

const SORT_ORDER = {
lastSaved: "Last Saved",
Expand Down Expand Up @@ -101,6 +103,7 @@ export const ItemListFilters = () => {
const { data: fields, isFetching: isFieldsFetching } =
useGetContentModelFieldsQuery(modelZUID);
const [sortModel, setSortModel] = useContext(TableSortContext);
const dispatch = useDispatch();

const activeSortOrder = sortModel?.[0]?.field;

Expand Down Expand Up @@ -360,6 +363,7 @@ export const ItemListFilters = () => {
onClick={() => {
setAnchorEl(null);
setParams(language.code, "lang");
dispatch(selectLang(language.code));
}}
>
{getFlagEmojiFromIETFTag(language.code)}{" "}
Expand Down
5 changes: 3 additions & 2 deletions src/apps/content-editor/src/app/views/ItemList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const ItemList = () => {
selectFilteredItems(state, modelZUID, activeLangId, !hasMounted)
);
const allFields = useSelector((state: AppState) => state.fields);
const user = useSelector((state: AppState) => state.user);
const { data: users, isFetching: isUsersFetching } = useGetUsersQuery();

const [isModelItemsFetching, setIsModelItemsFetching] = useState(true);
Expand Down Expand Up @@ -192,9 +193,9 @@ export const ItemList = () => {
}, [modelZUID, activeLanguageCode]);

useEffect(() => {
// if languages and no language param, set the first language as the active language
// if languages and no language param, set the user selected lang or first language as the active language
if (languages && !activeLanguageCode) {
setParams(languages[0].code, "lang");
setParams(user?.selected_lang || languages[0].code, "lang");
}
}, [languages, activeLanguageCode]);

Expand Down

0 comments on commit 672046b

Please sign in to comment.