Skip to content

Commit cbab296

Browse files
committed
Save work before debugging
1 parent ba2274b commit cbab296

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/SuggestionItem.jsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
import { useAppGlobalContext } from './context'
22

33
function SuggestionItem ({ suggestion }) {
4-
const { selectUserItem } = useAppGlobalContext()
4+
const { selectUserItem, isItemLoading } = useAppGlobalContext()
5+
6+
if (isItemLoading) {
7+
return (
8+
<li className='item-skeleton br-small'>
9+
<div className='item-skeleton__pic'></div>
10+
<div className='item-skeleton__name'></div>
11+
</li>
12+
)
13+
}
514

615
return (
716
<li

src/context.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function AppContext ({ children }) {
99
window.matchMedia('(prefers-color-scheme: dark)').matches
1010
)
1111
const [isLoading, setIsLoading] = useState(true)
12+
const [isItemLoading, setIsItemLoading] = useState(true)
1213
const [isError, setIsError] = useState(false)
1314
const [isIssue, setIsIssue] = useState(false)
1415
const [errorMessage, setErrorMessage] = useState('')
@@ -122,6 +123,7 @@ function AppContext ({ children }) {
122123
* @returns a list of suggested users
123124
*/
124125
async function getUserSuggestions (inputString) {
126+
setIsItemLoading(true)
125127
setIsError(false)
126128
if (!inputString) {
127129
setSuggestionList([])
@@ -142,12 +144,14 @@ function AppContext ({ children }) {
142144
} catch (error) {
143145
setIsError(true)
144146
}
147+
setIsItemLoading(false)
145148
}
146149

147150
/**
148151
* Fetches more suggested items from subsequent pages of results
149152
*/
150153
async function getMoreSuggestions () {
154+
setIsItemLoading(true)
151155
setIsError(false)
152156
try {
153157
const response = await axios.get(
@@ -183,6 +187,7 @@ function AppContext ({ children }) {
183187
} catch (error) {
184188
setIsError(true)
185189
}
190+
setIsItemLoading(false)
186191
}
187192

188193
/**
@@ -248,6 +253,7 @@ function AppContext ({ children }) {
248253
<AppGlobalContext.Provider
249254
value={{
250255
isLoading,
256+
isItemLoading,
251257
isError,
252258
isIssue,
253259
setIsError,

0 commit comments

Comments
 (0)