Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#5972 - Removing the Community Tag from the Search Tag Results in Global Search #6218

Merged
merged 2 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions packages/commonwealth/client/scripts/controllers/server/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class SearchController {
return this.getByQuery(searchQuery);
}
const searchCache = this._store.getOrAdd(searchQuery);
const { searchTerm, chainScope, isSearchPreview, sort } = searchQuery;
const { searchTerm, communityScope, isSearchPreview, sort } = searchQuery;
const pageSize = isSearchPreview ? SEARCH_PREVIEW_SIZE : SEARCH_PAGE_SIZE;
const scope = searchQuery.getSearchScope();

Expand All @@ -42,7 +42,7 @@ class SearchController {
) {
const discussions = await this.searchDiscussions(searchTerm, {
pageSize,
chainScope,
communityScope,
sort,
});

Expand All @@ -58,7 +58,7 @@ class SearchController {
if (scope.includes(SearchScope.Replies)) {
const comments = await this.searchComments(searchTerm, {
pageSize,
chainScope,
communityScope,
sort,
});

Expand Down Expand Up @@ -90,7 +90,7 @@ class SearchController {
if (scope.includes(SearchScope.Members)) {
const { profiles } = await this.searchMentionableProfiles(
searchTerm,
chainScope,
communityScope,
);

searchCache.results[SearchScope.Members] = profiles
Expand Down Expand Up @@ -143,10 +143,10 @@ class SearchController {
page: number,
pageSize: number,
) {
const { searchTerm, chainScope, sort } = searchQuery;
const { searchTerm, communityScope, sort } = searchQuery;
const searchParams = {
pageSize,
chainScope,
communityScope,
sort,
};
switch (tab) {
Expand Down Expand Up @@ -188,10 +188,10 @@ class SearchController {
params: SearchParams,
page?: number,
) => {
const { pageSize, chainScope, communityScope, sort } = params;
const { pageSize, communityScope, sort } = params;
try {
const queryParams = {
chain: chainScope,
chain: communityScope,
community: communityScope,
search: searchTerm,
page_size: pageSize,
Expand All @@ -218,10 +218,10 @@ class SearchController {
params: SearchParams,
page?: number,
) => {
const { pageSize, chainScope, communityScope, sort } = params;
const { pageSize, communityScope, sort } = params;
try {
const queryParams = {
chain: chainScope,
chain: communityScope,
community: communityScope,
search: searchTerm,
page_size: pageSize,
Expand All @@ -247,11 +247,11 @@ class SearchController {
searchTerm: string,
params: SearchParams,
): Promise<Thread[]> => {
const { pageSize, chainScope, communityScope } = params;
const { pageSize, communityScope } = params;
try {
const response = await axios.get(`${app.serverUrl()}/threads`, {
params: {
chain: chainScope,
chain: communityScope,
community: communityScope,
search: searchTerm,
results_size: pageSize,
Expand All @@ -272,14 +272,14 @@ class SearchController {

public searchMentionableProfiles = async (
searchTerm: string,
chainScope: string,
communityScope: string,
pageSize?: number,
page?: number,
includeRoles?: boolean,
) => {
const response = await axios.get(`${app.serverUrl()}/profiles`, {
params: {
chain: chainScope,
chain: communityScope,
search: searchTerm,
page_size: pageSize,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const useSearchResults = (
): {
searchResults: SearchResults;
} => {
const communityId = app.activeChainId() || 'all_communities';
const communityId = filters.includes('communities')
? 'all_communities'
: app.activeChainId();
const debouncedSearchTerm = useDebounce<string>(searchTerm, 500);

const sharedQueryOptions = {
Expand Down
9 changes: 4 additions & 5 deletions packages/commonwealth/client/scripts/models/SearchQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export enum SearchSort {

export interface SearchParams {
communityScope?: string;
chainScope?: string;
isSearchPreview?: boolean;
searchScope?: Array<SearchScope>;
sort?: SearchSort;
Expand All @@ -33,23 +32,23 @@ export interface SearchParams {

export default class SearchQuery implements SearchParams {
public searchTerm: Lowercase<string>;
public chainScope?: string;
public communityScope?: string;
public isSearchPreview?: boolean;
public searchScope: Array<SearchScope>;
public sort: SearchSort;

constructor(searchTerm = '', params?: SearchParams) {
this.searchTerm = <Lowercase<string>>searchTerm.toLowerCase();
this.searchScope = params?.searchScope || [SearchScope.All];
this.chainScope = params?.chainScope;
this.communityScope = params?.communityScope;
this.isSearchPreview = !!params?.isSearchPreview;
this.sort = params?.sort || SearchSort.Best;
}

public toEncodedString() {
let encodedString =
this.searchTerm.trim().replace(/\s+/g, '%20') +
(this.chainScope ? ` chainScope=${this.chainScope}` : '') +
(this.communityScope ? ` communityScope=${this.communityScope}` : '') +
(this.isSearchPreview ? ` isSearchPreview=${this.isSearchPreview}` : '') +
(this.sort ? ` sort=${this.sort}` : '');

Expand Down Expand Up @@ -107,7 +106,7 @@ export default class SearchQuery implements SearchParams {

public static fromUrlParams(url: Record<string, any>) {
const sq = new SearchQuery(url['q']);
sq.chainScope = url['chainScope'] || undefined;
sq.communityScope = url['communityScope'] || undefined;
sq.isSearchPreview = url['preview'] === 'true';
sq.sort = url['sort'] || SearchSort.Best;
sq.searchScope = url['scope'] || [SearchScope.All];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export const CWSearchBar: FC<SearchBarProps> = ({
}) => {
const navigate = useCommonNavigate();
const [showTag, setShowTag] = useState(true);
const communityId = app.activeChainId() || 'all_communities';
const communityId = showTag
? app.activeChainId() || 'all_communities'
: 'all_communities';
const community = app.config.chains.getById(communityId);
const [searchTerm, setSearchTerm] = useState('');
const { searchResults } = useSearchResults(searchTerm, [
Expand Down Expand Up @@ -95,7 +97,7 @@ export const CWSearchBar: FC<SearchBarProps> = ({
const handleGoToSearchPage = () => {
const searchQuery = new SearchQuery(searchTerm, {
isSearchPreview: false,
chainScope: showTag ? communityId : 'all_communities',
communityScope: showTag ? communityId : 'all_communities',
});
goToSearchPage(searchQuery, navigate);
resetSearchBar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const SearchPage = () => {
SORT_MAP[queryParams.sort] || DEFAULT_SORT_OPTIONS;

const sharedQueryOptions = {
communityId: app.activeChainId() || 'all_communities',
communityId: community,
searchTerm: queryParams.q,
limit: 20,
orderBy,
Expand Down
Loading