-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(survey): cereal psm and unify some psm parts
- Loading branch information
1 parent
4bbe843
commit 39a0db6
Showing
32 changed files
with
714 additions
and
753 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
151 changes: 0 additions & 151 deletions
151
apps/survey/src/components/elements/GuideImagePanel.vue
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 |
---|---|---|
@@ -1,13 +1,9 @@ | ||
export { default as AsServedWeight } from './AsServedWeight.vue'; | ||
export { default as CategoryContentsView } from './CategoryContentsView.vue'; | ||
export { default as ContextMenu } from './ContextMenu.vue'; | ||
export { default as DrinkScalePanel } from './DrinkScalePanel.vue'; | ||
export { default as ErrorAlert } from './ErrorAlert.vue'; | ||
export { default as FoodBrowser } from './FoodBrowser.vue'; | ||
export { default as FoodSearchResults } from './FoodSearchResults.vue'; | ||
export { default as GuideImagePanel } from './GuideImagePanel.vue'; | ||
export { default as ImagePlaceholder } from './ImagePlaceholder.vue'; | ||
export { default as InfoAlert } from './InfoAlert.vue'; | ||
export { default as QuantityCard } from './QuantityCard.vue'; | ||
export { default as SurveyProgressBar } from './SurveyProgressBar.vue'; | ||
export { default as ValidInvalidIcon } from './ValidInvalidIcon.vue'; |
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
101 changes: 101 additions & 0 deletions
101
apps/survey/src/components/prompts/dynamic/handlers/portion-size/CerealPromptHandler.vue
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,101 @@ | ||
<template> | ||
<cereal-prompt | ||
v-bind="{ continueEnabled, parameters, promptComponent, promptProps }" | ||
:food-name="foodName()" | ||
:initial-state="initialStateNotNull" | ||
@continue="$emit('continue')" | ||
@update="onUpdate" | ||
></cereal-prompt> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import type { PropType } from 'vue'; | ||
import { mapActions } from 'pinia'; | ||
import { defineComponent } from 'vue'; | ||
import type { CerealPromptProps, PortionSizeComponentType } from '@intake24/common/prompts'; | ||
import type { CerealParameters } from '@intake24/common/types/http'; | ||
import type { CerealPromptState } from '@intake24/survey/components/prompts/portion/CerealPrompt.vue'; | ||
import { | ||
createPromptHandlerStoreMixin, | ||
foodPromptUtils, | ||
} from '@intake24/survey/components/prompts/dynamic/handlers/mixins'; | ||
import { CerealPrompt } from '@intake24/survey/components/prompts/portion'; | ||
import { useSurvey } from '@intake24/survey/stores'; | ||
export default defineComponent({ | ||
name: 'CerealPromptHandler', | ||
components: { CerealPrompt }, | ||
mixins: [foodPromptUtils, createPromptHandlerStoreMixin<CerealPromptState>('cereal-prompt')], | ||
props: { | ||
promptProps: { | ||
type: Object as PropType<CerealPromptProps>, | ||
required: true, | ||
}, | ||
promptComponent: { | ||
type: String as PropType<PortionSizeComponentType>, | ||
required: true, | ||
}, | ||
}, | ||
computed: { | ||
parameters(): CerealParameters { | ||
if (this.selectedPortionSize().method !== 'cereal') | ||
throw new Error('Selected portion size method must be "cereal"'); | ||
return this.selectedPortionSize().parameters as unknown as CerealParameters; | ||
}, | ||
}, | ||
methods: { | ||
...mapActions(useSurvey, ['updateFood']), | ||
getFoodOrMealId(): number { | ||
return this.selectedFood().id; | ||
}, | ||
getInitialState(): CerealPromptState { | ||
return { | ||
panel: 0, | ||
objectIdx: undefined, | ||
objectConfirmed: false, | ||
servingImage: null, | ||
servingImageConfirmed: false, | ||
leftoversPrompt: undefined, | ||
leftoversImage: null, | ||
leftoversImageConfirmed: false, | ||
}; | ||
}, | ||
isValid(state: CerealPromptState): boolean { | ||
const objectValid = state.objectIdx !== undefined && state.objectConfirmed; | ||
const servingValid = !!state.servingImage && state.servingImageConfirmed; | ||
const leftoversValid = | ||
state.leftoversPrompt === false || | ||
(!!state.leftoversImage && state.leftoversImageConfirmed); | ||
return objectValid && servingValid && leftoversValid; | ||
}, | ||
async commitAnswer() { | ||
const currentState = this.currentStateNotNull; | ||
this.updateFood({ | ||
foodId: this.selectedFood().id, | ||
update: { | ||
portionSize: { | ||
method: 'cereal', | ||
serving: currentState.servingImage, | ||
leftovers: currentState.leftoversImage, | ||
servingWeight: currentState.servingImage?.weight || 0, | ||
leftoversWeight: currentState.leftoversImage?.weight || 0, | ||
}, | ||
}, | ||
}); | ||
}, | ||
}, | ||
}); | ||
</script> |
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.