-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
master1lan
committed
Jan 11, 2023
1 parent
e3f9829
commit 496f359
Showing
9 changed files
with
137 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { NavQueryItemType } from "@routers/layout/nav/tools"; | ||
| import { | ||
| useContext, | ||
| useState, | ||
| createContext, | ||
| useEffect, | ||
| ReactElement, | ||
| useReducer, | ||
| } from "react"; | ||
|
|
||
| type TagSelectProps = { | ||
| children: ReactElement; | ||
| }; | ||
| interface TagStates { | ||
| tags: NavQueryItemType[]; | ||
| } | ||
| enum TagsActionKind { | ||
| INCREASE = "INCREASE", | ||
| DECREASE = "DECREASE", | ||
| } | ||
| interface TagsAction { | ||
| type: TagsActionKind; | ||
| payload: NavQueryItemType; | ||
| } | ||
| const TagSelectContext = createContext< | ||
| TagStates & { | ||
| handerAddTag: (item: NavQueryItemType) => void; | ||
| handerDeleteTag: (item: NavQueryItemType) => void; | ||
| } | ||
| >({ | ||
| tags: [], | ||
| handerAddTag: () => {}, | ||
| handerDeleteTag: () => {}, | ||
| }); | ||
| function reducer(state: TagStates, action: TagsAction) { | ||
| const { type, payload } = action; | ||
| switch (type) { | ||
| case TagsActionKind.INCREASE: | ||
| return { tags: [...state.tags, payload] }; | ||
| case TagsActionKind.DECREASE: | ||
| return { tags: state.tags.filter((item) => item.id !== payload.id) }; | ||
| default: | ||
| return state; | ||
| } | ||
| } | ||
| const TagSelectProview = ({ children }: TagSelectProps) => { | ||
| const [tags, tagsDispath] = useReducer(reducer, { | ||
| tags: [] as NavQueryItemType[], | ||
| }), | ||
| handerAddTag = (item: NavQueryItemType) => | ||
| tagsDispath({ type: TagsActionKind.INCREASE, payload: item }), | ||
| handerDeleteTag = (item: NavQueryItemType) => | ||
| tagsDispath({ type: TagsActionKind.DECREASE, payload: item }); | ||
| return ( | ||
| <TagSelectContext.Provider | ||
| value={{ tags: tags.tags, handerAddTag, handerDeleteTag }} | ||
| > | ||
| {children} | ||
| </TagSelectContext.Provider> | ||
| ); | ||
| }; | ||
|
|
||
| export const useTagsSelected = () => useContext(TagSelectContext); | ||
|
|
||
| export default TagSelectProview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,18 @@ | ||
| import VideoMasonry from "./masonry"; | ||
| import { useTagsSelected } from "@components/proview/tagSelect"; | ||
| export default function VideoPage() { | ||
| const { tags } = useTagsSelected(), | ||
| qlists = tags | ||
| .filter((item) => item.queryType === "q") | ||
| .reduceRight((pre, cur) => { | ||
| return `${cur.queryString}+${pre}`; | ||
| }, ""), | ||
| q = qlists.length < 1 ? undefined : `tag.${qlists}`; | ||
| return ( | ||
| <> | ||
| <VideoMasonry /> | ||
| <VideoMasonry q={q} /> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| //todo 优化搜索设置 | ||
| //todo 添加上拉刷新 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters