Skip to content

Commit

Permalink
Use store in components
Browse files Browse the repository at this point in the history
Signed-off-by: Grigory V <scratchx@gmx.com>
  • Loading branch information
GVodyanov committed Jan 14, 2024
1 parent 122509c commit b4b5c2d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
9 changes: 5 additions & 4 deletions src/components/AppNavigation/AppointmentConfigList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ import PlusIcon from 'vue-material-design-icons/Plus.vue'
import AppointmentConfigModal from '../AppointmentConfigModal.vue'
import AppointmentConfig from '../../models/appointmentConfig.js'
import logger from '../../utils/logger.js'
import { mapGetters } from 'vuex'
import NoEmailAddressWarning from '../AppointmentConfigModal/NoEmailAddressWarning.vue'
import useAppointmentConfigsStore from '../../store/appointmentConfigs.js'

export default {
name: 'AppointmentConfigList',
Expand All @@ -87,9 +87,10 @@ export default {
}
},
computed: {
...mapGetters({
configs: 'allConfigs',
}),
configs() {
const store = useAppointmentConfigsStore()

Check warning on line 91 in src/components/AppNavigation/AppointmentConfigList.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppNavigation/AppointmentConfigList.vue#L90-L91

Added lines #L90 - L91 were not covered by tests
return store.allConfigs
},
defaultConfig() {
return AppointmentConfig.createDefault(
this.calendarUrlToUri(this.$store.getters.ownSortedCalendars[0].url),
Expand Down
8 changes: 6 additions & 2 deletions src/components/AppointmentConfigModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ import CheckedDurationSelect from './AppointmentConfigModal/CheckedDurationSelec
import VisibilitySelect from './AppointmentConfigModal/VisibilitySelect.vue'
import logger from '../utils/logger.js'
import Confirmation from './AppointmentConfigModal/Confirmation.vue'
import useAppointmentConfigsStore from '../store/appointmentConfigs.js'

export default {
name: 'AppointmentConfigModal',
Expand Down Expand Up @@ -201,6 +202,7 @@ export default {
enableFutureLimit: false,
rateLimitingReached: false,
showConfirmation: false,
store: useAppointmentConfigsStore(),
}
},
computed: {
Expand Down Expand Up @@ -308,10 +310,12 @@ export default {
try {
if (this.isNew) {
logger.info('Creating new config', { config })
this.editing = await this.$store.dispatch('createConfig', { config })
// this.editing = await this.$store.dispatch('createConfig', { config })
this.editing = await this.store.createConfig({ config })

Check warning on line 314 in src/components/AppointmentConfigModal.vue

View check run for this annotation

Codecov / codecov/patch

src/components/AppointmentConfigModal.vue#L314

Added line #L314 was not covered by tests
} else {
logger.info('Saving config', { config })
this.editing = await this.$store.dispatch('updateConfig', { config })
// this.editing = await this.$store.dispatch('updateConfig', { config })
this.editing = await this.store.updateConfig({ config })
}
this.showConfirmation = true
} catch (error) {
Expand Down
9 changes: 4 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import VTooltip from 'v-tooltip'
import VueShortKey from 'vue-shortkey'
import windowTitleService from './services/windowTitleService.js'
import { createPinia, PiniaVuePlugin } from 'pinia'
import useAppointmentConfigsStore from './store/appointmentConfigs.js'

Vue.use(PiniaVuePlugin)
const pinia = createPinia()

Check warning on line 48 in src/main.js

View check run for this annotation

Codecov / codecov/patch

src/main.js#L47-L48

Added lines #L47 - L48 were not covered by tests
Expand Down Expand Up @@ -73,15 +74,13 @@ Vue.prototype.n = translatePlural

windowTitleService(router, store)

store.commit(
'addInitialConfigs',
loadState('calendar', 'appointmentConfigs', []).map(config => new AppointmentConfig(config))
)

export default new Vue({
el: '#content',
router,
store,
render: h => h(App),
pinia,
})

const appointmentsConfigsStore = useAppointmentConfigsStore()
appointmentsConfigsStore.addInitialConfigs(loadState('calendar', 'appointmentConfigs', []).map(config => new AppointmentConfig(config)))

Check warning on line 86 in src/main.js

View check run for this annotation

Codecov / codecov/patch

src/main.js#L85-L86

Added lines #L85 - L86 were not covered by tests
9 changes: 7 additions & 2 deletions src/store/appointmentConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ export default defineStore('appointmentConfig', {
}
},
getters: {
allConfigs(state) {
return Object.values(state.configs)
allConfigs() {
return Object.values(this.configs)

Check warning on line 35 in src/store/appointmentConfigs.js

View check run for this annotation

Codecov / codecov/patch

src/store/appointmentConfigs.js#L34-L35

Added lines #L34 - L35 were not covered by tests
},
},
actions: {
addInitialConfigs(configs) {
for (const config of configs) {
this.configs[config.id] = config

Check warning on line 41 in src/store/appointmentConfigs.js

View check run for this annotation

Codecov / codecov/patch

src/store/appointmentConfigs.js#L39-L41

Added lines #L39 - L41 were not covered by tests
}
},
async updateConfig({ config }) {
try {
const updatedConfig = await updateConfig(config)
Expand Down

0 comments on commit b4b5c2d

Please sign in to comment.