Skip to content

Commit

Permalink
feat: add sorting to requests page
Browse files Browse the repository at this point in the history
  • Loading branch information
hegeaal committed Oct 19, 2023
1 parent 3915569 commit d6286b2
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 25 deletions.
16 changes: 10 additions & 6 deletions src/api/community-api/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ export const extractTopicsFromSearch = (
return uniqueTopics;
};

export const searchCommunityRequests = (queryTerm: string) => {
export const searchCommunityRequests = (
queryTerm: string,
sortOption?: string
) => {
if (queryTerm.length > 0) {
return axios
.get(
`${FDK_COMMUNITY_BASE_URI}/api/search?term=${queryTerm}&in=titles&matchWords=all&category=6`
`${FDK_COMMUNITY_BASE_URI}/api/search?term=${queryTerm}&in=titles&matchWords=all&categories[]=6&sortBy=${sortOption}&sortDirection=desc`
)
.then(({ data }) => data);
} else {
return axios
.get(`${FDK_COMMUNITY_BASE_URI}/api/search?&category=6`)
.then(({ data }) => data);
}
return axios
.get(
`${FDK_COMMUNITY_BASE_URI}/api/search?&categories[]=6&sortBy=${sortOption}&sortDirection=desc`
)
.then(({ data }) => data);
};

export const pruneNodebbTemplateTags = (raw_text: string) =>
Expand Down
8 changes: 6 additions & 2 deletions src/components/with-community/redux/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ export function searchTopicsFailed(message: string) {
};
}

export function searchRequestsRequested(queryTerm: string) {
export function searchRequestsRequested(
queryTerm: string,
sortOption?: string
) {
return {
type: SEARCH_REQUESTS_REQUESTED,
payload: {
queryTerm
queryTerm,
sortOption
}
};
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/with-community/redux/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ function* searchTopicsRequested({
}

function* searchRequestsRequested({
payload: { queryTerm }
payload: { queryTerm, sortOption }
}: ReturnType<typeof actions.searchRequestsRequested>) {
try {
const postHits: CommunityPost = yield call(
searchCommunityRequests,
queryTerm
queryTerm,
sortOption
);
const { multiplePages } = postHits;
const topics: CommunityTopic[] = (
Expand Down
5 changes: 4 additions & 1 deletion src/l10n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,9 @@
"views": "Number of Views",
"createRequest": "Create request",
"requestData": "Request data",
"requestDataInfo": "Do you want to request data, APIs, or anything else you can do it here. You will be redirected to datalandsbyen.no."
"requestDataInfo": "Do you want to request data, APIs, or anything else you can do it here. You will be redirected to datalandsbyen.no.",
"newestToOldest": "Newest to Oldest",
"mostVotes": "Most Votes",
"mostViews": "Most Views"
}
}
5 changes: 4 additions & 1 deletion src/l10n/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,9 @@
"views": "Antall visninger",
"createRequest": "Lag etterspørsel",
"requestData": "Etterspør data",
"requestDataInfo": "Ønsker du å etterspørre data, APIer eller annet du kan gjøre det her. Du blir sendt til datalandsbyen.no."
"requestDataInfo": "Ønsker du å etterspørre data, APIer eller annet du kan gjøre det her. Du blir sendt til datalandsbyen.no.",
"newestToOldest": "Nyeste til eldste",
"mostVotes": "Flest stemmer",
"mostViews": "Flest visninger"
}
}
5 changes: 4 additions & 1 deletion src/l10n/nn.json
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,9 @@
"views": "Antall visningar",
"createRequest": "Lag etterspurnad",
"requestData": "Etterspør data",
"requestDataInfo": "Ynskjer du å etterspørre data, APIer eller anna kan du gjere det her. Du blir sendt til datalandsbyen.no."
"requestDataInfo": "Ynskjer du å etterspørre data, APIer eller anna kan du gjere det her. Du blir sendt til datalandsbyen.no.",
"newestToOldest": "Nyeste til eldste",
"mostVotes": "Flest stemmer",
"mostViews": "Flest visningar"
}
}
35 changes: 26 additions & 9 deletions src/pages/requests/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const RequestsPage: FC<Props> = ({
<>
<Banner title={localization.requestsPage.title} />
<main id='content' className='container'>
<SC.Row>
<SC.FirstRow>
<SC.InfoText>
<p>
{localization.formatString(localization.requestsPage.ingress, {
Expand All @@ -52,14 +52,31 @@ const RequestsPage: FC<Props> = ({
{localization.requestsPage.createRequest}
</Button>
</SC.Button>
</SC.Row>
<SC.Button>
<input
type='text'
onChange={event => setSearch(event.target.value)}
></input>
<Button onClick={() => searchRequestsRequested(search)}>Søk</Button>
</SC.Button>
</SC.FirstRow>
<SC.FirstRow>
<SC.Row>
<Button
onClick={() => searchRequestsRequested(search, 'timestamp')}
>
{localization.requestsPage.newestToOldest}
</Button>
<Button onClick={() => searchRequestsRequested(search, 'upvotes')}>
{localization.requestsPage.mostVotes}
</Button>
<Button
onClick={() => searchRequestsRequested(search, 'topic.viewcount')}
>
{localization.requestsPage.mostViews}
</Button>
</SC.Row>
<SC.Row>
<input
type='text'
onChange={event => setSearch(event.target.value)}
/>
<Button onClick={() => searchRequestsRequested(search)}>Søk</Button>
</SC.Row>
</SC.FirstRow>
<SC.RequestsTitleRow>
<SC.RequestTitle>
{localization.requestsPage.requests}
Expand Down
11 changes: 8 additions & 3 deletions src/pages/requests/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,19 @@ const InfoText = styled.div`
margin-bottom: 50px;
`;

const Row = styled.div`
const FirstRow = styled.div`
display: flex;
justify-content: space-between;
align-items: center;
padding-bottom: 17px;
`;

const Row = styled.div`
display: flex;
`;

const Button = styled.div`
height: fit-content;
display: flex;
`;

const InfoBox = styled.div`
Expand All @@ -83,5 +87,6 @@ export default {
Row,
Button,
InfoBox,
Text
Text,
FirstRow
};

0 comments on commit d6286b2

Please sign in to comment.