Skip to content

Commit

Permalink
Merge pull request #28 from data-preservation-programs/fix-reactive-b…
Browse files Browse the repository at this point in the history
…utton-module

fix: zero button component now handles loading state updates correctly
  • Loading branch information
timelytree authored Sep 13, 2023
2 parents 6678853 + 66536d7 commit 4662b6b
Show file tree
Hide file tree
Showing 24 changed files with 39 additions and 69 deletions.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-Black.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-BlackItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-Bold.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-BoldItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-BookItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-Light.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-LightItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-Medium.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-MediumItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-Regular.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-RegularItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-SemiBold.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-SemiBoldItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-Thin.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-ThinItalic.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-Ultralight.otf
Binary file not shown.
Binary file modified assets/fonts/suisse-intl/SuisseIntl-UltralightItalic.otf
Binary file not shown.
29 changes: 21 additions & 8 deletions modules/zero-components/button/components/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
</template>

<script setup>
// ===================================================================== Imports
// ======================================================================= Props
const props = defineProps({
tag: { // 'button', 'a' or 'nuxt-link'
Expand Down Expand Up @@ -51,13 +48,16 @@ const props = defineProps({
}
})
// ======================================================================== Data
const emit = defineEmits(['clicked'])
const store = useZeroButtonStore()
const id = props.loader
const loading = ref(false)
// ======================================================================= Setup
const { $button } = useNuxtApp()
const id = props.loader || useUuid().v4()
const button = await $button(id).register()
const loading = button && button.loading
if (id) {
store.set({ id, loading: false })
}
// ==================================================================== Computed
const component = computed(() => {
Expand All @@ -66,14 +66,27 @@ const component = computed(() => {
return resolveComponent('NuxtLink')
})
// ======================================================================= Watch
watch(store.buttons, (buttons) => {
const found = buttons.find(button => button.id === id)
if (found) {
loading.value = found.loading
}
})
// ===================================================================== Methods
const clickHandler = (e) => {
e.stopPropagation()
if (!props.disabled) {
if (typeof props.loader === 'string') {
$button(id).set({ loading: true })
store.set({ id, loading: true })
}
emit('clicked', e)
}
}
// ======================================================================= Hooks
onBeforeUnmount(() => {
store.remove(id)
})
</script>
5 changes: 1 addition & 4 deletions modules/zero-components/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ export default {
components: [
{ file: 'button.vue', name: 'ZeroButton' }
],
plugins: [
{ file: 'button.js', name: 'zero-button' }
],
stores: [
{ file: 'button.js', name: 'zero-button-store' }
{ file: 'button.js', name: 'useZeroButtonStore' }
]
}
45 changes: 0 additions & 45 deletions modules/zero-components/button/plugins/button.js

This file was deleted.

25 changes: 14 additions & 11 deletions modules/zero-components/button/stores/button.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// ///////////////////////////////////////////////////////////////////// Imports
// -----------------------------------------------------------------------------
import { defineStore } from 'pinia'
import { ref } from '#imports'
import { reactive } from '#imports'

// /////////////////////////////////////////////////////////////////////// State
// -----------------------------------------------------------------------------
const buttons = ref({})
const buttons = reactive([])

// ///////////////////////////////////////////////////////////////////// Actions
// -----------------------------------------------------------------------------
// /////////////////////////////////////////////////////////////////// setButton
const setButton = (payload) => {
buttons.value[payload.id] = payload
return payload
// ///////////////////////////////////////////////////////////////////////// set
const set = (payload) => {
const index = buttons.findIndex(button => button.id === payload.id)
index === -1 ? buttons.push(payload) : buttons.splice(index, 1, payload)
}

// //////////////////////////////////////////////////////////////// removeButton
const removeButton = (id) => {
delete buttons.value[id]
// ////////////////////////////////////////////////////////////////////// remove
const remove = (id) => {
const index = buttons.findIndex(button => button.id === id)
if (id !== -1) {
buttons.splice(index, 1)
}
}

// ////////////////////////////////////////////////////////////////////// Export
Expand All @@ -26,6 +29,6 @@ export const useZeroButtonStore = defineStore('zero-button', () => ({
// ----- state
buttons,
// ----- actions
setButton,
removeButton
set,
remove
}))
1 change: 1 addition & 0 deletions modules/zero-components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const registerStores = (submodule, stores) => {
stores.forEach((store) => {
addImports({
name: store.name,
as: store.name,
from: resolve(`${submodule}/stores/${store.file}`)
})
})
Expand Down
2 changes: 1 addition & 1 deletion nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const baseUrls = {
production: 'https://singularity.storage/'
}

const frontendPort = 10050
const frontendPort = 10070

const seo = {
siteName: 'Singularity',
Expand Down
1 change: 1 addition & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</template>

<script setup>
// ===================================================================== Imports
import BlockBuilder from '@/components/blocks/block-builder'
// ======================================================================== Data
Expand Down

0 comments on commit 4662b6b

Please sign in to comment.