Skip to content

Commit

Permalink
Merge branch 'main' into profileDescCharLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronKeys committed Apr 14, 2024
2 parents 8d53a1d + 44c0a4c commit 2d0521b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
29 changes: 26 additions & 3 deletions FU.SPA/src/components/pages/Discover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const paramKey = {
games: 'games',
tags: 'tags',
page: 'page',
postSort: 'psort',
userSort: 'usort',
};

const paramToDayjs = (searchParams, paramKey) => {
Expand All @@ -49,7 +51,7 @@ export default function Discover() {
Users: 'Users',
};

const queryLimit = 10;
const queryLimit = 12;
const [totalResults, setTotalResults] = useState(0);
const [searchParams, setSearchParams] = useSearchParams();
const initialTab = searchParams.get('o') || tabOptions.Posts;
Expand Down Expand Up @@ -78,8 +80,13 @@ export default function Discover() {
const [gameOptions, setGameOptions] = useState([]);
const [tagOptions, setTagOptions] = useState([]);

const [postSortOption, setPostSortOption] = useState(null);
const [userSortOption, setUserSortOption] = useState(null);
const [postSortOption, setPostSortOption] = useState(
searchParams.get(paramKey.postSort) ||
config.POST_SORT_OPTIONS[1].value + ':asc',
);
const [userSortOption, setUserSortOption] = useState(
searchParams.get(paramKey.userSort) || null,
);

const [dateRangeRadioValue, setDateRangeRadioValue] = useState(() => {
const paramValue = searchParams.get(paramKey.dateRadio);
Expand Down Expand Up @@ -168,6 +175,20 @@ export default function Discover() {
params.set('o', tabOption);
}

if (postSortOption) {
params.set(paramKey.postSort, postSortOption);
}

if (userSortOption) {
params.set(paramKey.userSort, userSortOption);
}

if (tabOption === tabOptions.Posts) {
params.delete(paramKey.userSort);
} else {
params.delete(paramKey.postSort);
}

return params;
},
{ replace: true },
Expand Down Expand Up @@ -316,6 +337,7 @@ export default function Discover() {
const renderPostSortSelector = () => {
return (
<SortOptionsSelector
initialValue={postSortOption}
options={config.POST_SORT_OPTIONS}
onChange={(newValue) => {
setPostSortOption(newValue);
Expand All @@ -328,6 +350,7 @@ export default function Discover() {
const renderUserSortSelector = () => {
return (
<SortOptionsSelector
initialValue={userSortOption}
options={config.USER_SORT_OPTIONS}
onChange={(newValue) => {
setUserSortOption(newValue);
Expand Down
8 changes: 5 additions & 3 deletions FU.SPA/src/components/pages/Social.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default function Social() {
const [searchText, setSearchText] = useState(searchParams.get('q') || '');
const initialPage = parseInt(searchParams.get(paramKey.page), 10) || 1;

const queryLimit = 10;
const queryLimit = 12;
const [totalResults, setTotalResults] = useState(0);

const [posts, setPosts] = useState([]);
Expand All @@ -47,10 +47,12 @@ export default function Social() {
const [page, setPage] = useState(initialPage);

const [postSortOption, setPostSortOption] = useState(
searchParams.get('psort') || null,
searchParams.get('psort') ||
config.SOCIAL_POST_SORT_OPTIONS[1].value + ':asc',
);
const [userSortOption, setUserSortOption] = useState(
searchParams.get('usort') || null,
searchParams.get('usort') ||
config.SOCIAL_USER_SORT_OPTIONS[2].value + ':desc',
);

const { user } = useContext(UserContext);
Expand Down

0 comments on commit 2d0521b

Please sign in to comment.