Skip to content

Commit

Permalink
revert: files relative to useFetch hook
Browse files Browse the repository at this point in the history
  • Loading branch information
whalekiller03 committed Apr 29, 2024
1 parent 53c8684 commit fca2299
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 25 deletions.
16 changes: 3 additions & 13 deletions components/Profile/MyGroup/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,11 @@ const MyGroup = ({ hasTitle = true, sx, userId }) => {
if (!userId) {
return <Typography py={7.5}>趕快發起屬於你的揪團吧~</Typography>;
}
// TODO: 待優化
const me = useSelector((state) => state.user);

const [response, setResponse] = useState(null);
const { isFetching } = useFetch(
`${GROUP_API_URL}/${userId}`,
{
headers: {
Authorization: `Bearer ${me.token}`,
},
},
{
onSuccess: setResponse,
},
);
const { isFetching } = useFetch(`${GROUP_API_URL}/user/${userId}`, {
onSuccess: setResponse,
});

const getTargetIndexById = (data, id) => {
if (!Array.isArray(data)) return -1;
Expand Down
2 changes: 1 addition & 1 deletion hooks/useFetch.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useReducer, useState } from 'react';

const useFetch = (url, options = {}, { initialValue, onSuccess } = {}) => {
const useFetch = (url, { initialValue, onSuccess } = {}) => {
const [render, refetch] = useReducer((pre) => !pre, true);
const [data, setData] = useState(initialValue);
const [isFetching, setIsFetching] = useState(true);
Expand Down
7 changes: 1 addition & 6 deletions pages/group/detail/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import { BASE_URL } from '@/constants/common';
function GroupPage() {
const router = useRouter();
const { id } = router.query;
const me = useSelector((state) => state.user);
const { data, isFetching, isError } = useFetch(`${BASE_URL}/activity/${id}`, {
headers: {
Authorization: `Bearer ${me.token}`,
},
});
const { data, isFetching, isError } = useFetch(`${BASE_URL}/activity/${id}`);
const source = data?.data?.[0];

const SEOData = useMemo(
Expand Down
6 changes: 1 addition & 5 deletions pages/group/edit/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ function EditGroupPage() {
const router = useRouter();
const me = useSelector((state) => state.user);
const { id } = router.query;
const { data, isFetching } = useFetch(`${BASE_URL}/activity/${id}`, {
headers: {
Authorization: `Bearer ${me.token}`,
},
});
const { data, isFetching } = useFetch(`${BASE_URL}/activity/${id}`);
const source = data?.data?.[0];

const SEOData = useMemo(
Expand Down

0 comments on commit fca2299

Please sign in to comment.