Skip to content

Commit

Permalink
Merge pull request #2343 from Aylie-Chou/12-feature-info-struct-redesign
Browse files Browse the repository at this point in the history
feat: add latest page
  • Loading branch information
Aylie-Chou authored Jan 17, 2023
2 parents 602337d + ac2670c commit 0f0b57c
Show file tree
Hide file tree
Showing 7 changed files with 415 additions and 16 deletions.
3 changes: 3 additions & 0 deletions src/constants/data-loaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ export default {
topicListPage: {
nPerPage: 5,
},
latestPage: {
nPerPage: 10,
},
}
3 changes: 3 additions & 0 deletions src/constants/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export default {
bookmarkListPage: {
path: '/bookmarks/:pageNumber?',
},
latestPage: {
path: '/latest/:tagId?',
},
errorPage: {
path: '/error/:errorType',
},
Expand Down
45 changes: 29 additions & 16 deletions src/containers/Category.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,29 @@ function postsProp(state, listId, page) {
return posts
}

/**
* @param {string} categoryPath - category pathname
* @param {string} subcategoryPath - subcategory pathname
* @return {Object} - subcategoryList, activeTabIndex
*/
function titleTabProp(categoryPath, subcategoryPath) {
const subcategoryList = _.map(CATEGORY_SET[categoryPath], subcategoryKey => {
const path = subcategoryKey
const label = SUBCATEGORY_LABEL[subcategoryKey]
const id = SUBCATEGORY_ID[subcategoryKey]
const link =
subcategoryKey !== 'all'
? `/categories/${categoryPath}/${path}`
: `/categories/${categoryPath}`
return { id, label, link, path, isExternal: false }
})
const activeTabIndex = subcategoryPath
? _.findIndex(subcategoryList, ['path', subcategoryPath])
: 0

return { subcategoryList, activeTabIndex }
}

/**
* @typedef {Object} CategoryProps
* @property {string} listId - category set id
Expand Down Expand Up @@ -263,27 +286,17 @@ function mapStateToProps(state, props) {
const listId =
categoryId && subcategoryId ? `${categoryId}_${subcategoryId}` : categoryId
const catLabel = CATEGORY_LABEL[categoryPath]
const { subcategoryList, activeTabIndex } = titleTabProp(
categoryPath,
subcategoryPath
)
const page = pageProp(location)
const nPerPage = dataLoaderConst.categoryListPage.nPerPage

const defaultPathname = subcategoryPath
? `/categories/${categoryPath}/${subcategoryPath}`
: `/categories/${categoryPath}`
const pathname = _.get(location, 'pathname', defaultPathname)
const subcategoryList = _.map(CATEGORY_SET[categoryPath], subcategoryKey => {
const path = subcategoryKey
const label = SUBCATEGORY_LABEL[subcategoryKey]
const id = SUBCATEGORY_ID[subcategoryKey]
const link =
subcategoryKey !== 'all'
? `/categories/${categoryPath}/${path}`
: `/categories/${categoryPath}`
const isExternal = false
return { id, label, link, path, isExternal }
})
const activeTabIndex = subcategoryPath
? _.findIndex(subcategoryList, ['path', subcategoryPath])
: 0
const page = pageProp(location)
const nPerPage = dataLoaderConst.categoryListPage.nPerPage

return {
catLabel,
Expand Down
Loading

0 comments on commit 0f0b57c

Please sign in to comment.