-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use ternary operator instead of if statements in useGoalSum…
…maryStore
- Loading branch information
1 parent
1c168bd
commit c91e761
Showing
3 changed files
with
36 additions
and
56 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/components/GoalsComponents/MyGoal/GoalItemSummary/GoalSummary.tsx
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 was deleted.
Oops, something went wrong.
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,35 @@ | ||
import { GoalItem } from "@src/models/GoalItem"; | ||
import { formatSingularPlural, calculateDaysLeft } from "@src/utils"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useSublistSummary } from "./useSublistSummary"; | ||
|
||
const useGoalSummaryStore = (goal: GoalItem) => { | ||
const { t } = useTranslation(); | ||
const { subGoalsCount, subBudgetsCount } = useSublistSummary({ goal }); | ||
|
||
const getSublistSummaryText = () => | ||
goal.due | ||
? "" | ||
: subGoalsCount > 0 && subBudgetsCount === 0 | ||
? formatSingularPlural(subGoalsCount, "goal") | ||
: subBudgetsCount > 0 && subGoalsCount === 0 | ||
? formatSingularPlural(subBudgetsCount, "budget") | ||
: subGoalsCount > 0 && subBudgetsCount > 0 | ||
? `${formatSingularPlural(subGoalsCount, "goal")}, ${formatSingularPlural(subBudgetsCount, "budget")}` | ||
: ""; | ||
|
||
const getDurationSummaryText = () => (goal.duration ? t("hourWithCount", { count: Number(goal.duration) }) : ""); | ||
|
||
const getDueDateSummaryText = () => (goal.due ? calculateDaysLeft(goal.due) : ""); | ||
|
||
const getHabitSummaryText = () => (goal.habit === "weekly" ? t("everyWeek") : ""); | ||
|
||
return { | ||
sublistSummary: getSublistSummaryText(), | ||
durationSummary: getDurationSummaryText(), | ||
dueDateSummary: getDueDateSummaryText(), | ||
habitSummary: getHabitSummaryText(), | ||
}; | ||
}; | ||
|
||
export default useGoalSummaryStore; |