-
Notifications
You must be signed in to change notification settings - Fork 683
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
Create categoryTile/categoryList talon #1755
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d7e4f8d
Create categoryTile mixin and move makeurl to peregrine
sirugh dc7f291
Add mixin for categoryList
sirugh a326623
Refactor to use resourceUrl within component
sirugh 746b083
Prettier
sirugh e3e75f0
Update tests for use with talons
sirugh 616b329
Merge branch 'develop' into rugh/mixin-categoryList
sirugh 7d52247
Move to talons
sirugh 30e9dae
Update comments
sirugh a5a48e4
Fix imports
sirugh 290f0f1
Merge branch 'develop' into rugh/mixin-categoryList
sirugh 50743bc
Merge branch 'develop' into rugh/mixin-categoryList
sirugh a948b24
Update packages/venia-ui/lib/components/CategoryList/categoryList.js
sirugh 0e2165e
Feedback for categoryList
sirugh ab95f00
Add loading back to list return
sirugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/peregrine/lib/talons/CategoryList/useCategoryList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect } from 'react'; | ||
import { useQuery } from '../../hooks/useQuery'; | ||
|
||
/** | ||
* Returns props necessary to render a CategoryList component. | ||
* | ||
* @param {object} props | ||
* @param {object} props.query - category data | ||
* @param {string} props.id - category id | ||
* @return {{ data: object, error: boolean, loading: boolean }} | ||
*/ | ||
export const useCategoryList = props => { | ||
const { query, id } = props; | ||
const [queryResult, queryApi] = useQuery(query); | ||
const { data, error, loading } = queryResult; | ||
const { runQuery, setLoading } = queryApi; | ||
|
||
useEffect(() => { | ||
const fetchCategories = async () => { | ||
setLoading(true); | ||
|
||
await runQuery({ | ||
variables: { | ||
id | ||
} | ||
}); | ||
|
||
setLoading(false); | ||
}; | ||
|
||
fetchCategories(); | ||
}, [runQuery, setLoading, id]); | ||
|
||
return { | ||
data, | ||
error, | ||
loading | ||
}; | ||
}; |
49 changes: 49 additions & 0 deletions
49
packages/peregrine/lib/talons/CategoryList/useCategoryTile.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { useMemo } from 'react'; | ||
|
||
// TODO: get categoryUrlSuffix from graphql storeOptions when it is ready | ||
const categoryUrlSuffix = '.html'; | ||
const previewImageSize = 480; | ||
|
||
/** | ||
* Returns props necessary to render a CategoryTile component. | ||
* | ||
* @returns {Object} props necessary to render a category tile | ||
* @returns {Object} .image - an object containing url, type and width for the category image | ||
* @returns {Object} .item - an object containing name and url for the category tile | ||
*/ | ||
export const useCategoryTile = props => { | ||
const { item } = props; | ||
const { image, productImagePreview } = item; | ||
|
||
const imageObj = useMemo(() => { | ||
const previewProduct = productImagePreview.items[0]; | ||
if (image) { | ||
return { | ||
url: image, | ||
type: 'image-category', | ||
width: previewImageSize | ||
}; | ||
} else if (previewProduct) { | ||
return { | ||
url: previewProduct.small_image, | ||
type: 'image-product', | ||
width: previewImageSize | ||
}; | ||
} else { | ||
return null; | ||
} | ||
}, [image, productImagePreview]); | ||
|
||
const itemObject = useMemo( | ||
() => ({ | ||
name: item.name, | ||
url: `/${item.url_key}${categoryUrlSuffix}` | ||
}), | ||
[item] | ||
); | ||
|
||
return { | ||
image: imageObj, | ||
item: itemObject | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is
error
a boolean or anError
object?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.
I'll look and see how we're using it in
categoryList
and update the output accordingly.