-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: mentor's review fixes for Dictionary #6
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const styles = { | ||
text: { | ||
color: 'rebeccapurple', | ||
}, | ||
}; | ||
|
||
export default styles; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,36 +2,27 @@ import { Dispatch } from 'redux'; | |
import backendUrl from '../../consts'; | ||
import { DictionaryActionTypes, IWord } from '../types'; | ||
|
||
export function fetchDictionaryStart() { | ||
return { | ||
type: DictionaryActionTypes.FETCH_START, | ||
}; | ||
} | ||
export const fetchDictionaryStart = () => ({ | ||
type: DictionaryActionTypes.FETCH_START, | ||
}); | ||
|
||
export function fetchDictionarySuccess(words: IWord[]) { | ||
return { | ||
type: DictionaryActionTypes.FETCH_SUCCESS, | ||
payload: { words }, | ||
}; | ||
} | ||
export const fetchDictionarySuccess = (words: IWord[]) => ({ | ||
type: DictionaryActionTypes.FETCH_SUCCESS, | ||
payload: { words }, | ||
}); | ||
|
||
export function fetchDictionaryError(error: Error) { | ||
return { | ||
type: DictionaryActionTypes.FETCH_ERROR, | ||
payload: { error }, | ||
}; | ||
} | ||
export const fetchDictionaryError = (error: Error) => ({ | ||
type: DictionaryActionTypes.FETCH_ERROR, | ||
payload: { error }, | ||
}); | ||
|
||
export function fetchDictionary() { | ||
return async (dispatch: Dispatch) => { | ||
const apiURL = `${backendUrl}/words`; | ||
dispatch(fetchDictionaryStart()); | ||
try { | ||
const res = await fetch(apiURL); | ||
const words = await res.json(); | ||
dispatch(fetchDictionarySuccess(words)); | ||
} catch (e) { | ||
dispatch(fetchDictionaryError(e)); | ||
} | ||
}; | ||
} | ||
export const fetchDictionary = () => async (dispatch: Dispatch) => { | ||
dispatch(fetchDictionaryStart()); | ||
try { | ||
const res = await fetch(`${backendUrl}/words`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be nice if fetchDictionary function will take two value. For example "page" & "group", for this link https://react-learnwords-example.herokuapp.com/words?page=2&group=0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Будет сделано в будущем ) это пока что "скелет" |
||
const words = await res.json(); | ||
dispatch(fetchDictionarySuccess(words)); | ||
} catch (e) { | ||
dispatch(fetchDictionaryError(e)); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IWord[] как Array вроде хотели писать?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed