Files
TheGame/packages/web/utils/skillHelpers.ts
Alec LaLonde 44c706761c Feature/add timezone frontend (#231)
* Added tz column

* Updated hasura permissions on new table

* Added new dependencies for working with timezones

* Added SetupTimeZone component

* Bumped spacetime-informal to use their types

* Extracted timezone computation into helper, added useMemo hook

* Re-added spacetime types
2020-12-24 23:28:12 -07:00

41 lines
843 B
TypeScript

import { PlayerSkillFragment } from '../graphql/autogen/types';
export type SkillMap = {
[category: string]: CategoryOption;
};
export type SkillOption = PlayerSkillFragment & {
value: string;
label: string;
};
export type CategoryOption = {
label: string;
options: Array<SkillOption>;
};
export const parseSkills = (
skills: Array<PlayerSkillFragment>,
): Array<CategoryOption> => {
const skillsMap: SkillMap = {};
skills.map((skill) => {
if (!(skill.category in skillsMap)) {
skillsMap[skill.category] = {
label: skill.category,
options: [],
};
}
return skillsMap[skill.category].options?.push({
value: skill.id,
label: skill.name,
...skill,
});
});
return Object.values(skillsMap);
};
export type TimeZoneOption = {
value: string;
label: string;
};