diff --git a/src/components/Header/components/UserStep/Body.jsx b/src/components/Header/components/UserStep/Body.jsx
index a79a2f4..29cf83a 100644
--- a/src/components/Header/components/UserStep/Body.jsx
+++ b/src/components/Header/components/UserStep/Body.jsx
@@ -67,7 +67,7 @@ const Body = () => {
const inputRef = useRef();
const [search, setSearch] = useState('');
const [neverChange, setNeverChange] = useState(true);
- const { isFetching, searched, top } = useSelector(slice.selectors.getState);
+ const { isFetching, items, top } = useSelector(slice.selectors.getState);
const [bodyOpen, setBodyOpen] = useUIProperty('bodyOpen');
const onChange = useCallback(
@@ -126,8 +126,8 @@ const Body = () => {
dense
subheader={SearchHeader}
>
- {!searched.length && }
- {(searched || []).map((user) => (
+ {!items.length && }
+ {(items || []).map((user) => (
{
- const { profile } = useSelector(slice.selectors.getState);
+ const { selected } = useSelector(slice.selectors.getState);
+ const {
+ avatar_url, name, login,
+ html_url, public_repos, blog,
+ } = selected || {};
return (
-
+
- {!profile && Find a user
}
- {profile && (
+ {!selected && Find a user
}
+ {selected && (
- {profile.name || profile.login}
+ {name || login}
- {profile.login}
+ {login}
- {profile.public_repos}
+ {public_repos}
- {profile.blog && (
+ {blog && (
- blog
+ blog
)}
diff --git a/src/redux/modules/profiles.js b/src/redux/modules/profiles.js
index c3210db..1e9ab07 100644
--- a/src/redux/modules/profiles.js
+++ b/src/redux/modules/profiles.js
@@ -1,17 +1,17 @@
import { getProfile, searchAccount } from '@/redux/api/github';
import { createSlice, startFetching, stopFetching } from "@/redux/utils";
-import { call, put } from 'redux-saga/effects';
+import { call, cancelled, put } from 'redux-saga/effects';
const initialState = {
isFetching: false,
- profile: null,
- searched: [],
+ selected: null,
+ items: [],
top: [],
error: null,
};
-const setProfile = (state, profile) => {
- state.profile = profile;
+const setProfile = (state, selected) => {
+ state.selected = selected;
};
export default createSlice({
@@ -31,7 +31,7 @@ export default createSlice({
search: startFetching,
searchSuccess: (state, { payload }) => {
stopFetching(state);
- state.searched = Array.isArray(payload) ? payload : [];
+ state.items = Array.isArray(payload) ? payload : [];
},
fetchTop: startFetching,
fetchTopSuccess: (state, { payload }) => {
@@ -39,6 +39,8 @@ export default createSlice({
state.top = Array.isArray(payload) ? payload : [];
},
+ stopFetching,
+
fail: (state, { payload: { message } }) => {
stopFetching(state);
state.error = message;
@@ -53,6 +55,9 @@ export default createSlice({
yield put(actions.fetchProfileSuccess(data));
} catch (error) {
yield put(actions.fail(error));
+ if (yield cancelled()) {
+ yield put(actions.stopFetching());
+ }
}
},
},
@@ -64,6 +69,9 @@ export default createSlice({
yield put(actions.searchSuccess(data));
} catch (error) {
yield put(actions.fail(error));
+ if (yield cancelled()) {
+ yield put(actions.stopFetching());
+ }
}
},
},
@@ -75,6 +83,9 @@ export default createSlice({
yield put(actions.fetchTopSuccess(data));
} catch (error) {
yield put(actions.fail(error));
+ if (yield cancelled()) {
+ yield put(actions.stopFetching());
+ }
}
},
},