From dfba0ec4847b7c85aceb28aed76b11072c66d79e Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Tue, 12 Dec 2023 21:56:44 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Move=20mockData=20to?= =?UTF-8?q?=20the=20API=20directory=20and=20implement=20Redux=20integratio?= =?UTF-8?q?n=20with=20the=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Group/GroupList/GroupCard.jsx | 10 +- .../Group/GroupList/GroupCard.styled.jsx | 6 +- components/Group/GroupList/index.jsx | 70 +- components/Group/More.jsx | 33 + components/Group/index.jsx | 63 +- constants/areas.js | 46 +- constants/category.js | 12 + pages/api/__mocks__/group.mock.json | 662 ++++++++++++++++++ pages/api/group/index.js | 64 ++ public/assets/empty-cover.png | Bin 0 -> 2552 bytes redux/actions/group.js | 37 + redux/reducers/group.js | 57 ++ redux/reducers/index.js | 2 + redux/sagas/groupSaga.js | 27 + redux/sagas/index.js | 9 +- 15 files changed, 999 insertions(+), 99 deletions(-) create mode 100644 components/Group/More.jsx create mode 100644 pages/api/__mocks__/group.mock.json create mode 100644 pages/api/group/index.js create mode 100644 public/assets/empty-cover.png create mode 100644 redux/actions/group.js create mode 100644 redux/reducers/group.js create mode 100644 redux/sagas/groupSaga.js diff --git a/components/Group/GroupList/GroupCard.jsx b/components/Group/GroupList/GroupCard.jsx index c7d70b57..bc991255 100644 --- a/components/Group/GroupList/GroupCard.jsx +++ b/components/Group/GroupList/GroupCard.jsx @@ -1,5 +1,6 @@ import LocationOnOutlinedIcon from '@mui/icons-material/LocationOnOutlined'; import Image from '@/shared/components/Image'; +import emptyCoverImg from '@/public/assets/empty-cover.png'; import { StyledAreas, StyledContainer, @@ -19,10 +20,11 @@ function GroupCard({ partnerEducationStep, description, area, + isGrouping, }) { return ( - {photoAlt} + {photoAlt {title} @@ -44,7 +46,11 @@ function GroupCard({ -
揪團中
+ {isGrouping ? ( +
揪團中
+ ) : ( +
已結束
+ )}
diff --git a/components/Group/GroupList/GroupCard.styled.jsx b/components/Group/GroupList/GroupCard.styled.jsx index d4fff45c..4c3dd3cf 100644 --- a/components/Group/GroupList/GroupCard.styled.jsx +++ b/components/Group/GroupList/GroupCard.styled.jsx @@ -20,6 +20,10 @@ export const StyledTitle = styled.h2` font-size: 14px; font-weight: bold; line-height: 1.4; + display: -webkit-box; + -webkit-box-orient: vertical; + -webkit-line-clamp: 1; + overflow: hidden; `; export const StyledInfo = styled.div` @@ -66,7 +70,7 @@ export const StyledFooter = styled.footer` border-radius: 50%; } - &.end { + &.finished { --bg-color: #f3f3f3; --color: #92989a; } diff --git a/components/Group/GroupList/index.jsx b/components/Group/GroupList/index.jsx index be9c4ccf..4b547cab 100644 --- a/components/Group/GroupList/index.jsx +++ b/components/Group/GroupList/index.jsx @@ -1,4 +1,12 @@ +import { useEffect } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; import styled from '@emotion/styled'; +import { Box } from '@mui/material'; +import { AREAS } from '@/constants/areas'; +import { CATEGORIES } from '@/constants/category'; +import { EDUCATION_STEP } from '@/constants/member'; +import useSearchParamsManager from '@/hooks/useSearchParamsManager'; +import { setQuery } from '@/redux/actions/group'; import GroupCard from './GroupCard'; export const StyledGroupItem = styled.li` @@ -50,21 +58,57 @@ const StyledGroupList = styled.ul` justify-content: space-between; `; -function GroupList({ list, isLoading }) { +function GroupList() { + const dispatch = useDispatch(); + const [getSearchParams] = useSearchParamsManager(); + const { items, isLoading } = useSelector((state) => state.group); + + useEffect(() => { + const filterOptions = { + area: AREAS, + category: CATEGORIES, + edu: EDUCATION_STEP, + grouping: true, + q: true, + }; + const params = {}; + const searchParams = getSearchParams(); + Object.keys(filterOptions).forEach((key) => { + const searchParam = searchParams[key]; + const options = filterOptions[key]; + + if (searchParam && options) { + params[key] = Array.isArray(options) + ? searchParam + .split(',') + .filter((item) => options.some((option) => option.label === item)) + .join(',') + : searchParam; + } + }); + dispatch(setQuery(params)); + }, [getSearchParams]); + return ( - - {list?.length || isLoading ? ( - list.map((data) => ( - - - - )) - ) : ( -
  • - 哎呀!這裡好像沒有符合你條件的揪團,別失望!讓我們試試其他選項。 -
  • + <> + + {items?.length || isLoading ? ( + items.map((data) => ( + + + + )) + ) : ( +
  • + 哎呀!這裡好像沒有符合你條件的揪團,別失望!讓我們試試其他選項。 +
  • + )} +
    + + {isLoading && ( + 搜尋揪團中~ )} -
    + ); } diff --git a/components/Group/More.jsx b/components/Group/More.jsx new file mode 100644 index 00000000..9ab883be --- /dev/null +++ b/components/Group/More.jsx @@ -0,0 +1,33 @@ +import { useDispatch, useSelector } from 'react-redux'; +import { Box, Button } from '@mui/material'; +import { setLimit } from '@/redux/actions/group'; + +export default function More() { + const dispatch = useDispatch(); + const { limit, total, isLoading } = useSelector((state) => state.group); + const isMore = total > limit || isLoading; + + return ( + + {isMore ? ( + + ) : ( + '已經到底囉~' + )} + + ); +} diff --git a/components/Group/index.jsx b/components/Group/index.jsx index 7489b305..6ee2bed2 100644 --- a/components/Group/index.jsx +++ b/components/Group/index.jsx @@ -1,11 +1,11 @@ -import { useEffect, useState } from 'react'; import styled from '@emotion/styled'; -import { Box, Button } from '@mui/material'; +import { Box } from '@mui/material'; import AreaChips from './AreaChips'; import Banner from './Banner'; import SearchField from './SearchField'; import SelectedCategory from './SelectedCategory'; import GroupList from './GroupList'; +import More from './More'; const StyledGroup = styled.div` position: relative; @@ -30,41 +30,7 @@ const ContainerWrapper = styled(Box)` z-index: 2; `; -const createTemplate = (_, id) => ({ - id, - title: '颱風天不衝浪要幹嘛', - photoURL: - 'https://images.unsplash.com/photo-1502680390469-be75c86b636f?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxzZWFyY2h8Mnx8c3VyZnxlbnwwfHwwfHw%3D&auto=format&fit=crop&w=800&q=60', - photoAlt: '封面圖', - category: ['語言與文學', '人文社會', '自然科學', '生活'], - partnerEducationStep: '高中', - description: - '希望能像朋友,一起讀有興趣的科目,每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!', - area: '台北市', -}); - -const mockData = (length) => - new Promise((res) => - setTimeout(() => { - res(Array.from({ length }, createTemplate)); - }, 600), - ); - function Group() { - const [total, setTotal] = useState(12); - const [list, setList] = useState([]); - const [isLoading, setIsLoading] = useState(true); - - useEffect(() => { - const setDataAndLoaded = (data) => { - setList(data); - setIsLoading(false); - }; - - setIsLoading(true); - mockData(total).then(setDataAndLoaded); - }, [total]); - return ( @@ -75,31 +41,10 @@ function Group() { - - {isLoading && ( - - 搜尋揪團中~ - - )} + - - - + ); } diff --git a/constants/areas.js b/constants/areas.js index 18384fa2..c9a31cec 100644 --- a/constants/areas.js +++ b/constants/areas.js @@ -1,25 +1,25 @@ export const AREAS = [ - { name: '線上' }, - { name: '臺北市' }, - { name: '新北市' }, - { name: '基隆市' }, - { name: '桃園市' }, - { name: '新竹市' }, - { name: '新竹縣' }, - { name: '苗栗縣' }, - { name: '臺中市' }, - { name: '南投縣' }, - { name: '彰化縣' }, - { name: '雲林縣' }, - { name: '嘉義市' }, - { name: '嘉義縣' }, - { name: '臺南市' }, - { name: '高雄市' }, - { name: '屏東縣' }, - { name: '臺東縣' }, - { name: '花蓮縣' }, - { name: '宜蘭縣' }, - { name: '澎湖縣' }, - { name: '金門縣' }, - { name: '連江縣' }, + { name: '線上', label: '線上' }, + { name: '台北市', label: '台北市' }, + { name: '新北市', label: '新北市' }, + { name: '基隆市', label: '基隆市' }, + { name: '桃園市', label: '桃園市' }, + { name: '新竹市', label: '新竹市' }, + { name: '新竹縣', label: '新竹縣' }, + { name: '苗栗縣', label: '苗栗縣' }, + { name: '台中市', label: '台中市' }, + { name: '南投縣', label: '南投縣' }, + { name: '彰化縣', label: '彰化縣' }, + { name: '雲林縣', label: '雲林縣' }, + { name: '嘉義市', label: '嘉義市' }, + { name: '嘉義縣', label: '嘉義縣' }, + { name: '台南市', label: '台南市' }, + { name: '高雄市', label: '高雄市' }, + { name: '屏東縣', label: '屏東縣' }, + { name: '台東縣', label: '台東縣' }, + { name: '花蓮縣', label: '花蓮縣' }, + { name: '宜蘭縣', label: '宜蘭縣' }, + { name: '澎湖縣', label: '澎湖縣' }, + { name: '金門縣', label: '金門縣' }, + { name: '連江縣', label: '連江縣' }, ]; diff --git a/constants/category.js b/constants/category.js index 79629194..2cef3c9d 100644 --- a/constants/category.js +++ b/constants/category.js @@ -62,50 +62,62 @@ export const SEARCH_TAGS = { export const CATEGORIES = [ { key: 'language', + label: '語言與文學', value: '語言與文學', }, { key: 'math', + label: '數學與邏輯', value: '數學與邏輯', }, { key: 'comsci', + label: '資訊與工程', value: '資訊與工程', }, { key: 'humanity', + label: '人文社會', value: '人文社會', }, { key: 'natusci', + label: '自然科學', value: '自然科學', }, { key: 'art', + label: '藝術', value: '藝術', }, { key: 'education', + label: '教育', value: '教育', }, { key: 'life', + label: '生活', value: '生活', }, { key: 'health', + label: '運動/心理/醫學', value: '運動/心理/醫學', }, { key: 'business', + label: '商業與社會創新', value: '商業與社會創新', }, { key: 'multires', + label: '綜合型學習資源', value: '綜合型學習資源', }, { key: 'learningtools', + label: '學習/教學工具', value: '學習/教學工具', }, ]; diff --git a/pages/api/__mocks__/group.mock.json b/pages/api/__mocks__/group.mock.json new file mode 100644 index 00000000..d30e942d --- /dev/null +++ b/pages/api/__mocks__/group.mock.json @@ -0,0 +1,662 @@ +[ + { + "id": "00001", + "title": "文學少女讀書會", + "photoURL": "https://images.unsplash.com/photo-1558021212-51b6ecfa0db9?q=80&w=1783&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", + "photoAlt": "封面圖", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "新北市、台北市、線上", + "isGrouping": true + }, + { + "id": "00002", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "https://images.unsplash.com/photo-1674027444454-97b822a997b6?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", + "photoAlt": "封面圖", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "線上", + "isGrouping": false + }, + { + "id": "00003", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "https://images.unsplash.com/photo-1583526241256-cb18e8635e5b?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", + "photoAlt": "封面圖", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00004", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "嘉義縣、線上", + "isGrouping": true + }, + { + "id": "00005", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "新竹縣、新竹市", + "isGrouping": true + }, + { + "id": "00006", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "基隆市、新北市、台北市", + "isGrouping": true + }, + { + "id": "00007", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "高雄市", + "isGrouping": true + }, + { + "id": "00008", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "澎湖縣、線上", + "isGrouping": true + }, + { + "id": "00009", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "新北市、台北市、線上", + "isGrouping": true + }, + { + "id": "00010", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "線上", + "isGrouping": true + }, + { + "id": "00011", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00012", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "嘉義縣、線上", + "isGrouping": false + }, + { + "id": "00013", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "新竹縣、新竹市", + "isGrouping": true + }, + { + "id": "00014", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "基隆市、新北市、台北市", + "isGrouping": true + }, + { + "id": "00015", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "高雄市", + "isGrouping": true + }, + { + "id": "00016", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "澎湖縣、線上", + "isGrouping": true + }, + { + "id": "00017", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "新北市、台北市、線上", + "isGrouping": true + }, + { + "id": "00018", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "線上", + "isGrouping": true + }, + { + "id": "00019", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00020", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "嘉義縣、線上", + "isGrouping": true + }, + { + "id": "00021", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "新竹縣、新竹市", + "isGrouping": true + }, + { + "id": "00022", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "基隆市、新北市、台北市", + "isGrouping": true + }, + { + "id": "00023", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "高雄市", + "isGrouping": true + }, + { + "id": "00024", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "澎湖縣、線上", + "isGrouping": true + }, + { + "id": "00025", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "新北市、台北市、線上", + "isGrouping": true + }, + { + "id": "00026", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "線上", + "isGrouping": false + }, + { + "id": "00027", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00028", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "嘉義縣、線上", + "isGrouping": true + }, + { + "id": "00029", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "新竹縣、新竹市", + "isGrouping": true + }, + { + "id": "00030", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "基隆市、新北市、台北市", + "isGrouping": true + }, + { + "id": "00031", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "高雄市", + "isGrouping": true + }, + { + "id": "00032", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "澎湖縣、線上", + "isGrouping": false + }, + { + "id": "00033", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "新北市、台北市、線上", + "isGrouping": false + }, + { + "id": "00034", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "線上", + "isGrouping": false + }, + { + "id": "00035", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00036", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "嘉義縣、線上", + "isGrouping": true + }, + { + "id": "00037", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "新竹縣、新竹市", + "isGrouping": true + }, + { + "id": "00038", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "基隆市、新北市、台北市", + "isGrouping": true + }, + { + "id": "00039", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "高雄市", + "isGrouping": true + }, + { + "id": "00040", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "澎湖縣、線上", + "isGrouping": true + }, + { + "id": "00041", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "新北市、台北市、線上", + "isGrouping": true + }, + { + "id": "00042", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "線上", + "isGrouping": true + }, + { + "id": "00043", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00044", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "嘉義縣、線上", + "isGrouping": true + }, + { + "id": "00045", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "新竹縣、新竹市", + "isGrouping": true + }, + { + "id": "00046", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "基隆市、新北市、台北市", + "isGrouping": true + }, + { + "id": "00047", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "高雄市", + "isGrouping": true + }, + { + "id": "00048", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "澎湖縣、線上", + "isGrouping": true + }, + { + "id": "00049", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "新北市、台北市、線上", + "isGrouping": true + }, + { + "id": "00050", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "線上", + "isGrouping": true + }, + { + "id": "00051", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00052", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "嘉義縣、線上", + "isGrouping": true + }, + { + "id": "00053", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "新竹縣、新竹市", + "isGrouping": true + }, + { + "id": "00054", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "基隆市、新北市、台北市", + "isGrouping": true + }, + { + "id": "00055", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "高雄市", + "isGrouping": true + }, + { + "id": "00056", + "title": "文學少女讀書會", + "photoURL": "", + "photoAlt": "", + "category": ["語言與文學", "人文社會"], + "partnerEducationStep": "高中", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "澎湖縣、線上", + "isGrouping": true + }, + { + "id": "00057", + "title": "尋找北北基線上自學程式、AI的小夥伴們", + "photoURL": "", + "photoAlt": "", + "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], + "partnerEducationStep": "國中", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "新北市、台北市、線上", + "isGrouping": true + }, + { + "id": "00058", + "title": "Smart Reading 科普閱讀力大賽 徵人中", + "photoURL": "", + "photoAlt": "", + "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], + "partnerEducationStep": "大學", + "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", + "area": "線上", + "isGrouping": true + }, + { + "id": "00059", + "title": "【秋季】木工課+釣魚+野外技能學習", + "photoURL": "", + "photoAlt": "", + "category": ["藝術", "自然科學", "生活"], + "partnerEducationStep": "其他", + "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", + "area": "南投縣", + "isGrouping": true + }, + { + "id": "00060", + "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", + "photoURL": "", + "photoAlt": "", + "category": ["人文社會", "運動/心理/醫學", "生活"], + "partnerEducationStep": "其他", + "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", + "area": "嘉義縣、線上", + "isGrouping": true + } +] diff --git a/pages/api/group/index.js b/pages/api/group/index.js new file mode 100644 index 00000000..46ebe7b2 --- /dev/null +++ b/pages/api/group/index.js @@ -0,0 +1,64 @@ +import groupMockData from '../__mocks__/group.mock.json'; + +/** + * 根據傳入的條件進行篩選 + * @param {string[]} itemValue - 資料的值 + * @param {string[]} conditionValue - 篩選條件的值 + * @returns {boolean} - 是否符合保留條件 + */ +function filterBy(itemValue, conditionValue = []) { + return ( + !conditionValue.length || + conditionValue.every((cond) => itemValue.includes(cond)) + ); +} + +function checkInvalidParameter(req, res, requiredParams) { + const params = requiredParams.filter((param) => !req.query[param]); + + if (params.length) { + res.status(400).json({ + message: 'Invalid parameter', + params, + }); + return true; + } + + return false; +} + +/** + * 揪團 mock api + * @param {import("next").NextApiRequest} req request 請求 + * @param {import("next").NextApiResponse} res response 回應 + */ +export default function handler(req, res) { + switch (req.method) { + case 'GET': { + if (checkInvalidParameter(req, res, ['limit'])) return; + + try { + const { limit, q, edu, area, category, grouping } = req.query; + const isGrouping = grouping === 'true'; + const end = Number(limit); + const filterData = groupMockData + .filter((item) => !q || item.title.includes(q)) + .filter((item) => !edu || edu.includes(item.partnerEducationStep)) + .filter((item) => !grouping || item.isGrouping === isGrouping) + .filter((item) => filterBy(item.area.split('、'), area?.split(','))) + .filter((item) => filterBy(item.category, category?.split(','))); + + const items = filterData.slice(0, end); + + res.status(200).json({ + items, + total: filterData.length, + }); + } catch (err) { + res.status(500).json({ message: err.message }); + } + break; + } + default: + } +} diff --git a/public/assets/empty-cover.png b/public/assets/empty-cover.png new file mode 100644 index 0000000000000000000000000000000000000000..785b7dd0f364f4473a6bde0b5574946f524d9175 GIT binary patch literal 2552 zcmZ`*XHb*b8vdvOBq0<535FoZvJnBPS(?%WM4A+32~B#HrZibv5RhI3q_coZiN@z#xuu>gR7o3(3XaG@ghm?*lb8;U1omp=1``*j^67Wd&`N>Hz zesTLZujhYzWv!Xrg?2Zh{L_O_h@ zoX=6JKx3@TSXsj2A5q5>P*I>2%HF$HvE8Pj3^XPnIL_QzB!8SKp??Hon5j&+5@ln772(&tjQvtV0sH1lj#Dq?J;zB;zakmT&n67Vp?LHMP06QU_dfGDM~Ewz?M z0dieVWcA8*+w{F$7elmIiNBAOX0ZN^WMs`)aHgs8HEAIzoNM1!`5SJ%yXUmzk zr2=CK$1&e?4xR)fYG_U5pH>!+Q}IYDI31M`%nUgc=LuS|szn zK>Y8AxQ59vDKaLsGTn&KCK0B)_mreKMy<@Y{^Z%eU6+BcP*ks-Q z`nqo+ZK)s!A6*Pro2OI}j?R5M6;M-}2d(n@ryLpVhSK#uM=4dvjz@Jl`g|OGGJ_x+ z{WHN^i6m_4N$;~>-{DEmn{J;PHnYE{(%#t0Js&ow ze9{C-#Zbt#<3dYK%XMT)lwGmK_{`O(=9dYTx648bJKF7Q1@G5pAp2$dOCKeF6vP;q zxRzUr1X`NrS{qNgqnkIugi5JHnExM9F!YvPERq+lyg?k@AzEYg(ro#YzChv1nKe`I zW6e&bx=d(1REzkDEFZ;xFd(E}*hKk;>~L|2J(^PiCq}hk$!|Rj_3IU$Nug0%-e>Kl z|FUBlR||zl=BYh#+q^L^XoaCs6hHL~4|U<27FaGKG!C{t_L@a>%m`90?*6WsB6^Z( zR=MhMfb5U%#FX(D94)qBhL%Hj^a8`nPs1)AZgmX~6hE2kkaSQn%F{HBwdaLL9=NMq z{plxD zl214?G<&W8)9MPnV;e@Tn7H7wTdGl`nocO<5BRH{9lp?DLQ0xNt@Fa~?7ugP3DL0K zmbPzliPYN6!wvR-z*B&|iud`7!uhHKYl4t2rxGGWQYGCt?DN6EmR)nh=$!>tD*G}@ zq48)+rG4GLtsza~<~A~iTrpk0_g$x!N2^7F~ACaf=Y;1qoM67=%SUh1rlUMI3rqosHJY>&C4 zzRdVIw6Ep0q}g1cXe6(w4oR2fF)!=#N#B2ARZ%WZH+7gk_+Yt-g`is_blgV5q1Slz zRY}IRSy_oK{Ct=B{RtZx1Yga)dwynm|L^9l;s)C|6A6=C7peF@A7HMp@F`>Q5uy>M)+ zX>hc)TAiNg@4X~N=nGtdI0W4&1i1hntuyV9>eBrN9wb@)%wPj*yO=w<`CKl#^<{`I zPCTH~ZK)iNN$kT4A|c=D3O;MHA_}Mo_b%kGe|^Z><7rQz1x(a7W`dJuDN$KFcbb={ z*h2kQnA@Q6^z5Yv5UvjP<;PQ4^*Q6ozl^tz(bOrk<%htnNC@vl$Wr(6cOCO{x7#N#U( zA~qi`w(yDOL#)NTC?m69Bu!hpy@et$2Ju6~+t)fNCTBNgxl4x#jo~wY@cE|=ufFJnZ5fK7yLPX1l~kSJRDgLwKrVONmW40=B=;i$*`cHqcM-$9th9Ocd(JWzA}nqENXy}zNsEo$0_bVEMd|a literal 0 HcmV?d00001 diff --git a/redux/actions/group.js b/redux/actions/group.js new file mode 100644 index 00000000..6891f4e0 --- /dev/null +++ b/redux/actions/group.js @@ -0,0 +1,37 @@ +export const DEFAULT_LIMIT = 12; +export const SET_LIMIT = 'SET_LIMIT'; +export const SET_QUERY = 'SET_QUERY'; +export const GET_GROUP_ITEMS_SUCCESS = 'GET_GROUP_ITEMS_SUCCESS'; +export const GET_GROUP_ITEMS_FAILURE = 'GET_GROUP_ITEMS_FAILURE'; + +export function setLimit(limit) { + return { + type: SET_LIMIT, + payload: { + limit, + }, + }; +} + +export function setQuery(query = {}) { + return { + type: SET_QUERY, + payload: { + query, + }, + }; +} + +export function getGroupItemsSuccess({ items = [], total = 0 } = {}) { + return { + type: GET_GROUP_ITEMS_SUCCESS, + payload: { + items, + total, + }, + }; +} + +export function getGroupItemsError(payload) { + return { type: GET_GROUP_ITEMS_FAILURE, payload }; +} diff --git a/redux/reducers/group.js b/redux/reducers/group.js new file mode 100644 index 00000000..7d014dc0 --- /dev/null +++ b/redux/reducers/group.js @@ -0,0 +1,57 @@ +import { + DEFAULT_LIMIT, + SET_LIMIT, + SET_QUERY, + GET_GROUP_ITEMS_SUCCESS, + GET_GROUP_ITEMS_FAILURE, +} from '../actions/group'; + +const initialState = { + limit: DEFAULT_LIMIT, + query: {}, + items: [], + total: 0, + isLoading: true, +}; + +const reducer = (state = initialState, action) => { + const limit = action?.payload?.limit || DEFAULT_LIMIT; + + switch (action.type) { + case SET_LIMIT: { + return { + ...state, + limit, + isLoading: true, + }; + } + case SET_QUERY: { + return { + ...state, + ...(action.payload ?? {}), + items: [], + limit, + isLoading: true, + }; + } + case GET_GROUP_ITEMS_SUCCESS: { + return { + ...state, + ...(action.payload ?? {}), + isLoading: false, + }; + } + case GET_GROUP_ITEMS_FAILURE: { + return { + ...state, + total: 0, + isLoading: false, + }; + } + default: { + return state; + } + } +}; + +export default reducer; diff --git a/redux/reducers/index.js b/redux/reducers/index.js index 7ab81a62..c601daea 100644 --- a/redux/reducers/index.js +++ b/redux/reducers/index.js @@ -4,6 +4,7 @@ import user from './user'; import theme from './theme'; import shared from './shared'; import resource from './resource'; +import group from './group'; const allReducers = combineReducers({ search, @@ -11,6 +12,7 @@ const allReducers = combineReducers({ theme, shared, resource, + group, }); export default allReducers; diff --git a/redux/sagas/groupSaga.js b/redux/sagas/groupSaga.js new file mode 100644 index 00000000..8c46bff1 --- /dev/null +++ b/redux/sagas/groupSaga.js @@ -0,0 +1,27 @@ +import { put, takeEvery, select } from 'redux-saga/effects'; +import { + SET_LIMIT, + SET_QUERY, + getGroupItemsError, + getGroupItemsSuccess, +} from '../actions/group'; + +function* getGroupItems() { + const { + group: { limit, query }, + } = yield select(); + const queryString = new URLSearchParams({ ...query, limit }).toString(); + const URL = `/api/group?${queryString}`; + try { + const response = yield fetch(URL).then((res) => res.json()); + yield put(getGroupItemsSuccess(response)); + } catch (error) { + yield put(getGroupItemsError(error)); + } +} + +function* groupSaga() { + yield takeEvery([SET_LIMIT, SET_QUERY], getGroupItems); +} + +export default groupSaga; diff --git a/redux/sagas/index.js b/redux/sagas/index.js index 95794dd6..7ceb4b47 100644 --- a/redux/sagas/index.js +++ b/redux/sagas/index.js @@ -3,7 +3,14 @@ import searchSaga from './searchSaga'; import userSaga from './user'; import sharedSaga from './sharedSaga'; import resourceSaga from './resourceSaga'; +import groupSaga from './groupSaga'; export default function* rootSaga() { - yield all([searchSaga(), userSaga(), sharedSaga(), resourceSaga()]); + yield all([ + searchSaga(), + userSaga(), + sharedSaga(), + resourceSaga(), + groupSaga(), + ]); } From 35176606ead02ad4c2bb69d82638ec184a719d27 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Wed, 13 Dec 2023 11:10:15 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20potential=20type=20c?= =?UTF-8?q?onfusion=20and=20refactor=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Group/AreaChips.jsx | 1 + components/Group/GroupList/GroupCard.jsx | 2 +- components/Group/GroupList/index.jsx | 1 - pages/api/__mocks__/group.mock.json | 6 +++--- pages/api/group/index.js | 21 +++++++++++++-------- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/components/Group/AreaChips.jsx b/components/Group/AreaChips.jsx index 9b7e2aa3..6bb3a551 100644 --- a/components/Group/AreaChips.jsx +++ b/components/Group/AreaChips.jsx @@ -8,6 +8,7 @@ const StyledAreaChips = styled.ul` display: flex; flex-wrap: wrap; margin-bottom: 16px; + gap: 12px 0; `; const AreaChips = () => { diff --git a/components/Group/GroupList/GroupCard.jsx b/components/Group/GroupList/GroupCard.jsx index bc991255..282c2195 100644 --- a/components/Group/GroupList/GroupCard.jsx +++ b/components/Group/GroupList/GroupCard.jsx @@ -34,7 +34,7 @@ function GroupCard({ 適合階段 - {partnerEducationStep} + {partnerEducationStep || '皆可'} diff --git a/components/Group/GroupList/index.jsx b/components/Group/GroupList/index.jsx index 4b547cab..abb44aef 100644 --- a/components/Group/GroupList/index.jsx +++ b/components/Group/GroupList/index.jsx @@ -55,7 +55,6 @@ export const StyledGroupItem = styled.li` const StyledGroupList = styled.ul` display: flex; flex-wrap: wrap; - justify-content: space-between; `; function GroupList() { diff --git a/pages/api/__mocks__/group.mock.json b/pages/api/__mocks__/group.mock.json index d30e942d..9123a8f5 100644 --- a/pages/api/__mocks__/group.mock.json +++ b/pages/api/__mocks__/group.mock.json @@ -27,7 +27,7 @@ "photoURL": "https://images.unsplash.com/photo-1583526241256-cb18e8635e5b?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", "photoAlt": "封面圖", "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", + "partnerEducationStep": "高中、大學", "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", "area": "南投縣", "isGrouping": true @@ -38,7 +38,7 @@ "photoURL": "", "photoAlt": "", "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", + "partnerEducationStep": null, "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", "area": "嘉義縣、線上", "isGrouping": true @@ -49,7 +49,7 @@ "photoURL": "", "photoAlt": "", "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", + "partnerEducationStep": null, "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", "area": "新竹縣、新竹市", "isGrouping": true diff --git a/pages/api/group/index.js b/pages/api/group/index.js index 46ebe7b2..fadcf489 100644 --- a/pages/api/group/index.js +++ b/pages/api/group/index.js @@ -2,14 +2,19 @@ import groupMockData from '../__mocks__/group.mock.json'; /** * 根據傳入的條件進行篩選 - * @param {string[]} itemValue - 資料的值 - * @param {string[]} conditionValue - 篩選條件的值 + * @param {null | string[]} itemArray - 資料的值 + * @param {string | string[]} conditionValue - 篩選條件的值 * @returns {boolean} - 是否符合保留條件 */ -function filterBy(itemValue, conditionValue = []) { +function some(itemArray, conditionValue) { + const conditionArray = Array.isArray(conditionValue) + ? conditionValue + : conditionValue?.split(',') || []; + return ( - !conditionValue.length || - conditionValue.every((cond) => itemValue.includes(cond)) + !conditionArray.length || + !Array.isArray(itemArray) || + conditionArray.some((cond) => itemArray.includes(cond)) ); } @@ -43,10 +48,10 @@ export default function handler(req, res) { const end = Number(limit); const filterData = groupMockData .filter((item) => !q || item.title.includes(q)) - .filter((item) => !edu || edu.includes(item.partnerEducationStep)) .filter((item) => !grouping || item.isGrouping === isGrouping) - .filter((item) => filterBy(item.area.split('、'), area?.split(','))) - .filter((item) => filterBy(item.category, category?.split(','))); + .filter((item) => some(item.area?.split('、'), area)) + .filter((item) => some(item.category, category)) + .filter((item) => some(item.partnerEducationStep?.split('、'), edu)); const items = filterData.slice(0, end); From 3e89d37d939ef8c07c9bae7c50871799492fa464 Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Tue, 16 Jan 2024 22:47:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E2=9C=A8=20=E6=96=B0=E5=A2=9E=20Image=2040?= =?UTF-8?q?4=20=E6=99=82=EF=BC=8C=E8=87=AA=E5=8B=95=E6=9B=B4=E6=8F=9B?= =?UTF-8?q?=E5=82=99=E7=94=A8=E5=9C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/components/Image/index.jsx | 38 ++++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/shared/components/Image/index.jsx b/shared/components/Image/index.jsx index 1ef7d0aa..37f3f1a6 100644 --- a/shared/components/Image/index.jsx +++ b/shared/components/Image/index.jsx @@ -1,5 +1,7 @@ import Skeleton from '@mui/material/Skeleton'; import { LazyLoadImage } from 'react-lazy-load-image-component'; +import emptyCoverImg from '@/public/assets/empty-cover.png'; +import { useState } from 'react'; const Loading = () => ( ( - } - /> -); +}) => { + const [isError, setIsError] = useState(false); + return ( + } + onError={() => setIsError(true)} + /> + ); +}; export default Image; From ab754c6dfd7b965bbeea7863d1f4f5bb42ba9d1e Mon Sep 17 00:00:00 2001 From: Johnson Mao Date: Tue, 16 Jan 2024 22:51:42 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E2=9C=A8=20=E4=B8=B2=E6=8E=A5=E6=8F=AA?= =?UTF-8?q?=E5=9C=98=E6=9F=A5=E8=A9=A2=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/Group/GroupList/GroupCard.jsx | 4 +- components/Group/GroupList/index.jsx | 2 +- components/Group/More.jsx | 8 +- pages/api/__mocks__/group.mock.json | 662 ----------------------- pages/api/group/index.js | 69 --- redux/actions/group.js | 19 +- redux/reducers/group.js | 14 +- redux/sagas/groupSaga.js | 11 +- 8 files changed, 32 insertions(+), 757 deletions(-) delete mode 100644 pages/api/__mocks__/group.mock.json delete mode 100644 pages/api/group/index.js diff --git a/components/Group/GroupList/GroupCard.jsx b/components/Group/GroupList/GroupCard.jsx index 282c2195..38a889a1 100644 --- a/components/Group/GroupList/GroupCard.jsx +++ b/components/Group/GroupList/GroupCard.jsx @@ -1,6 +1,7 @@ import LocationOnOutlinedIcon from '@mui/icons-material/LocationOnOutlined'; import Image from '@/shared/components/Image'; import emptyCoverImg from '@/public/assets/empty-cover.png'; +import { timeDuration } from '@/utils/date'; import { StyledAreas, StyledContainer, @@ -21,6 +22,7 @@ function GroupCard({ description, area, isGrouping, + updatedDate, }) { return ( @@ -45,7 +47,7 @@ function GroupCard({ {area} - + {isGrouping ? (
    揪團中
    ) : ( diff --git a/components/Group/GroupList/index.jsx b/components/Group/GroupList/index.jsx index abb44aef..d92ec7ca 100644 --- a/components/Group/GroupList/index.jsx +++ b/components/Group/GroupList/index.jsx @@ -93,7 +93,7 @@ function GroupList() { {items?.length || isLoading ? ( items.map((data) => ( - + )) diff --git a/components/Group/More.jsx b/components/Group/More.jsx index 9ab883be..d7e78f2d 100644 --- a/components/Group/More.jsx +++ b/components/Group/More.jsx @@ -1,11 +1,11 @@ import { useDispatch, useSelector } from 'react-redux'; import { Box, Button } from '@mui/material'; -import { setLimit } from '@/redux/actions/group'; +import { setPageSize } from '@/redux/actions/group'; export default function More() { const dispatch = useDispatch(); - const { limit, total, isLoading } = useSelector((state) => state.group); - const isMore = total > limit || isLoading; + const { pageSize, total, isLoading } = useSelector((state) => state.group); + const isMore = total > pageSize || isLoading; return ( dispatch(setLimit(limit + 12))} + onClick={() => dispatch(setPageSize(pageSize + 12))} > 顯示更多 diff --git a/pages/api/__mocks__/group.mock.json b/pages/api/__mocks__/group.mock.json deleted file mode 100644 index 9123a8f5..00000000 --- a/pages/api/__mocks__/group.mock.json +++ /dev/null @@ -1,662 +0,0 @@ -[ - { - "id": "00001", - "title": "文學少女讀書會", - "photoURL": "https://images.unsplash.com/photo-1558021212-51b6ecfa0db9?q=80&w=1783&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", - "photoAlt": "封面圖", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "新北市、台北市、線上", - "isGrouping": true - }, - { - "id": "00002", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "https://images.unsplash.com/photo-1674027444454-97b822a997b6?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", - "photoAlt": "封面圖", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "線上", - "isGrouping": false - }, - { - "id": "00003", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "https://images.unsplash.com/photo-1583526241256-cb18e8635e5b?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", - "photoAlt": "封面圖", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "高中、大學", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00004", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": null, - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "嘉義縣、線上", - "isGrouping": true - }, - { - "id": "00005", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": null, - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "新竹縣、新竹市", - "isGrouping": true - }, - { - "id": "00006", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "基隆市、新北市、台北市", - "isGrouping": true - }, - { - "id": "00007", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "高雄市", - "isGrouping": true - }, - { - "id": "00008", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "澎湖縣、線上", - "isGrouping": true - }, - { - "id": "00009", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "新北市、台北市、線上", - "isGrouping": true - }, - { - "id": "00010", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "線上", - "isGrouping": true - }, - { - "id": "00011", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00012", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "嘉義縣、線上", - "isGrouping": false - }, - { - "id": "00013", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "新竹縣、新竹市", - "isGrouping": true - }, - { - "id": "00014", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "基隆市、新北市、台北市", - "isGrouping": true - }, - { - "id": "00015", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "高雄市", - "isGrouping": true - }, - { - "id": "00016", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "澎湖縣、線上", - "isGrouping": true - }, - { - "id": "00017", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "新北市、台北市、線上", - "isGrouping": true - }, - { - "id": "00018", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "線上", - "isGrouping": true - }, - { - "id": "00019", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00020", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "嘉義縣、線上", - "isGrouping": true - }, - { - "id": "00021", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "新竹縣、新竹市", - "isGrouping": true - }, - { - "id": "00022", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "基隆市、新北市、台北市", - "isGrouping": true - }, - { - "id": "00023", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "高雄市", - "isGrouping": true - }, - { - "id": "00024", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "澎湖縣、線上", - "isGrouping": true - }, - { - "id": "00025", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "新北市、台北市、線上", - "isGrouping": true - }, - { - "id": "00026", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "線上", - "isGrouping": false - }, - { - "id": "00027", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00028", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "嘉義縣、線上", - "isGrouping": true - }, - { - "id": "00029", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "新竹縣、新竹市", - "isGrouping": true - }, - { - "id": "00030", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "基隆市、新北市、台北市", - "isGrouping": true - }, - { - "id": "00031", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "高雄市", - "isGrouping": true - }, - { - "id": "00032", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "澎湖縣、線上", - "isGrouping": false - }, - { - "id": "00033", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "新北市、台北市、線上", - "isGrouping": false - }, - { - "id": "00034", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "線上", - "isGrouping": false - }, - { - "id": "00035", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00036", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "嘉義縣、線上", - "isGrouping": true - }, - { - "id": "00037", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "新竹縣、新竹市", - "isGrouping": true - }, - { - "id": "00038", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "基隆市、新北市、台北市", - "isGrouping": true - }, - { - "id": "00039", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "高雄市", - "isGrouping": true - }, - { - "id": "00040", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "澎湖縣、線上", - "isGrouping": true - }, - { - "id": "00041", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "新北市、台北市、線上", - "isGrouping": true - }, - { - "id": "00042", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "線上", - "isGrouping": true - }, - { - "id": "00043", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00044", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "嘉義縣、線上", - "isGrouping": true - }, - { - "id": "00045", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "新竹縣、新竹市", - "isGrouping": true - }, - { - "id": "00046", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "基隆市、新北市、台北市", - "isGrouping": true - }, - { - "id": "00047", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "高雄市", - "isGrouping": true - }, - { - "id": "00048", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "澎湖縣、線上", - "isGrouping": true - }, - { - "id": "00049", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "新北市、台北市、線上", - "isGrouping": true - }, - { - "id": "00050", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "線上", - "isGrouping": true - }, - { - "id": "00051", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00052", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "嘉義縣、線上", - "isGrouping": true - }, - { - "id": "00053", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "新竹縣、新竹市", - "isGrouping": true - }, - { - "id": "00054", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "基隆市、新北市、台北市", - "isGrouping": true - }, - { - "id": "00055", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "高雄市", - "isGrouping": true - }, - { - "id": "00056", - "title": "文學少女讀書會", - "photoURL": "", - "photoAlt": "", - "category": ["語言與文學", "人文社會"], - "partnerEducationStep": "高中", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "澎湖縣、線上", - "isGrouping": true - }, - { - "id": "00057", - "title": "尋找北北基線上自學程式、AI的小夥伴們", - "photoURL": "", - "photoAlt": "", - "category": ["數學與邏輯", "資訊與工程", "商業與社會創新"], - "partnerEducationStep": "國中", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "新北市、台北市、線上", - "isGrouping": true - }, - { - "id": "00058", - "title": "Smart Reading 科普閱讀力大賽 徵人中", - "photoURL": "", - "photoAlt": "", - "category": ["教育", "生活", "商業與社會創新", "綜合型學習資源"], - "partnerEducationStep": "大學", - "description": "希望能像朋友,一起讀有興趣的科目每週1-2次見面練習這兩種,每次總時數2-3小時不限,希望你跟我一樣很想追求有效進步也不怕辛苦!一起讀日文也可以喔!", - "area": "線上", - "isGrouping": true - }, - { - "id": "00059", - "title": "【秋季】木工課+釣魚+野外技能學習", - "photoURL": "", - "photoAlt": "", - "category": ["藝術", "自然科學", "生活"], - "partnerEducationStep": "其他", - "description": "我家小朋友14歲,目前常駐在上海,申請在家自學。目前自己規畫學習進度。主要有興趣做些TTS、Vits、Yolov的聲音、視覺項目。不知道有沒有同好一起來研究、交流!", - "area": "南投縣", - "isGrouping": true - }, - { - "id": "00060", - "title": "▋宜蘭青年志工中心培力工作坊 ▋城市觀察學Part2.", - "photoURL": "", - "photoAlt": "", - "category": ["人文社會", "運動/心理/醫學", "生活"], - "partnerEducationStep": "其他", - "description": "作為一位數學和科學老師,我理解學生對於這些學科的挑戰和挫折感,當遇到問題,不知從何想起,迷路的感覺。", - "area": "嘉義縣、線上", - "isGrouping": true - } -] diff --git a/pages/api/group/index.js b/pages/api/group/index.js deleted file mode 100644 index fadcf489..00000000 --- a/pages/api/group/index.js +++ /dev/null @@ -1,69 +0,0 @@ -import groupMockData from '../__mocks__/group.mock.json'; - -/** - * 根據傳入的條件進行篩選 - * @param {null | string[]} itemArray - 資料的值 - * @param {string | string[]} conditionValue - 篩選條件的值 - * @returns {boolean} - 是否符合保留條件 - */ -function some(itemArray, conditionValue) { - const conditionArray = Array.isArray(conditionValue) - ? conditionValue - : conditionValue?.split(',') || []; - - return ( - !conditionArray.length || - !Array.isArray(itemArray) || - conditionArray.some((cond) => itemArray.includes(cond)) - ); -} - -function checkInvalidParameter(req, res, requiredParams) { - const params = requiredParams.filter((param) => !req.query[param]); - - if (params.length) { - res.status(400).json({ - message: 'Invalid parameter', - params, - }); - return true; - } - - return false; -} - -/** - * 揪團 mock api - * @param {import("next").NextApiRequest} req request 請求 - * @param {import("next").NextApiResponse} res response 回應 - */ -export default function handler(req, res) { - switch (req.method) { - case 'GET': { - if (checkInvalidParameter(req, res, ['limit'])) return; - - try { - const { limit, q, edu, area, category, grouping } = req.query; - const isGrouping = grouping === 'true'; - const end = Number(limit); - const filterData = groupMockData - .filter((item) => !q || item.title.includes(q)) - .filter((item) => !grouping || item.isGrouping === isGrouping) - .filter((item) => some(item.area?.split('、'), area)) - .filter((item) => some(item.category, category)) - .filter((item) => some(item.partnerEducationStep?.split('、'), edu)); - - const items = filterData.slice(0, end); - - res.status(200).json({ - items, - total: filterData.length, - }); - } catch (err) { - res.status(500).json({ message: err.message }); - } - break; - } - default: - } -} diff --git a/redux/actions/group.js b/redux/actions/group.js index 6891f4e0..25bdba2c 100644 --- a/redux/actions/group.js +++ b/redux/actions/group.js @@ -1,14 +1,17 @@ -export const DEFAULT_LIMIT = 12; -export const SET_LIMIT = 'SET_LIMIT'; +export const DEFAULT_PAGE_SIZE = 6; +export const SET_PAGE_SIZE = 'SET_PAGE_SIZE'; export const SET_QUERY = 'SET_QUERY'; export const GET_GROUP_ITEMS_SUCCESS = 'GET_GROUP_ITEMS_SUCCESS'; export const GET_GROUP_ITEMS_FAILURE = 'GET_GROUP_ITEMS_FAILURE'; +export const BASE_API_URL = + process.env.NEXT_PUBLIC_API_URL || 'https://daodao-server.onrender.com'; +export const GROUP_API_URL = `${BASE_API_URL}/activity`; -export function setLimit(limit) { +export function setPageSize(pageSize) { return { - type: SET_LIMIT, + type: SET_PAGE_SIZE, payload: { - limit, + pageSize, }, }; } @@ -22,12 +25,12 @@ export function setQuery(query = {}) { }; } -export function getGroupItemsSuccess({ items = [], total = 0 } = {}) { +export function getGroupItemsSuccess({ data = [], totalCount = 0 } = {}) { return { type: GET_GROUP_ITEMS_SUCCESS, payload: { - items, - total, + items: data, + total: totalCount, }, }; } diff --git a/redux/reducers/group.js b/redux/reducers/group.js index 7d014dc0..106a277c 100644 --- a/redux/reducers/group.js +++ b/redux/reducers/group.js @@ -1,13 +1,13 @@ import { - DEFAULT_LIMIT, - SET_LIMIT, + DEFAULT_PAGE_SIZE, + SET_PAGE_SIZE, SET_QUERY, GET_GROUP_ITEMS_SUCCESS, GET_GROUP_ITEMS_FAILURE, } from '../actions/group'; const initialState = { - limit: DEFAULT_LIMIT, + pageSize: DEFAULT_PAGE_SIZE, query: {}, items: [], total: 0, @@ -15,13 +15,13 @@ const initialState = { }; const reducer = (state = initialState, action) => { - const limit = action?.payload?.limit || DEFAULT_LIMIT; + const pageSize = action?.payload?.pageSize || DEFAULT_PAGE_SIZE; switch (action.type) { - case SET_LIMIT: { + case SET_PAGE_SIZE: { return { ...state, - limit, + pageSize, isLoading: true, }; } @@ -30,7 +30,7 @@ const reducer = (state = initialState, action) => { ...state, ...(action.payload ?? {}), items: [], - limit, + pageSize, isLoading: true, }; } diff --git a/redux/sagas/groupSaga.js b/redux/sagas/groupSaga.js index 8c46bff1..dada13b8 100644 --- a/redux/sagas/groupSaga.js +++ b/redux/sagas/groupSaga.js @@ -1,6 +1,7 @@ import { put, takeEvery, select } from 'redux-saga/effects'; import { - SET_LIMIT, + GROUP_API_URL, + SET_PAGE_SIZE, SET_QUERY, getGroupItemsError, getGroupItemsSuccess, @@ -8,10 +9,10 @@ import { function* getGroupItems() { const { - group: { limit, query }, + group: { pageSize, query }, } = yield select(); - const queryString = new URLSearchParams({ ...query, limit }).toString(); - const URL = `/api/group?${queryString}`; + const queryString = new URLSearchParams({ ...query, pageSize }).toString(); + const URL = `${GROUP_API_URL}?${queryString}`; try { const response = yield fetch(URL).then((res) => res.json()); yield put(getGroupItemsSuccess(response)); @@ -21,7 +22,7 @@ function* getGroupItems() { } function* groupSaga() { - yield takeEvery([SET_LIMIT, SET_QUERY], getGroupItems); + yield takeEvery([SET_PAGE_SIZE, SET_QUERY], getGroupItems); } export default groupSaga;