Skip to content

Commit

Permalink
feat: added filters
Browse files Browse the repository at this point in the history
  • Loading branch information
jordan-ae committed Mar 5, 2024
1 parent cc34097 commit 6364e08
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 15 deletions.
32 changes: 26 additions & 6 deletions src/pages/people/tabs/Wanted.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { usePerson } from 'hooks';
import { observer } from 'mobx-react-lite';
import { EuiCheckboxGroup } from '@elastic/eui';
import { BountyModal } from 'people/main/bountyModal';
import { widgetConfigs } from 'people/utils/Constants';
import NoneSpace from 'people/utils/NoneSpace';
Expand All @@ -13,6 +14,7 @@ import { paginationQueryLimit } from 'store/main';
import styled from 'styled-components';
import { LoadMoreContainer } from '../../../people/widgetViews/WidgetSwitchViewer';
import { colors } from '../../../config/colors';

const config = widgetConfigs.bounties;
type BountyType = any;
const Container = styled.div`
Expand Down Expand Up @@ -52,14 +54,17 @@ export const Wanted = observer(() => {
const [loading, setIsLoading] = useState<boolean>(false);
const [page, setPage] = useState(1);
const [hasMoreBounties, setHasMoreBounties] = useState(true);
const [sort, setSort] = useState('paid');

const Status = ['open', 'assingned', 'paid'];

// Function to fetch user tickets with pagination
const getUserTickets = async () => {
setIsLoading(true);

// Fetch bounties for the specified page and limit
const response = await main.getPersonCreatedBounties(
{ page: page, limit: paginationQueryLimit },
{ page: page, limit: paginationQueryLimit, sortBy: sort },
uuid
);

Expand All @@ -77,7 +82,7 @@ export const Wanted = observer(() => {
setPage(nextPage);
// Fetch bounties for the next page
const response = await main.getPersonCreatedBounties(
{ page: nextPage, limit: paginationQueryLimit },
{ page: nextPage, limit: paginationQueryLimit, sortBy: sort },
uuid
);
// Check if the response has fewer bounties than the limit, indicating no more bounties to load
Expand All @@ -90,7 +95,7 @@ export const Wanted = observer(() => {

useEffect(() => {
getUserTickets();
}, [main]);
}, [main, sort]);

if (!main.createdBounties?.length && !loading) {
return (
Expand Down Expand Up @@ -130,11 +135,26 @@ export const Wanted = observer(() => {
style={{
width: '100%',
display: 'flex',
justifyContent: 'flex-end',
paddingBottom: '16px'
justifyContent: 'space-between',
paddingBottom: '16px',
alignItems: 'center'
}}
>
{canEdit && <PostBounty widget="bounties" />}
<h4>Bounties {sort}</h4>
<div style={{ display: 'flex' }}>
<EuiCheckboxGroup
style={{ display: 'flex', alignItems: 'center', gap: 10, marginRight: 20 }}
options={Status.map((status: any) => ({
label: `${status}`,
id: status
}))}
idToSelectedMap={{ [sort]: true }}
onChange={(id: any) => {
setSort(id);
}}
/>
{canEdit && <PostBounty widget="bounties" />}
</div>
</div>
{displayedBounties
.filter((w: BountyType) => w.body.owner_id === person?.owner_pubkey)
Expand Down
35 changes: 31 additions & 4 deletions src/people/widgetViews/UserTicketsView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { useEffect, useState } from 'react';
import { Route, Switch, useParams, useRouteMatch, Router } from 'react-router-dom';
import { useStores } from 'store';
import { EuiCheckboxGroup } from '@elastic/eui';
import NoResults from 'people/utils/UserNoResults';
import { useIsMobile, usePerson } from 'hooks';
import { useIsMobile } from 'hooks';
import { Spacer } from 'people/main/Body';
import styled from 'styled-components';
import { BountyModal } from 'people/main/bountyModal/BountyModal';
Expand All @@ -13,6 +14,7 @@ import { colors } from '../../config/colors';
import WantedView from './WantedView';
import DeleteTicketModal from './DeleteModal';
import { LoadMoreContainer } from './WidgetSwitchViewer';

type BountyType = any;

const Container = styled.div`
Expand Down Expand Up @@ -49,7 +51,7 @@ const UserTickets = () => {
const isMobile = useIsMobile();
const { path, url } = useRouteMatch();

const { person } = usePerson(ui.selectedPerson);
const Status = ['Assigned', 'Paid'];

const [deletePayload, setDeletePayload] = useState<object>({});
const [showDeleteModal, setShowDeleteModal] = useState<boolean>(false);
Expand All @@ -59,6 +61,7 @@ const UserTickets = () => {
const [loading, setIsLoading] = useState<boolean>(true);
const [hasMoreBounties, setHasMoreBounties] = useState(true);
const [bountyOwner, setBountyOwner] = useState<Person>();
const [sort, setSort] = useState('');
const [page, setPage] = useState(1);
const paginationLimit = 20;

Expand Down Expand Up @@ -113,7 +116,7 @@ const UserTickets = () => {
const nextPage = page + 1;
setPage(nextPage);
const response = await main.getPersonAssignedBounties(
{ page: nextPage, limit: paginationLimit },
{ page: nextPage, limit: paginationLimit, sortBy: sort },
uuid
);
if (response.length < paginationLimit) {
Expand All @@ -124,7 +127,7 @@ const UserTickets = () => {

useEffect(() => {
getUserTickets();
}, [main]);
}, [main, sort]);

const listItems =
displayedBounties && displayedBounties.length ? (
Expand Down Expand Up @@ -171,6 +174,30 @@ const UserTickets = () => {
</Route>
</Switch>
</Router>
<div
style={{
width: '100%',
display: 'flex',
justifyContent: 'space-between',
paddingBottom: '16px',
alignItems: 'center'
}}
>
<h4>Assigned Bounties {sort}</h4>
<div style={{ display: 'flex' }}>
<EuiCheckboxGroup
style={{ display: 'flex', gap: 20, alignItems: 'center', alignContent: 'center' }}
options={Status.map((status: any) => ({
label: `${status}`,
id: status
}))}
idToSelectedMap={{ [sort]: true }}
onChange={(id: any) => {
setSort(id);
}}
/>
</div>
</div>
{!loading ? listItems : ''}
{hasMoreBounties && !loading && (
<LoadMoreContainer
Expand Down
8 changes: 3 additions & 5 deletions src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,7 @@ export class MainStore {

const query = this.appendQueryParams(`people/wanteds/assigned/${uuid}`, paginationQueryLimit, {
sortBy: 'paid',
...queryParams,
direction: 'ASC'
...queryParams
});

try {
Expand Down Expand Up @@ -986,9 +985,7 @@ export class MainStore {
queryParams = { ...queryParams, search: uiStore.searchText };

const query = this.appendQueryParams(`people/wanteds/created/${uuid}`, paginationQueryLimit, {
...queryParams,
sortBy: 'paid',
direction: 'ASC'
...queryParams
});

try {
Expand Down Expand Up @@ -1652,6 +1649,7 @@ export class MainStore {
body.coding_languages = languages;
}

// eslint-disable-next-line no-useless-catch
try {
const request = `gobounties?token=${info?.tribe_jwt}`;
//TODO: add some sort of authentication
Expand Down

0 comments on commit 6364e08

Please sign in to comment.