diff --git a/db/db.go b/db/db.go index 3aa3fcab9..c030aae36 100644 --- a/db/db.go +++ b/db/db.go @@ -437,9 +437,35 @@ func (db database) GetUserBountiesCount(personKey string, tabType string) int64 return count } -func (db database) GetBountiesCount() int64 { +func (db database) GetBountiesCount(r *http.Request) int64 { + keys := r.URL.Query() + open := keys.Get("Open") + assingned := keys.Get("Assigned") + paid := keys.Get("Paid") + openQuery := "" + assignedQuery := "" + paidQuery := "" + + if open != "" && open == "true" { + openQuery = "AND assignee = ''" + assignedQuery = "" + } + if assingned != "" && assingned == "true" { + if open != "" && open == "true" { + assignedQuery = "OR assignee != ''" + } else { + assignedQuery = "AND assignee != ''" + } + } + if paid != "" && paid == "true" { + paidQuery = "AND paid = true" + } + var count int64 - db.db.Model(&Bounty{}).Where("show != ?", false).Count(&count) + + query := "SELECT COUNT(*) FROM bounty WHERE show != false" + allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + db.db.Raw(allQuery).Scan(&count) return count } @@ -447,11 +473,18 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B keys := r.URL.Query() tags := keys.Get("tags") // this is a string of tags separated by commas offset, limit, sortBy, direction, search := utils.GetPaginationParams(r) + open := keys.Get("Open") + assingned := keys.Get("Assigned") + paid := keys.Get("Paid") ms := []Bounty{} orderQuery := "" limitQuery := "" searchQuery := "" + openQuery := "" + assignedQuery := "" + paidQuery := "" + if sortBy != "" && direction != "" { orderQuery = "ORDER BY " + sortBy + " " + direction } else { @@ -463,10 +496,24 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B if search != "" { searchQuery = fmt.Sprintf("WHERE LOWER(title) LIKE %s", "'%"+search+"%'") } + if open != "" && open == "true" { + openQuery = "AND assignee = ''" + assignedQuery = "" + } + if assingned != "" && assingned == "true" { + if open != "" && open == "true" { + assignedQuery = "OR assignee != ''" + } else { + assignedQuery = "AND assignee != ''" + } + } + if paid != "" && paid == "true" { + paidQuery = "AND paid = true" + } - rawQuery := `SELECT * FROM bounty WHERE org_uuid = '` + org_uuid + `'` - - theQuery := db.db.Raw(rawQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery) + query := `SELECT * FROM bounty WHERE org_uuid = '` + org_uuid + `'` + allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery + theQuery := db.db.Raw(allQuery) if tags != "" { // pull out the tags and add them in here @@ -514,12 +561,18 @@ func (db database) GetAllBounties(r *http.Request) []Bounty { keys := r.URL.Query() tags := keys.Get("tags") // this is a string of tags separated by commas offset, limit, sortBy, direction, search := utils.GetPaginationParams(r) + open := keys.Get("Open") + assingned := keys.Get("Assigned") + paid := keys.Get("Paid") ms := []Bounty{} orderQuery := "" limitQuery := "" searchQuery := "" + openQuery := "" + assignedQuery := "" + paidQuery := "" if sortBy != "" && direction != "" { orderQuery = "ORDER BY " + sortBy + " " + direction @@ -532,10 +585,24 @@ func (db database) GetAllBounties(r *http.Request) []Bounty { if search != "" { searchQuery = fmt.Sprintf("AND LOWER(title) LIKE %s", "'%"+search+"%'") } + if open != "" && open == "true" { + openQuery = "AND assignee = ''" + assignedQuery = "" + } + if assingned != "" && assingned == "true" { + if open != "" && open == "true" { + assignedQuery = "OR assignee != ''" + } else { + assignedQuery = "AND assignee != ''" + } + } + if paid != "" && paid == "true" { + paidQuery = "AND paid = true" + } query := "SELECT * FROM public.bounty WHERE show != false" - allQuery := query + " " + searchQuery + " " + orderQuery + " " + limitQuery + allQuery := query + " " + openQuery + " " + assignedQuery + " " + paidQuery + " " + searchQuery + " " + orderQuery + " " + limitQuery theQuery := db.db.Raw(allQuery) diff --git a/db/db_codes_test.go b/db/db_codes_test.go index 4caad51cf..9a552688e 100644 --- a/db/db_codes_test.go +++ b/db/db_codes_test.go @@ -28,9 +28,7 @@ func TestCodeGet(t *testing.T) { defer db.Close() gorm.Open("postgres", db) - rows := sqlmock.NewRows([]string{"connection_string", "date_created", "is_used", "date_created"}).AddRow(code.ID, code.ConnectionString, code.IsUsed, code.DateCreated) - mock.ExpectQuery(regexp.QuoteMeta( `SELECT connection_string, date_created FROM connectioncodes WHERE is_used = ? ORDER BY id DESC LIMIT 1`)). WithArgs(false). diff --git a/db/store_test.go b/db/store_test.go index f6c365ace..3d404f1e3 100644 --- a/db/store_test.go +++ b/db/store_test.go @@ -9,9 +9,7 @@ func TestSetCache(t *testing.T) { var value = "Trial" InitCache() - Store.SetCache(key, value) - cacheValue, err := Store.GetCache(key) if err != nil { @@ -30,7 +28,6 @@ func TestDeleteCache(t *testing.T) { InitCache() Store.SetCache(key, value) - cacheValue, err := Store.GetCache(key) if err != nil { @@ -42,7 +39,6 @@ func TestDeleteCache(t *testing.T) { } Store.DeleteCache(key) - _, errD := Store.GetCache(key) if errD == nil { @@ -60,9 +56,7 @@ func TestSetLnCache(t *testing.T) { } InitCache() - Store.SetLnCache(key, value) - cacheValue, err := Store.GetLnCache(key) if err != nil { diff --git a/frontend/app/src/pages/tickets/TicketModalPage.tsx b/frontend/app/src/pages/tickets/TicketModalPage.tsx index 10ad53551..3fab46a00 100644 --- a/frontend/app/src/pages/tickets/TicketModalPage.tsx +++ b/frontend/app/src/pages/tickets/TicketModalPage.tsx @@ -38,7 +38,6 @@ export const TicketModalPage = observer(({ setConnectPerson }: Props) => { const [isDeleted, setisDeleted] = useState(false); const isMobile = useIsMobile(); - const { uuid } = useParams<{ uuid: string }>(); const search = useMemo(() => { const s = new URLSearchParams(location.search); diff --git a/frontend/app/src/pages/tickets/Tickets.tsx b/frontend/app/src/pages/tickets/Tickets.tsx index 4fd60dbc5..de7e33f68 100644 --- a/frontend/app/src/pages/tickets/Tickets.tsx +++ b/frontend/app/src/pages/tickets/Tickets.tsx @@ -3,23 +3,30 @@ import { observer } from 'mobx-react-lite'; import FirstTimeScreen from 'people/main/FirstTimeScreen'; import BountyHeader from 'people/widgetViews/BountyHeader'; import WidgetSwitchViewer from 'people/widgetViews/WidgetSwitchViewer'; -import React, { useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState } from 'react'; import { useHistory } from 'react-router'; +import { queryLimit } from 'store/main'; import { colors } from '../../config/colors'; import { useIsMobile } from '../../hooks'; import { useStores } from '../../store'; import { Body, Backdrop } from './style'; // avoid hook within callback warning by renaming hooks - function BodyComponent() { const { main, ui } = useStores(); const [loading, setLoading] = useState(true); const [showDropdown, setShowDropdown] = useState(false); const selectedWidget = 'wanted'; const [scrollValue, setScrollValue] = useState(false); - const [checkboxIdToSelectedMap, setCheckboxIdToSelectedMap] = useState({}); + const [checkboxIdToSelectedMap, setCheckboxIdToSelectedMap] = useState({ + Open: true, + Assigned: false, + Paid: false + }); const [checkboxIdToSelectedMapLanguage, setCheckboxIdToSelectedMapLanguage] = useState({}); + const [page, setPage] = useState(1); + const [currentItems, setCurrentItems] = useState(queryLimit); + const [totalBounties, setTotalBounties] = useState(0); const color = colors['light']; @@ -31,10 +38,10 @@ function BodyComponent() { await main.getOpenGithubIssues(); await main.getBadgeList(); await main.getPeople(); - await main.getPeopleBounties({ page: 1, resetPage: true }); + await main.getPeopleBounties({ page: 1, resetPage: true, ...checkboxIdToSelectedMap }); setLoading(false); })(); - }, [main]); + }, [main, checkboxIdToSelectedMap]); useEffect(() => { setCheckboxIdToSelectedMap({ @@ -50,6 +57,22 @@ function BodyComponent() { } }, [main, ui.meInfo]); + const getTotalBounties = useCallback( + async (statusData: any) => { + const totalBounties = await main.getTotalBountyCount( + statusData.Open, + statusData.Assigned, + statusData.Paid + ); + setTotalBounties(totalBounties); + }, + [main] + ); + + useEffect(() => { + getTotalBounties(checkboxIdToSelectedMap); + }, [getTotalBounties]); + const onChangeStatus = (optionId: any) => { const newCheckboxIdToSelectedMap = { ...checkboxIdToSelectedMap, @@ -58,6 +81,10 @@ function BodyComponent() { } }; setCheckboxIdToSelectedMap(newCheckboxIdToSelectedMap); + getTotalBounties(newCheckboxIdToSelectedMap); + // set data to default + setCurrentItems(queryLimit); + setPage(1); }; const onChangeLanguage = (optionId: any) => { @@ -129,6 +156,11 @@ function BodyComponent() { fromBountyPage={true} selectedWidget={selectedWidget} loading={loading} + totalBounties={totalBounties} + currentItems={currentItems} + setCurrentItems={setCurrentItems} + page={page} + setPage={setPage} /> @@ -191,6 +223,11 @@ function BodyComponent() { fromBountyPage={true} selectedWidget={selectedWidget} loading={loading} + totalBounties={totalBounties} + currentItems={currentItems} + setCurrentItems={setCurrentItems} + page={page} + setPage={setPage} /> diff --git a/frontend/app/src/people/utils/__test__/__mockData__/users.ts b/frontend/app/src/people/utils/__test__/__mockData__/users.ts index 6009d0202..2b28a3a14 100644 --- a/frontend/app/src/people/utils/__test__/__mockData__/users.ts +++ b/frontend/app/src/people/utils/__test__/__mockData__/users.ts @@ -1,75 +1,75 @@ -import { Person } from 'store/main'; - -export const users: Person[] = [ - { - id: 1, - pubkey: 'test_pub_key', - alias: '', - contact_key: 'test_owner_contact_key', - owner_route_hint: 'test_owner_route_hint', - unique_name: 'test 1', - tags: [], - photo_url: '', - route_hint: 'test_hint:1099567661057', - price_to_meet: 0, - url: 'https://mockApi.com', - description: 'description', - verification_signature: 'test_verification_signature', - extras: { - email: [{ value: 'testEmail@sphinx.com' }], - liquid: [{ value: 'none' }], - wanted: [], - coding_languages: [{ label: 'Typescript', value: 'Typescript' }] - }, - owner_alias: 'test 1', - owner_pubkey: 'test_pub_key', - img: '/static/avatarPlaceholders/placeholder_34.jpg' - }, - { - id: 2, - pubkey: 'test_pub_key', - alias: 'test 2', - contact_key: 'test_owner_contact_key', - owner_route_hint: 'test_owner_route_hint', - unique_name: 'test 2', - tags: [], - photo_url: '', - route_hint: 'test_hint:1099567661057', - price_to_meet: 0, - url: 'https://mockApi.com', - description: 'description', - verification_signature: 'test_verification_signature', - extras: { - email: [{ value: 'testEmail@sphinx.com' }], - liquid: [{ value: 'none' }], - wanted: [], - coding_languages: [{ label: 'Java', value: 'Java' }] - }, - owner_alias: 'test 2', - owner_pubkey: 'test_pub_key', - img: '/static/avatarPlaceholders/placeholder_34.jpg' - }, - { - id: 3, - pubkey: 'test_pub_key', - alias: 'test 3', - contact_key: 'test_owner_contact_key', - owner_route_hint: 'test_owner_route_hint', - unique_name: 'test 3', - tags: [], - photo_url: '', - route_hint: 'test_hint:1099567661057', - price_to_meet: 0, - url: 'https://mockApi.com', - description: 'description', - verification_signature: 'test_verification_signature', - extras: { - email: [{ value: 'testEmail@sphinx.com' }], - liquid: [{ value: 'none' }], - wanted: [] - }, - owner_alias: 'test 3', - owner_pubkey: 'test_pub_key', - img: '/static/avatarPlaceholders/placeholder_34.jpg' - } -]; +import { Person } from 'store/main'; + +export const users: Person[] = [ + { + id: 1, + pubkey: 'test_pub_key', + alias: '', + contact_key: 'test_owner_contact_key', + owner_route_hint: 'test_owner_route_hint', + unique_name: 'test 1', + tags: [], + photo_url: '', + route_hint: 'test_hint:1099567661057', + price_to_meet: 0, + url: 'https://mockApi.com', + description: 'description', + verification_signature: 'test_verification_signature', + extras: { + email: [{ value: 'testEmail@sphinx.com' }], + liquid: [{ value: 'none' }], + wanted: [], + coding_languages: [{ label: 'Typescript', value: 'Typescript' }] + }, + owner_alias: 'test 1', + owner_pubkey: 'test_pub_key', + img: '/static/avatarPlaceholders/placeholder_34.jpg' + }, + { + id: 2, + pubkey: 'test_pub_key', + alias: 'test 2', + contact_key: 'test_owner_contact_key', + owner_route_hint: 'test_owner_route_hint', + unique_name: 'test 2', + tags: [], + photo_url: '', + route_hint: 'test_hint:1099567661057', + price_to_meet: 0, + url: 'https://mockApi.com', + description: 'description', + verification_signature: 'test_verification_signature', + extras: { + email: [{ value: 'testEmail@sphinx.com' }], + liquid: [{ value: 'none' }], + wanted: [], + coding_languages: [{ label: 'Java', value: 'Java' }] + }, + owner_alias: 'test 2', + owner_pubkey: 'test_pub_key', + img: '/static/avatarPlaceholders/placeholder_34.jpg' + }, + { + id: 3, + pubkey: 'test_pub_key', + alias: 'test 3', + contact_key: 'test_owner_contact_key', + owner_route_hint: 'test_owner_route_hint', + unique_name: 'test 3', + tags: [], + photo_url: '', + route_hint: 'test_hint:1099567661057', + price_to_meet: 0, + url: 'https://mockApi.com', + description: 'description', + verification_signature: 'test_verification_signature', + extras: { + email: [{ value: 'testEmail@sphinx.com' }], + liquid: [{ value: 'none' }], + wanted: [] + }, + owner_alias: 'test 3', + owner_pubkey: 'test_pub_key', + img: '/static/avatarPlaceholders/placeholder_34.jpg' + } +]; diff --git a/frontend/app/src/people/utils/__test__/filterValidation.spec.ts b/frontend/app/src/people/utils/__test__/filterValidation.spec.ts index 34546362a..9c24e1ede 100644 --- a/frontend/app/src/people/utils/__test__/filterValidation.spec.ts +++ b/frontend/app/src/people/utils/__test__/filterValidation.spec.ts @@ -1,69 +1,69 @@ -import { bountyHeaderFilter, bountyHeaderLanguageFilter } from '../filterValidation'; -import filterByCodingLanguage from '../filterPeople'; -import { users } from '../__test__/__mockData__/users'; - -describe('testing filters', () => { - describe('bountyHeaderFilter', () => { - test('o/t/t', () => { - expect(bountyHeaderFilter({ Open: true }, true, true)).toEqual(false); - }); - test('a/t/t', () => { - expect(bountyHeaderFilter({ Assigned: true }, true, true)).toEqual(false); - }); - test('p/t/t', () => { - expect(bountyHeaderFilter({ Paid: true }, true, true)).toEqual(true); - }); - test('/t/t', () => { - expect(bountyHeaderFilter({}, true, true)).toEqual(true); - }); - test('o/f/t', () => { - expect(bountyHeaderFilter({ Open: true }, false, true)).toEqual(false); - }); - test('a/f/t', () => { - expect(bountyHeaderFilter({ Assigned: true }, false, true)).toEqual(true); - }); - test('p/f/t', () => { - expect(bountyHeaderFilter({ Paid: true }, false, true)).toEqual(false); - }); - }); - describe('bountyHeaderLanguageFilter', () => { - test('match', () => { - expect(bountyHeaderLanguageFilter(['Javascript', 'Python'], { Javascript: true })).toEqual( - true - ); - }); - test('no-match', () => { - expect( - bountyHeaderLanguageFilter(['Javascript'], { Python: true, Javascript: false }) - ).toEqual(false); - }); - test('no filters', () => { - expect(bountyHeaderLanguageFilter(['Javascript'], {})).toEqual(true); - }); - test('no languages', () => { - expect(bountyHeaderLanguageFilter([], { Javascript: true })).toEqual(false); - }); - test('false filters', () => { - expect( - bountyHeaderLanguageFilter(['Javascript'], { Javascript: false, Python: false }) - ).toEqual(true); - }); - }); - describe('peopleHeaderCodingLanguageFilters', () => { - test('match', () => { - expect(filterByCodingLanguage(users, { Typescript: true })).toStrictEqual([users[0]]); - }); - test('no_match', () => { - expect(filterByCodingLanguage(users, { Rust: true })).toStrictEqual([]); - }); - test('no filters', () => { - expect(filterByCodingLanguage(users, {})).toEqual(users); - }); - test('false filters', () => { - expect(filterByCodingLanguage(users, { PHP: false, MySQL: false })).toStrictEqual(users); - }); - test('no users', () => { - expect(filterByCodingLanguage([], { Typescript: true })).toStrictEqual([]); - }); - }); -}); +import { bountyHeaderFilter, bountyHeaderLanguageFilter } from '../filterValidation'; +import filterByCodingLanguage from '../filterPeople'; +import { users } from '../__test__/__mockData__/users'; + +describe('testing filters', () => { + describe('bountyHeaderFilter', () => { + test('o/t/t', () => { + expect(bountyHeaderFilter({ Open: true }, true, true)).toEqual(false); + }); + test('a/t/t', () => { + expect(bountyHeaderFilter({ Assigned: true }, true, true)).toEqual(false); + }); + test('p/t/t', () => { + expect(bountyHeaderFilter({ Paid: true }, true, true)).toEqual(true); + }); + test('/t/t', () => { + expect(bountyHeaderFilter({}, true, true)).toEqual(true); + }); + test('o/f/t', () => { + expect(bountyHeaderFilter({ Open: true }, false, true)).toEqual(false); + }); + test('a/f/t', () => { + expect(bountyHeaderFilter({ Assigned: true }, false, true)).toEqual(true); + }); + test('p/f/t', () => { + expect(bountyHeaderFilter({ Paid: true }, false, true)).toEqual(false); + }); + }); + describe('bountyHeaderLanguageFilter', () => { + test('match', () => { + expect(bountyHeaderLanguageFilter(['Javascript', 'Python'], { Javascript: true })).toEqual( + true + ); + }); + test('no-match', () => { + expect( + bountyHeaderLanguageFilter(['Javascript'], { Python: true, Javascript: false }) + ).toEqual(false); + }); + test('no filters', () => { + expect(bountyHeaderLanguageFilter(['Javascript'], {})).toEqual(true); + }); + test('no languages', () => { + expect(bountyHeaderLanguageFilter([], { Javascript: true })).toEqual(false); + }); + test('false filters', () => { + expect( + bountyHeaderLanguageFilter(['Javascript'], { Javascript: false, Python: false }) + ).toEqual(true); + }); + }); + describe('peopleHeaderCodingLanguageFilters', () => { + test('match', () => { + expect(filterByCodingLanguage(users, { Typescript: true })).toStrictEqual([users[0]]); + }); + test('no_match', () => { + expect(filterByCodingLanguage(users, { Rust: true })).toStrictEqual([]); + }); + test('no filters', () => { + expect(filterByCodingLanguage(users, {})).toEqual(users); + }); + test('false filters', () => { + expect(filterByCodingLanguage(users, { PHP: false, MySQL: false })).toStrictEqual(users); + }); + test('no users', () => { + expect(filterByCodingLanguage([], { Typescript: true })).toStrictEqual([]); + }); + }); +}); diff --git a/frontend/app/src/people/utils/filterPeople.ts b/frontend/app/src/people/utils/filterPeople.ts index 8e20fddd2..1ce50e8bd 100644 --- a/frontend/app/src/people/utils/filterPeople.ts +++ b/frontend/app/src/people/utils/filterPeople.ts @@ -1,22 +1,22 @@ -import { Person } from 'store/main'; - -interface CodingLanguage { - [language: string]: boolean; -} - -const filterByCodingLanguage = (users: Person[], codingLanguages: CodingLanguage) => { - const requiredLanguages = Object.keys(codingLanguages).filter( - (key: string) => codingLanguages[key] - ); - - return users.filter((user: Person) => { - const userCodingLanguages = (user.extras.coding_languages ?? []).map( - (t: { [key: string]: string }) => t.value - ); - return requiredLanguages?.every((requiredLanguage: string) => - userCodingLanguages.includes(requiredLanguage) - ); - }); -}; - -export default filterByCodingLanguage; +import { Person } from 'store/main'; + +interface CodingLanguage { + [language: string]: boolean; +} + +const filterByCodingLanguage = (users: Person[], codingLanguages: CodingLanguage) => { + const requiredLanguages = Object.keys(codingLanguages).filter( + (key: string) => codingLanguages[key] + ); + + return users.filter((user: Person) => { + const userCodingLanguages = (user.extras.coding_languages ?? []).map( + (t: { [key: string]: string }) => t.value + ); + return requiredLanguages?.every((requiredLanguage: string) => + userCodingLanguages.includes(requiredLanguage) + ); + }); +}; + +export default filterByCodingLanguage; diff --git a/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx b/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx index 34867467a..7d2ae0303 100644 --- a/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx +++ b/frontend/app/src/people/widgetViews/WidgetSwitchViewer.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useState } from 'react'; import styled from 'styled-components'; import { observer } from 'mobx-react-lite'; import { useIsMobile } from 'hooks/uiHooks'; @@ -6,7 +6,7 @@ import { queryLimit } from 'store/main'; import { Spacer } from '../main/Body'; import NoResults from '../utils/NoResults'; import { uiStore } from '../../store/ui'; -import { bountyHeaderFilter, bountyHeaderLanguageFilter } from '../utils/filterValidation'; +import { bountyHeaderLanguageFilter } from '../utils/filterValidation'; import { colors } from '../../config/colors'; import { useStores } from '../../store'; import { widgetConfigs } from '../utils/Constants'; @@ -76,9 +76,11 @@ function WidgetSwitchViewer(props: any) { const [deletePayload, setDeletePayload] = useState({}); const closeModal = () => setShowDeleteModal(false); const showModal = () => setShowDeleteModal(true); - const [page, setPage] = useState(1); - const [currentItems, setCurrentItems] = useState(queryLimit); - const [totalBounties, setTotalBounties] = useState(queryLimit); + const { currentItems, setCurrentItems, totalBounties, page: propsPage, setPage } = props; + + const items = currentItems ?? 0; + const bountiesTotal = totalBounties ?? 0; + const page = propsPage ?? 0; const panelStyles = isMobile ? { @@ -109,9 +111,9 @@ function WidgetSwitchViewer(props: any) { const activeList = [...listSource[selectedWidget]].filter(({ body }: any) => { const value = { ...body }; - return ( - bountyHeaderFilter(props?.checkboxIdToSelectedMap, value?.paid, !!value?.assignee) && - bountyHeaderLanguageFilter(value?.coding_languages, props?.checkboxIdToSelectedMapLanguage) + return bountyHeaderLanguageFilter( + value?.coding_languages, + props?.checkboxIdToSelectedMapLanguage ); }); @@ -156,21 +158,20 @@ function WidgetSwitchViewer(props: any) { closeModal(); }; - const getTotalBountiesCount = useCallback(async () => { - const totalBounties = await main.getTotalBountyCount(); - setTotalBounties(totalBounties); - }, [main]); - - useEffect(() => { - getTotalBountiesCount(); - }, [getTotalBountiesCount]); - const nextBounties = async () => { const currentPage = page + 1; - setPage(currentPage); - setCurrentItems(currentItems + queryLimit); + if (setPage) { + setPage(currentPage); + } - await main.getPeopleBounties({ limit: queryLimit, page: currentPage }); + if (setCurrentItems) { + setCurrentItems(currentItems + queryLimit); + } + await main.getPeopleBounties({ + limit: queryLimit, + page: currentPage, + ...props.checkboxIdToSelectedMap + }); }; const listItems = @@ -239,7 +240,7 @@ function WidgetSwitchViewer(props: any) { ) : ( ); - const showLoadMore = totalBounties > currentItems && activeList.length >= queryLimit; + const showLoadMore = bountiesTotal > items && activeList.length >= queryLimit; return ( <> {listItems} diff --git a/frontend/app/src/store/main.ts b/frontend/app/src/store/main.ts index 4a22b064c..256d69b85 100644 --- a/frontend/app/src/store/main.ts +++ b/frontend/app/src/store/main.ts @@ -1065,9 +1065,11 @@ export class MainStore { } } - async getTotalBountyCount(): Promise { + async getTotalBountyCount(open: boolean, assigned: boolean, paid: boolean): Promise { try { - const count = await api.get(`gobounties/count`); + const count = await api.get( + `gobounties/count?Open=${open}&Assigned=${assigned}&Paid=${paid}` + ); return await count; } catch (e) { console.log('fetch failed getTotalBountyCount: ', e); diff --git a/handlers/bounty.go b/handlers/bounty.go index e0dbc6315..d4e15e523 100644 --- a/handlers/bounty.go +++ b/handlers/bounty.go @@ -71,7 +71,7 @@ func GetUserBountyCount(w http.ResponseWriter, r *http.Request) { } func GetBountyCount(w http.ResponseWriter, r *http.Request) { - bountyCount := db.DB.GetBountiesCount() + bountyCount := db.DB.GetBountiesCount(r) w.WriteHeader(http.StatusOK) json.NewEncoder(w).Encode(bountyCount) }