ramda#toPairs TypeScript Examples
The following examples show how to use
ramda#toPairs.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: useNextQuestion.tsx From nosgestesclimat-site with MIT License | 6 votes |
export function getNextSteps(
missingVariables: Array<MissingVariables>
): Array<DottedName> {
const byCount = ([, [count]]: [unknown, [number]]) => count
const byScore = ([, [, score]]: [unknown, [unknown, number]]) => score
const missingByTotalScore = reduce<MissingVariables, MissingVariables>(
mergeWith(add),
{},
missingVariables
)
const innerKeys = flatten(map(keys, missingVariables)),
missingByTargetsAdvanced = Object.fromEntries(
Object.entries(countBy(identity, innerKeys)).map(
// Give higher score to top level questions
([name, score]) => [
name,
score + Math.max(0, 4 - name.split('.').length),
]
)
)
const missingByCompound = mergeWith(
pair,
missingByTargetsAdvanced,
missingByTotalScore
),
pairs = toPairs<number>(missingByCompound),
sortedPairs = sortWith([descend(byCount), descend(byScore) as any], pairs)
return map(head, sortedPairs) as any
}
Example #2
Source File: InputSuggestions.tsx From nosgestesclimat-site with MIT License | 5 votes |
export default function InputSuggestions({
suggestions = {},
onSecondClick = (x) => x,
onFirstClick,
}: InputSuggestionsProps) {
const [suggestion, setSuggestion] = useState<ASTNode>()
const { t, i18n } = useTranslation()
return (
<div
className="ui__ notice"
css={`
display: flex;
align-items: baseline;
justify-content: flex-end;
margin-bottom: 0.4rem;
flew-wrap: wrap;
@media (max-width: 800px) {
flex-wrap: nowrap;
overflow-x: auto;
white-space: nowrap;
justify-content: normal;
height: 1.6rem;
scrollbar-width: none;
::-webkit-scrollbar {
display: none;
}
}
`}
>
{toPairs(suggestions).map(([text, value]: [string, ASTNode]) => {
return (
<button
className="ui__ link-button"
type="button"
key={text}
css={`
margin: 0.2rem 0.4rem !important;
:first-child {
margin-left: 0rem !important;
}
`}
onClick={() => {
onFirstClick(value)
if (suggestion !== value) setSuggestion(value)
else onSecondClick && onSecondClick(value)
}}
title={t('Insérer cette suggestion')}
>
{emoji(text)}
</button>
)
})}
</div>
)
}