From a6038d336ddab576674a3c8b101759f5ac1ff0e9 Mon Sep 17 00:00:00 2001 From: pghorpade Date: Mon, 16 Sep 2024 13:55:17 -0700 Subject: [PATCH 01/20] feat: set ref ismobile to false and update it in onmounted client side --- src/lib-components/HeaderSmart.vue | 71 +++++++++++++++--------------- src/stories/HeaderSmart.stories.js | 41 +++-------------- 2 files changed, 42 insertions(+), 70 deletions(-) diff --git a/src/lib-components/HeaderSmart.vue b/src/lib-components/HeaderSmart.vue index edca78b77..4a32d8869 100644 --- a/src/lib-components/HeaderSmart.vue +++ b/src/lib-components/HeaderSmart.vue @@ -1,56 +1,55 @@ - diff --git a/src/stories/HeaderSmart.stories.js b/src/stories/HeaderSmart.stories.js index ef2ba6cc1..992ae7b85 100644 --- a/src/stories/HeaderSmart.stories.js +++ b/src/stories/HeaderSmart.stories.js @@ -1,12 +1,15 @@ // Storybook default settings import { useGlobalStore } from '@/stores/GlobalStore' import HeaderSmart from '@/lib-components/HeaderSmart' +import { onMounted, ref } from 'vue' export default { title: 'GLOBAL / Header Smart', component: HeaderSmart, } + + const mock = { secondary: [ { @@ -262,11 +265,11 @@ const mockMicrosite = { // Variations of stories below export function Default() { return { - created() { + setup() { const globalStore = useGlobalStore() globalStore.header.primary = mock.primary globalStore.header.secondary = mock.secondary - globalStore.winWidth = 824 + // To simulate mobile header just resize the storybook window }, components: { HeaderSmart }, @@ -278,11 +281,11 @@ export function Default() { // Variations of stories below export function DefaultMicrosite() { return { - created() { + setup() { const globalStore = useGlobalStore() globalStore.header.primary = mockMicrosite.primary globalStore.header.secondary = mockMicrosite.secondary - globalStore.winWidth = 824 + // To simulate mobile header just resize the storybook window }, components: { HeaderSmart }, @@ -290,33 +293,3 @@ export function DefaultMicrosite() { template: '', } } - -export function DesktopWindowWidth() { - return { - created() { - const globalStore = useGlobalStore() - globalStore.header.primary = mock.primary - globalStore.header.secondary = mock.secondary - globalStore.winWidth = 1200 - }, - components: { HeaderSmart }, - - template: '', - } -} - -export function DesktopWindowWidthMicrosite() { - return { - created() { - const globalStore = useGlobalStore() - globalStore.header.primary = mockMicrosite.primary - globalStore.header.secondary = mockMicrosite.secondary - globalStore.winWidth = 1200 - }, - - components: { HeaderSmart }, - - template: ``, - } -} From a4550b17b20ac037c45add0cba21ebda3f34433c Mon Sep 17 00:00:00 2001 From: pghorpade Date: Fri, 20 Sep 2024 08:07:24 -0700 Subject: [PATCH 02/20] fix: hydration error and undefined errors by adding watchers --- src/lib-components/HeaderMain.vue | 11 ++- src/lib-components/HeaderSmart.vue | 24 ++++-- src/lib-components/IconWithLink.vue | 112 +++++++++++++++----------- src/lib-components/NavSecondary.vue | 79 ++++++++++++++---- src/styles/ftva/_section-wrapper.scss | 44 ++++++++-- 5 files changed, 196 insertions(+), 74 deletions(-) diff --git a/src/lib-components/HeaderMain.vue b/src/lib-components/HeaderMain.vue index 69844a5ff..a7877f48b 100644 --- a/src/lib-components/HeaderMain.vue +++ b/src/lib-components/HeaderMain.vue @@ -32,8 +32,15 @@ const parseTitle = computed(() => { diff --git a/src/lib-components/HeaderSmart.vue b/src/lib-components/HeaderSmart.vue index 4a32d8869..072a9e52e 100644 --- a/src/lib-components/HeaderSmart.vue +++ b/src/lib-components/HeaderSmart.vue @@ -18,25 +18,39 @@ const props = defineProps({ // Access the global store const globalStore = useGlobalStore() const { header } = storeToRefs(globalStore) +// Use refs for primary, secondary menu items, and header type +const primaryMenuItems = ref(header.value.primary || []) +const secondaryMenuItems = ref(header.value.secondary || []) +const currentHeader = ref(HeaderMain) + const isMobile = ref(false) onMounted(() => { const { width } = useWindowSize() watch(width, (newWidth) => { + console.log("newWidth", newWidth) isMobile.value = newWidth <= 1200 + currentHeader.value = isMobile.value ? HeaderMainResponsive : HeaderMain }, { immediate: true }) + + watch( + header, + (newVal, oldVal) => { + console.log('Header updated from parent page', newVal, oldVal) + primaryMenuItems.value = newVal.primary + secondaryMenuItems.value = newVal.secondary + }, + { deep: true, immediate: true } + ) }) -// Computed properties -const primaryMenuItems = computed(() => header.value.primary) -const secondaryMenuItems = computed(() => header.value.secondary) -const whichHeader = computed(() => (isMobile.value ? HeaderMainResponsive : HeaderMain)) +