Skip to content

Commit

Permalink
Merge pull request #430 from pennlabs/exclusive-view
Browse files Browse the repository at this point in the history
Exclusive view on H@P
  • Loading branch information
xiayufeilucy authored Apr 5, 2021
2 parents 847794a + 6892a7f commit a9c96a8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
12 changes: 8 additions & 4 deletions backend/clubs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,14 @@ def parse_many_to_many(label, field, value, operation, queryset):

if tags[0].isdigit() or operation == "id":
tags = [int(tag) for tag in tags if tag]
if settings.BRANDING == "fyh" and (
field == "target_years"
or field == "student_types"
or field == "target_schools"
if (
settings.BRANDING == "fyh"
and request.GET.get("viewType", "") == "exclusive"
and (
field == "target_years"
or field == "student_types"
or field == "target_schools"
)
):
queryset = queryset.annotate(
num_tags=Count(f"{field}", distinct=True)
Expand Down
57 changes: 52 additions & 5 deletions frontend/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { CLUB_RECRUITMENT_CYCLES } from 'components/ClubEditPage/ClubEditCard'
import ListRenewalDialog from 'components/ClubPage/ListRenewalDialog'
import LiveEventsDialog from 'components/ClubPage/LiveEventsDialog'
import { Icon, Metadata, Title, WideContainer } from 'components/common'
import {
Checkbox,
Icon,
Metadata,
Title,
WideContainer,
} from 'components/common'
import DisplayButtons from 'components/DisplayButtons'
import { FuseTag } from 'components/FilterSearch'
import { ActionLink } from 'components/Header/Feedback'
Expand Down Expand Up @@ -257,21 +263,29 @@ const Splash = (props: SplashProps): ReactElement => {
const [clubs, setClubs] = useState<PaginatedClubPage>(props.clubs)
const [isLoading, setLoading] = useState<boolean>(false)
const [searchInput, setSearchInput] = useState<SearchInput>({})
const [viewType, setViewType] = useState<string>('general')
const [currentViewType, setCurrentViewType] = useState<string>('general')
const [display, setDisplay] = useState<'cards' | 'list'>('cards')

useEffect((): void => {
if (equal(searchInput, currentSearch.current)) {
if (
equal(searchInput, currentSearch.current) &&
currentViewType === viewType
) {
return
}

currentSearch.current = { ...searchInput }

setLoading(true)

const params = new URLSearchParams()
params.set('format', 'json')
params.set('page', '1')

if (SITE_ID === 'fyh') {
params.set('viewType', viewType)
setCurrentViewType(viewType)
}

Object.entries(searchInput).forEach(([key, value]) => {
params.set(key, value)
})
Expand All @@ -286,7 +300,11 @@ const Splash = (props: SplashProps): ReactElement => {
setLoading(false)
}
})
}, [searchInput])
}, [searchInput, viewType])

const handleViewTypeChange = () => {
setViewType(viewType === 'general' ? 'exclusive' : 'general')
}

const tagOptions = useMemo<FuseTag[]>(
() =>
Expand Down Expand Up @@ -513,6 +531,35 @@ const Splash = (props: SplashProps): ReactElement => {
{' '}
{clubs.count} result{clubs.count === 1 ? '' : 's'}
</ResultsText>
{SITE_ID === 'fyh' && (
<div style={{ marginBottom: '5px' }}>
<span
style={{
marginRight: '10px',
}}
>
Exclusive View
</span>
<Checkbox
color={'black'}
checked={viewType === 'exclusive'}
onChange={handleViewTypeChange}
/>
<span
style={{
marginRight: '10px',
marginLeft: '20px',
}}
>
General View
</span>
<Checkbox
color={'black'}
checked={viewType === 'general'}
onChange={handleViewTypeChange}
/>
</div>
)}

<SearchTags
searchInput={searchInput}
Expand Down

0 comments on commit a9c96a8

Please sign in to comment.