-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(article-cat-state): sync name alias & dashboard fix (#145)
- Loading branch information
Showing
29 changed files
with
183 additions
and
105 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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,37 @@ | ||
import { useContext } from 'react' | ||
import { MobXProviderContext } from 'mobx-react' | ||
import { filter } from 'ramda' | ||
|
||
import { toJS } from '@/mobx' | ||
import type { TNameAlias } from '@/spec' | ||
|
||
/** | ||
* NOTE: should use observer to wrap the component who use this hook | ||
*/ | ||
const useNameAlias = (group = 'kanban'): Record<string, TNameAlias> => { | ||
const { store } = useContext(MobXProviderContext) | ||
|
||
if (store === null) { | ||
throw new Error('Store cannot be null, please add a context provider') | ||
} | ||
|
||
const alias = {} | ||
let aliasList = [] | ||
|
||
if (!group) { | ||
aliasList = toJS(store.dashboardThread.nameAlias) | ||
} else { | ||
aliasList = filter( | ||
(item: TNameAlias) => item.group === group, | ||
toJS(store.dashboardThread.nameAlias), | ||
) | ||
} | ||
|
||
aliasList.forEach((item) => { | ||
alias[item.slug] = item | ||
}) | ||
|
||
return alias | ||
} | ||
|
||
export default useNameAlias |
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
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
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.