Skip to content

Commit

Permalink
refactor(#491): use service for wine logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyckahn committed Apr 30, 2024
1 parent c8e4717 commit 83e2d09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/components/WineRecipeList/WineRecipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import CardHeader from '@mui/material/CardHeader'
import CardActions from '@mui/material/CardActions'
import Button from '@mui/material/Button'

import {
grapeVarietyNameMap,
wineVarietyValueMap,
} from '../../data/crops/grape'
import { grapeVarietyNameMap } from '../../data/crops/grape'
import { wineService } from '../../services/wine'
import { grapeVariety } from '../../enums'
import { wines } from '../../img'
import { integerString } from '../../utils'
Expand Down Expand Up @@ -37,7 +35,7 @@ export const WineRecipe = ({ wineVariety }) => {
<>
<p>
Days to mature:{' '}
{integerString(3 * wineVarietyValueMap[wineVariety])}
{integerString(wineService.getDaysToMature(wineVariety))}
</p>
{
// FIXME: Show type and number of grapes required (4x their wineVarietyValueMap value)
Expand Down
21 changes: 21 additions & 0 deletions src/services/wine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* @typedef {import('../enums').grapeVariety} grapeVarietyEnum
*/

import { wineVarietyValueMap } from '../data/crops/grape'

export class WineService {
/**
* @private
*/
maturityDayMultiplier = 3

/**
* @param {grapeVarietyEnum} grapeVariety
*/
getDaysToMature = grapeVariety => {
return wineVarietyValueMap[grapeVariety] * this.maturityDayMultiplier
}
}

export const wineService = new WineService()

0 comments on commit 83e2d09

Please sign in to comment.