Skip to content

Commit

Permalink
refactor(filter): sort filter
Browse files Browse the repository at this point in the history
  • Loading branch information
mydearxym committed Nov 14, 2023
1 parent 0c894f1 commit de45c15
Show file tree
Hide file tree
Showing 20 changed files with 125 additions and 187 deletions.
1 change: 1 addition & 0 deletions src/spec/article.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export type TArticleState =
| TArticleCatReject

export type TArticleCat = 'ALL' | 'BUG' | 'FEATURE' | 'QUESTION' | 'OTHER'
export type TArticleSort = 'ALL' | 'PUBLISH' | 'UPVOTE' | 'COMMENT' | 'VIEWS'

export type TArticlePubSelector = {
cat?: TArticleCat | null
Expand Down
1 change: 1 addition & 0 deletions src/spec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export type {
TArticleState,
TFAQSection,
TArticleTitle,
TArticleSort,
} from './article'

export type {
Expand Down
5 changes: 5 additions & 0 deletions src/spec/menu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export type TMenu =
| 'ARROW_TO_BOTTOM'
| 'SETTING'
| 'DELETE'
// sort
| 'PUBLISH'
| 'UPVOTE'
| 'COMMENT'
| 'VIEWS'
// commont
| 'TODO'
| 'WIP'
Expand Down
2 changes: 1 addition & 1 deletion src/spec/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@ export type TUploadPreview = {
radius: number
}

export type TConditionMode = 'state' | 'cat' | 'article' | 'tag'
export type TConditionMode = 'state' | 'cat' | 'sort' | 'tag'
57 changes: 27 additions & 30 deletions src/widgets/ArticlesFilter/DesktopView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
*
*/

import { FC, Fragment, useState } from 'react'
import { FC, useState } from 'react'
import { observer } from 'mobx-react-lite'
import dynamic from 'next/dynamic'

import type { TArticleCat, TArticleState } from '@/spec'
import type { TArticleCat, TArticleSort, TArticleState } from '@/spec'
import { PUBLISH_MODE } from '@/constant/publish'
import { CONDITION_MODE } from '@/constant/mode'

import { ARTICLE_CAT, ARTICLE_STATE } from '@/constant/gtd'
import { ARTICLE_SORT } from '@/constant/sort'
import TYPE from '@/constant/type'
import { BANNER_LAYOUT } from '@/constant/layout'
import useBannerLayout from '@/hooks/useBannerLayout'
Expand All @@ -24,10 +25,6 @@ import PublishButton from '@/widgets/Buttons/PublishButton'
import ConditionSelector from '@/widgets/ConditionSelector'
import SearchBox from '@/widgets/SearchBox'

import SortFilter from './SortFilter'
// import SelectedFilters from './SelectedFilters'
// import FilterResult from './FilterResult'

import type { TProps } from '.'
import { Wrapper } from './styles'

Expand All @@ -46,34 +43,34 @@ const ArticlesFilter: FC<TProps> = ({
}) => {
const bannerLayout = useBannerLayout()
const [activeCat, setActiveCat] = useState<TArticleCat>(ARTICLE_CAT.ALL)
const [activeSort, setActiveSort] = useState<TArticleSort>(ARTICLE_SORT.ALL)
const [activeState, setActiveState] = useState<TArticleState>(ARTICLE_STATE.ALL)

const searchMode = false

return (
<Wrapper>
{!searchMode && (
<Fragment>
<SortFilter onSelect={onSelect} activeFilter={activeFilter} />
<ConditionSelector
mode={CONDITION_MODE.CAT}
active={activeCat}
onSelect={(cat: TArticleCat) => setActiveCat(cat)}
selected={activeCat !== ARTICLE_CAT.ALL}
/>
<ConditionSelector
mode={CONDITION_MODE.STATE}
active={activeState}
onSelect={(state: TArticleState) => setActiveState(state)}
selected={activeState !== ARTICLE_STATE.ALL}
/>
<Space right={10} />
<SpaceGrow />
<DesktopOnly>
{resState === TYPE.RES_STATE.LOADING && <LavaLampLoading right={28} left={10} />}
</DesktopOnly>
</Fragment>
)}
<ConditionSelector
mode={CONDITION_MODE.SORT}
active={activeSort}
onSelect={(sort: TArticleSort) => setActiveSort(sort)}
selected={activeSort !== ARTICLE_SORT.ALL}
/>
<ConditionSelector
mode={CONDITION_MODE.CAT}
active={activeCat}
onSelect={(cat: TArticleCat) => setActiveCat(cat)}
selected={activeCat !== ARTICLE_CAT.ALL}
/>
<ConditionSelector
mode={CONDITION_MODE.STATE}
active={activeState}
onSelect={(state: TArticleState) => setActiveState(state)}
selected={activeState !== ARTICLE_STATE.ALL}
/>
<Space right={10} />
<SpaceGrow />
<DesktopOnly>
{resState === TYPE.RES_STATE.LOADING && <LavaLampLoading right={28} left={10} />}
</DesktopOnly>
{bannerLayout === BANNER_LAYOUT.SIDEBAR && <SearchBox right={8} />}
{bannerLayout === BANNER_LAYOUT.SIDEBAR && (
<PublishButton
Expand Down
7 changes: 0 additions & 7 deletions src/widgets/ArticlesFilter/MobileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ import { buildLog } from '@/logger'
import { SpaceGrow } from '@/widgets/Common'

import ConditionSelector from '@/widgets/ConditionSelector'
import TagSelector from '@/widgets/TagSelector'
import SearchBox from '@/widgets/SearchBox'

import SortFilter from './SortFilter'
// import SelectedFilters from './SelectedFilters'
// import FilterResult from './FilterResult'

import type { TProps } from '.'
import { Wrapper } from './styles/mobile_view'

Expand All @@ -48,8 +43,6 @@ const ArticlesFilter: FC<TProps> = ({
<Wrapper>
{!searchMode && (
<Fragment>
<SortFilter onSelect={onSelect} activeFilter={activeFilter} />
<TagSelector groupedTags={groupedTags} activeTag={activeTag} mode="mobile" />
<ConditionSelector
mode={CONDITION_MODE.CAT}
selected={false}
Expand Down
4 changes: 0 additions & 4 deletions src/widgets/ArticlesFilter/ModelineView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import TYPE from '@/constant/type'
import { buildLog } from '@/logger'

import { Space } from '@/widgets/Common'
import TagSelector from '@/widgets/TagSelector'

import SortFilter from './SortFilter'
// import SelectedFilters from './SelectedFilters'
// import FilterResult from './FilterResult'

Expand All @@ -39,9 +37,7 @@ const ArticlesFilter: FC<TProps> = ({

return (
<ModelineWrapper>
<TagSelector groupedTags={groupedTags} activeTag={activeTag} mode="modeline" />
<Space right={6} />
<SortFilter onSelect={onSelect} activeFilter={activeFilter} placement="top-start" />

{/* <SearchBox searchMode={searchMode} onSearch={onSearch} closeSearch={closeSearch} /> */}
</ModelineWrapper>
Expand Down
57 changes: 0 additions & 57 deletions src/widgets/ArticlesFilter/SelectedFilters.tsx

This file was deleted.

46 changes: 0 additions & 46 deletions src/widgets/ArticlesFilter/SortFilter.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion src/widgets/ArticlesFilter/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Input from '@/widgets/Input'
export const Wrapper = styled.div`
${css.row('align-center')};
width: 100%;
margin-bottom: 8px;
margin-bottom: 4px;
margin-left: -10px;
${css.media.mobile`
display: none;
Expand Down
10 changes: 9 additions & 1 deletion src/widgets/ConditionSelector/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { find } from 'ramda'

import type { TConditionMode } from '@/spec'
import { CONDITION_MODE } from '@/constant/mode'
import { POST_STATE_MENU_ITEMS, POST_CAT_MENU_ITEMS } from '@/constant/menu'
import { POST_STATE_MENU_ITEMS, POST_CAT_MENU_ITEMS, POST_SORT_MENU_ITEMS } from '@/constant/menu'

import type { TMenuItem, TActiveCondition } from './spec'

Expand All @@ -16,6 +16,10 @@ export const getMenuItems = (mode: TConditionMode): TMenuItem[] => {
return POST_CAT_MENU_ITEMS
}

case CONDITION_MODE.SORT: {
return POST_SORT_MENU_ITEMS
}

default: {
return []
}
Expand All @@ -36,6 +40,10 @@ export const getTitle = (mode: TConditionMode): string => {
return '类别'
}

case CONDITION_MODE.SORT: {
return '排序'
}

default: {
return '??'
}
Expand Down
5 changes: 2 additions & 3 deletions src/widgets/ConditionSelector/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ActiveLabel from './ActiveLabel'

import type { TActiveCondition } from './spec'
import { getMenuItems, getTitle, getActiveMenuItem } from './helper'
import { FilterWrapper } from './styles'
import { Wrapper } from './styles'

type TProps = {
mode: TConditionMode
Expand All @@ -34,7 +34,6 @@ const ConditionSelector: FC<TProps> = ({
const [menuOpen, setMenuOpen] = useState(false)
const ref = useRef(null)

const Wrapper = FilterWrapper
const popWidth = 120

const menuItems = getMenuItems(mode)
Expand All @@ -45,7 +44,7 @@ const ConditionSelector: FC<TProps> = ({
const title = getTitle(mode)

return (
<Wrapper $selected={selected} $menuOpen={menuOpen} {...restProps} ref={ref}>
<Wrapper ref={ref} $selected={selected} $menuOpen={menuOpen} {...restProps}>
{!selected ? (
<Menu
offset={offset as [number, number]}
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/ConditionSelector/spec.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { TArticleState, TArticleCat, TMenu } from '@/spec'
import type { TArticleState, TArticleCat, TMenu, TArticleSort } from '@/spec'

export type TActiveCondition = TArticleState | TArticleCat | 'ALL'
export type TActiveCondition = TArticleState | TArticleCat | TArticleSort | 'ALL'

export type TMenuItem = {
key: string
Expand Down
1 change: 1 addition & 0 deletions src/widgets/ConditionSelector/styles/active_label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const Hint = styled.div`
export const LabelWrapper = styled.div`
${css.row('align-center')};
padding: 5px 6px;
padding-right: 8px;
border-radius: 8px;
background: ${theme('hoverActive')};
margin-left: 3px;
Expand Down
19 changes: 1 addition & 18 deletions src/widgets/ConditionSelector/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import css, { theme } from '@/css'
import { WithMargin } from '@/widgets/Common'

type TWrapper = { $menuOpen?: boolean; $selected?: boolean }
export const FilterWrapper = styled(WithMargin)<TWrapper>`
export const Wrapper = styled(WithMargin)<TWrapper>`
${css.row('align-center')};
color: ${theme('article.digest')};
font-size: 13px;
Expand All @@ -23,23 +23,6 @@ export const FilterWrapper = styled(WithMargin)<TWrapper>`
background: ${theme('hoverBg')};
}
`
export const FullWrapper = styled(FilterWrapper)<TWrapper>`
border: 1px solid;
border-color: ${({ $menuOpen }) =>
$menuOpen ? theme('article.digest') : theme('button.ghostBorder')};
padding: 0 5px;
padding-left: 15px;
border-radius: 10px;
&:hover {
border-color: ${theme('article.digest')};
cursor: pointer;
}
transition: all 0.2s;
`

export const SelectItem = styled.div<TActive>`
${css.row('align-start')};
padding: 4px 8px;
Expand Down
Loading

0 comments on commit de45c15

Please sign in to comment.