From 4437fde6a0d87fe947a577529699f15d46f92575 Mon Sep 17 00:00:00 2001 From: epadams Date: Sun, 24 Mar 2024 19:41:21 -0400 Subject: [PATCH 1/7] Selector and options displayed correctly, sorting not working yet --- FU.SPA/src/components/pages/Discover.jsx | 10 ++++++++++ FU.SPA/src/config.js | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/FU.SPA/src/components/pages/Discover.jsx b/FU.SPA/src/components/pages/Discover.jsx index 7a0af065..b8206e33 100644 --- a/FU.SPA/src/components/pages/Discover.jsx +++ b/FU.SPA/src/components/pages/Discover.jsx @@ -315,6 +315,16 @@ export default function Discover() { }} /> ); + } else if (tabOption === tabOptions.Users) { + return ( + { + setSortOption(newValue); + setPage(1); + }} + /> + ); } }; diff --git a/FU.SPA/src/config.js b/FU.SPA/src/config.js index e12f2c43..d592de75 100644 --- a/FU.SPA/src/config.js +++ b/FU.SPA/src/config.js @@ -15,6 +15,14 @@ const config = { { value: 'newest', label: 'Created Date' }, { value: 'soonest', label: 'Start Time' }, { value: 'title', label: 'Title' }, + // TODO(epadams) add num players, already present in api + ], + USER_SORT_OPTIONS: [ + { value: 'username', label: 'Name' }, + /* look into adding these + { value: 'join-date', label: 'Account Age' }, // can literally just sort by account id + { value: 'birthday', label: 'Birthday' }, // more involved + */ ], }; From 578ce219b0262aa4b7268ed02e29d364e21969c7 Mon Sep 17 00:00:00 2001 From: epadams Date: Sun, 24 Mar 2024 19:52:28 -0400 Subject: [PATCH 2/7] Add more sorting options --- FU.SPA/src/components/pages/Discover.jsx | 1 + FU.SPA/src/config.js | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/FU.SPA/src/components/pages/Discover.jsx b/FU.SPA/src/components/pages/Discover.jsx index b8206e33..99070f45 100644 --- a/FU.SPA/src/components/pages/Discover.jsx +++ b/FU.SPA/src/components/pages/Discover.jsx @@ -321,6 +321,7 @@ export default function Discover() { options={config.USER_SORT_OPTIONS} onChange={(newValue) => { setSortOption(newValue); + console.log('new value:',newValue); setPage(1); }} /> diff --git a/FU.SPA/src/config.js b/FU.SPA/src/config.js index d592de75..267a686c 100644 --- a/FU.SPA/src/config.js +++ b/FU.SPA/src/config.js @@ -15,14 +15,12 @@ const config = { { value: 'newest', label: 'Created Date' }, { value: 'soonest', label: 'Start Time' }, { value: 'title', label: 'Title' }, + { value: 'players', label: '# of Players'}, // TODO(epadams) add num players, already present in api ], USER_SORT_OPTIONS: [ { value: 'username', label: 'Name' }, - /* look into adding these - { value: 'join-date', label: 'Account Age' }, // can literally just sort by account id - { value: 'birthday', label: 'Birthday' }, // more involved - */ + { value: 'joindate', label: 'Account Age' }, // can just sort by account id ], }; From 81bfb310e59a853b6f557885bfa5000c7e580986 Mon Sep 17 00:00:00 2001 From: epadams Date: Sun, 24 Mar 2024 19:52:48 -0400 Subject: [PATCH 3/7] Remove unnessecary comment --- FU.SPA/src/config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/FU.SPA/src/config.js b/FU.SPA/src/config.js index 267a686c..a0891945 100644 --- a/FU.SPA/src/config.js +++ b/FU.SPA/src/config.js @@ -16,7 +16,6 @@ const config = { { value: 'soonest', label: 'Start Time' }, { value: 'title', label: 'Title' }, { value: 'players', label: '# of Players'}, - // TODO(epadams) add num players, already present in api ], USER_SORT_OPTIONS: [ { value: 'username', label: 'Name' }, From 474df8080040cab3f9734e17aa8f9398b68a257b Mon Sep 17 00:00:00 2001 From: epadams Date: Sun, 24 Mar 2024 19:56:49 -0400 Subject: [PATCH 4/7] Added comment explaining issues with id sorting --- FU.SPA/src/config.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/FU.SPA/src/config.js b/FU.SPA/src/config.js index a0891945..b6fa6ef0 100644 --- a/FU.SPA/src/config.js +++ b/FU.SPA/src/config.js @@ -19,7 +19,11 @@ const config = { ], USER_SORT_OPTIONS: [ { value: 'username', label: 'Name' }, - { value: 'joindate', label: 'Account Age' }, // can just sort by account id + { value: 'joindate', label: 'Account Age' }, + /* can just sort by account id + * maybe not as simple, if we sort by user id it doesn't account for users + * that were low id and deleted their account + */ ], }; From 365b41d66e14dfe9b610102dbac8d87d401450b2 Mon Sep 17 00:00:00 2001 From: epadams Date: Wed, 27 Mar 2024 16:51:57 -0400 Subject: [PATCH 5/7] Sorting by name working, working on DOB --- FU.API/FU.API/Models/Sorting.cs | 2 + FU.API/FU.API/Services/SearchService.cs | 1 + FU.SPA/src/components/pages/Discover.jsx | 61 +++++++++++++----------- FU.SPA/src/config.js | 10 ++-- FU.SPA/src/helpers/requestBuilder.js | 6 +++ 5 files changed, 46 insertions(+), 34 deletions(-) diff --git a/FU.API/FU.API/Models/Sorting.cs b/FU.API/FU.API/Models/Sorting.cs index 5e0c221f..97cd2f3d 100644 --- a/FU.API/FU.API/Models/Sorting.cs +++ b/FU.API/FU.API/Models/Sorting.cs @@ -3,6 +3,8 @@ namespace FU.API.Models; public enum UserSortType { Username, + DOB, + AccountAge, } public enum PostSortType diff --git a/FU.API/FU.API/Services/SearchService.cs b/FU.API/FU.API/Services/SearchService.cs index 4236f02d..6cc99a7f 100644 --- a/FU.API/FU.API/Services/SearchService.cs +++ b/FU.API/FU.API/Services/SearchService.cs @@ -123,6 +123,7 @@ private static Expression> SelectUserProperty(User return sortType switch { UserSortType.Username => (user) => user.NormalizedUsername, + UserSortType.DOB => (user) => user.DOB, _ => (user) => user.NormalizedUsername, }; } diff --git a/FU.SPA/src/components/pages/Discover.jsx b/FU.SPA/src/components/pages/Discover.jsx index 99070f45..432d725a 100644 --- a/FU.SPA/src/components/pages/Discover.jsx +++ b/FU.SPA/src/components/pages/Discover.jsx @@ -76,7 +76,9 @@ export default function Discover() { ); const [gameOptions, setGameOptions] = useState([]); const [tagOptions, setTagOptions] = useState([]); - const [sortOption, setSortOption] = useState(null); + + const [postSortOption, setPostSortOption] = useState(null); + const [userSortOption, setUserSortOption] = useState(null); const [dateRangeRadioValue, setDateRangeRadioValue] = useState(() => { const paramValue = searchParams.get(paramKey.dateRadio); @@ -179,7 +181,7 @@ export default function Discover() { tags: tags, limit: queryLimit, page: page, - sort: sortOption, + sort: postSortOption, }; if (startDate) query.startDate = startDate; @@ -211,16 +213,20 @@ export default function Discover() { } } + // Search and set posts const response = await SearchService.searchPosts(query); setPosts(response.data); setTotalResults(response.totalCount); } else { + // on User tab const query = { keywords: searchText, limit: queryLimit, page: page, + sort: userSortOption, }; + // Search and set users const response = await SearchService.searchUsers(query); setPlayers(response.data); setTotalResults(response.totalCount); @@ -247,7 +253,8 @@ export default function Discover() { startTime, endTime, tabOption, - sortOption, + postSortOption, + userSortOption, ]); useEffect(() => { @@ -304,29 +311,28 @@ export default function Discover() { } }; - const renderSortSelector = () => { - if (tabOption === tabOptions.Posts) { - return ( - { - setSortOption(newValue); - setPage(1); - }} - /> - ); - } else if (tabOption === tabOptions.Users) { - return ( - { - setSortOption(newValue); - console.log('new value:',newValue); - setPage(1); - }} - /> - ); - } + const renderPostSortSelector = () => { + return ( + { + setPostSortOption(newValue); + setPage(1); + }} + /> + ); + }; + + const renderUserSortSelector = () => { + return ( + { + setUserSortOption(newValue); + setPage(1); + }} + /> + ); }; const renderTabSelectors = () => { @@ -428,7 +434,8 @@ export default function Discover() { searchText={searchText} onSearchSubmit={setSearchText} /> - {renderSortSelector()} + {tabOption === tabOptions.Posts && renderPostSortSelector()} + {tabOption === tabOptions.Users && renderUserSortSelector()} {renderTabContent()}
{ queryString += '&limit=' + query.limit; } + // Sort option if (query.sort) { queryString += '&sort=' + query.sort; } @@ -67,6 +68,11 @@ const buildUserQueryString = (query) => { queryString += '&limit=' + query.limit; } + // Sort option + if (query.sort) { + queryString += '&sort=' + query.sort; + } + return queryString; }; From fe5c1b65d1b2eab9feaaf2701bc497f7c1bd7ba0 Mon Sep 17 00:00:00 2001 From: epadams Date: Sun, 31 Mar 2024 15:33:49 -0400 Subject: [PATCH 6/7] Update Mapper.cs, sorting DOB works now --- FU.API/FU.API/Helpers/Mapper.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/FU.API/FU.API/Helpers/Mapper.cs b/FU.API/FU.API/Helpers/Mapper.cs index 6b73da57..b341b6c8 100644 --- a/FU.API/FU.API/Helpers/Mapper.cs +++ b/FU.API/FU.API/Helpers/Mapper.cs @@ -108,6 +108,7 @@ public static UserQuery ToUserQuery(this UserSearchRequestDTO dto) query.SortType = arr[0] switch { "username" => UserSortType.Username, + "dob" => UserSortType.DOB, "chatactivity" => UserSortType.ChatActivity, _ => UserSortType.Username, }; From 6c55dd0d63f323978d1154d29edfc906769b1370 Mon Sep 17 00:00:00 2001 From: evan-scales Date: Sun, 31 Mar 2024 17:36:58 -0400 Subject: [PATCH 7/7] add sorting to connected users --- FU.API/FU.API/Services/SearchService.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FU.API/FU.API/Services/SearchService.cs b/FU.API/FU.API/Services/SearchService.cs index 16cc8525..176fee9a 100644 --- a/FU.API/FU.API/Services/SearchService.cs +++ b/FU.API/FU.API/Services/SearchService.cs @@ -12,6 +12,8 @@ public class SearchService : CommonService, ISearchService { private static readonly DateTime DefaultTime = DateTime.MinValue; + private static readonly DateOnly DefaultDate = new DateOnly(1, 1, 1); + private readonly AppDbContext _dbContext; public SearchService(AppDbContext dbContext) @@ -127,7 +129,7 @@ private static Expression> SelectUserProperty(User return sortType switch { UserSortType.Username => (user) => user.NormalizedUsername, - UserSortType.DOB => (user) => user.DOB, + UserSortType.DOB => (user) => user.DOB ?? DefaultDate, _ => (user) => user.NormalizedUsername, }; } @@ -138,6 +140,7 @@ private static Expression> SelectConnectedUserPropert { UserSortType.Username => (ur) => ur.User2.NormalizedUsername, UserSortType.ChatActivity => (ur) => ur.Chat.LastMessageAt ?? DefaultTime, + UserSortType.DOB => (ur) => ur.User2.DOB ?? DefaultDate, _ => (ur) => ur.User2.NormalizedUsername, }; }