-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from KaiShoya/refactor/#145_create_stores
Refactor/#145 create stores drinks
- Loading branch information
Showing
9 changed files
with
283 additions
and
121 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "drink-counter", | ||
"version": "1.9.9", | ||
"version": "1.9.10", | ||
"license": "MIT", | ||
"engines": { | ||
"node": "18" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<script setup lang="ts"> | ||
import { storeToRefs } from 'pinia' | ||
import { usePageDrinkNewStore } from '~/store/pages/drinks/new' | ||
const drinkNewStore = usePageDrinkNewStore() | ||
const { name, color } = storeToRefs(drinkNewStore) | ||
const { initPage, create } = drinkNewStore | ||
initPage() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<div class="field"> | ||
<label class="label">{{ $t('drinks.name') }}</label> | ||
<div class="control"> | ||
<input | ||
v-model="name" | ||
class="input" | ||
type="text" | ||
placeholder="ビール" | ||
> | ||
</div> | ||
</div> | ||
|
||
<div class="field"> | ||
<label class="label">{{ $t('drinks.color') }}</label> | ||
<div class="control columns is-vcentered is-mobile"> | ||
<div | ||
class="column" | ||
style="flex: none; margin-left: 12px;" | ||
> | ||
<input | ||
v-model="color" | ||
type="color" | ||
> | ||
</div> | ||
<input | ||
v-model="color" | ||
class="input column" | ||
type="text" | ||
placeholder="#000000" | ||
> | ||
<div | ||
class="column" | ||
style="flex: none; margin-right: 12px;" | ||
> | ||
<button | ||
class="button" | ||
@click="color = generateRandomColor()" | ||
> | ||
<span class="icon is-medium"> | ||
<i class="mdi mdi-cached mdi-24px" /> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<button | ||
class="button" | ||
@click="create()" | ||
> | ||
{{ $t('drinks.add') }} | ||
</button> | ||
|
||
<NuxtLink | ||
to="/drinks" | ||
class="button" | ||
> | ||
{{ $t('drinks.cancel') }} | ||
</NuxtLink> | ||
</div> | ||
</div> | ||
</template> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useDrinksStore } from '~/store/data/drinks' | ||
|
||
export const usePageDrinkEditStore = defineStore('pageDrinkEditStore', () => { | ||
const { $i18n } = useNuxtApp() | ||
const route = useRoute() | ||
const drinksStore = useDrinksStore() | ||
const { fetchDrinks, findDrink, updateDrink } = drinksStore | ||
|
||
// 編集対象のドリンクID | ||
const drinkId = Number(route.params.id) | ||
|
||
// 編集対象のドリンク名 | ||
const name = ref<string>('') | ||
// 編集対象の色 | ||
const color = ref<string | null>(null) | ||
|
||
const initPage = async () => { | ||
const error = await fetchDrinks() | ||
if (error) { | ||
showDangerToast($i18n.t(error)) | ||
return | ||
} | ||
|
||
const drink = findDrink(drinkId) | ||
if (drink === undefined) { | ||
showDangerToast($i18n.t('error.GET_RECORD')) | ||
navigateTo('/drinks') | ||
} else { | ||
name.value = drink.name | ||
color.value = drink.color | ||
} | ||
} | ||
|
||
const updateDrinkById = async () => { | ||
const error = await updateDrink(drinkId, name.value, color.value) | ||
if (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error) | ||
showDangerToast($i18n.t('drinks.update_failure', { name: name.value })) | ||
} else { | ||
showSuccessToast($i18n.t('drinks.update_success', { name: name.value })) | ||
navigateTo('/drinks') | ||
} | ||
} | ||
|
||
return { | ||
drinkId, | ||
name, | ||
color, | ||
initPage, | ||
updateDrinkById, | ||
} | ||
}) |
Oops, something went wrong.
f222ec9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
drink-counter – ./
drink-counter-git-main-shoya85.vercel.app
drink-counter-theta.vercel.app
drink-counter-shoya85.vercel.app