Skip to content

Commit

Permalink
GOTH-623 (#315)
Browse files Browse the repository at this point in the history
* refactor sticky header
* destickify article newsletter
* lazy load a few components
* Lazy load logo collection
* lazy load sidebar
  • Loading branch information
walsh9 authored Sep 18, 2023
1 parent d74c46c commit 53d5687
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 290 deletions.
25 changes: 13 additions & 12 deletions components/ArticlePageHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import VFlexibleLink from '@nypublicradio/nypr-design-system-vue3/v2/src/components/VFlexibleLink.vue'
import VShareTools from '@nypublicradio/nypr-design-system-vue3/v2/src/components/VShareTools.vue'
import VShareToolsItem from '@nypublicradio/nypr-design-system-vue3/v2/src/components/VShareToolsItem.vue'
import { useCurrentHeaderAdHeight } from '~/composables/states'
const { $analytics } = useNuxtApp()
const props = defineProps({
Expand Down Expand Up @@ -35,18 +34,14 @@ const sidebarIsOpen = useSidebarIsOpen()
const sidebarOpenedFrom = useSidebarOpenedFrom()
const strapline = useStrapline()
const progressPercentage = computed(() => `${props.progress}%`)
const currentHeaderAdHeight = useCurrentHeaderAdHeight()
const openSidebar = (e) => {
sidebarIsOpen.value = true
sidebarOpenedFrom.value = e.target
}
</script>

<template>
<header
class="article-page-header"
:style="`top: ${currentHeaderAdHeight}px;`"
>
<header>
<section class="article-page-header-progress">
<div
class="article-page-header-contents content py-0 my-3 flex align-items-center justify-content-between"
Expand Down Expand Up @@ -158,18 +153,24 @@ const openSidebar = (e) => {

<style lang="scss">
.article-page-header {
opacity: 0;
display: none;
width: 100%;
opacity: 1;
display: block;
width: 100vw;
height: 68px;
position: fixed;
position: absolute;
z-index: 1000;
top: 50px;
top: 0px;
left: -50vw;
background: white;
transition: opacity 0.25s linear;
@include media('>=md') {
top: 0px !important;
position: fixed;
left: 0;
}
}
.article-page-header-enter-active, .article-page-header-leave-active { opacity: 0; }
.article-page-header-progress {
--progressPercentage: v-bind(progressPercentage);
background: linear-gradient(
Expand Down
4 changes: 2 additions & 2 deletions components/CenterFeature.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const articlesSm = ref([
</div>
<div class="col-3 flex-order-3">
<hr class="my-3 block xl:hidden" />
<horizontal-drag :items="articlesSm" v-slot="slotProps">
<lazy-horizontal-drag :items="articlesSm" v-slot="slotProps">
<gothamist-card
v-slot="card"
:article="slotProps.item"
Expand All @@ -119,7 +119,7 @@ const articlesSm = ref([
@link-click="$event => card.trackClick($event)"
/>
</gothamist-card>
</horizontal-drag>
</lazy-horizontal-drag>
<div class="block lg:hidden mb-4 xl:mb-7 m-auto mt-6">
<HtlAd layout="rectangle" slot="htlad-gothamist_index_topper" />
</div>
Expand Down
4 changes: 3 additions & 1 deletion components/GothamistFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ const copyrightYear = ref(props.navigation.copyrightYear)
<div class="block lg:hidden">
<menu-list :navLinks="props.navigation.primaryFooterLinks" />
</div>
<nypr-logos-bracket />
<LoadLazily>
<lazy-nypr-logos-bracket />
</LoadLazily>
</div>
</div>
<hr class="w-full my-4" />
Expand Down
24 changes: 7 additions & 17 deletions components/GothamistMainHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import VFlexibleLink from '@nypublicradio/nypr-design-system-vue3/v2/src/compone
defineProps<{
isMinimized: boolean
isFixed?: boolean
navigation: Navigation
donateUrlBase: string
utmCampaign: string
}>()
const emit = defineEmits(['visible','not-visible'])
const currentSteamStation = useCurrentSteamStation()
const { $analytics } = useNuxtApp()
const sidebarIsOpen = useSidebarIsOpen()
const sidebarOpenedFrom = useSidebarOpenedFrom()
const strapline = await useStrapline()
const currentHeaderAdHeight = useCurrentHeaderAdHeight()
const openSidebar = (e) => {
sidebarIsOpen.value = true
sidebarOpenedFrom.value = e.target
}
const headerElement = ref(null)
const onVisible = () => emit('visible')
const onNotVisible = () => emit('not-visible')
useVisibilityTracking(headerElement, onVisible, onNotVisible)
const trackClick = (category, label) => {
//emitted mobile menu click event
$analytics.sendEvent('click_tracking', {
Expand All @@ -31,9 +35,8 @@ const trackClick = (category, label) => {

<template>
<header
ref="headerElement"
class="gothamist-header"
:class="[{ 'is-fixed': isFixed }]"
:style="isFixed ? `top:${currentHeaderAdHeight}px;` : ``"
>
<div
class="top flex justify-content-between align-items-center sm:align-items-end"
Expand Down Expand Up @@ -107,19 +110,6 @@ const trackClick = (category, label) => {

<style lang="scss">
.gothamist-header {
&.is-fixed {
opacity: 0;
display: none;
position: fixed;
left: 0;
right: 0;
z-index: 100;
background-color: var(--white);
top: 90px;
@include media('>=md') {
top: 0px !important;
}
}
.top,
.bottom {
width: 100%;
Expand Down
82 changes: 0 additions & 82 deletions components/HeaderScrollTrigger.vue

This file was deleted.

5 changes: 2 additions & 3 deletions components/HorizontalDrag.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { ref, onMounted } from 'vue'
import { gsap } from 'gsap'
import { Draggable } from '~/assets/gsap/Draggable.js'
import { InertiaPlugin } from '~/assets/gsap/InertiaPlugin.js'
import breakpoint from '@nypublicradio/nypr-design-system-vue3/src/assets/library/breakpoints.module.scss'
import { ArticlePage } from '~~/composables/types/Page.js'
const props = defineProps<{
items: any[]
Expand All @@ -15,7 +14,7 @@ const dragBoundsRef = ref(null)
const isMobile = ref(false)
const unitMinWidth = 310
const toDragWidth = ref(unitMinWidth * props.items.length)
const toDragWidthPx = ref(toDragWidth.value + 'px')
const toDragWidthPx = ref(`${toDragWidth.value}px`)
onMounted(() => {
// draggable setup
Expand Down
4 changes: 2 additions & 2 deletions components/LeftFeature.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ props.collection.data?.[4] && articlesSm.value.push(normalizeArticlePage(props.c
/>
</gothamist-card>
<hr class="my-3" />
<horizontal-drag v-if="articlesSm" :items="articlesSm" v-slot="slotProps">
<lazy-horizontal-drag v-if="articlesSm" :items="articlesSm" v-slot="slotProps">
<gothamist-card
v-slot="card"
:article="slotProps.item"
Expand All @@ -118,7 +118,7 @@ props.collection.data?.[4] && articlesSm.value.push(normalizeArticlePage(props.c
@link-click="$event => card.trackClick($event)"
/>
</gothamist-card>
</horizontal-drag>
</lazy-horizontal-drag>
</div>
</div>
</div>
Expand Down
28 changes: 28 additions & 0 deletions components/LoadLazily.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script setup lang="ts">
const props = withDefaults(defineProps<{
options?: {
root?: HTMLElement
rootMargin?: string
threshold?: number | number[]
}
}>(), {
options: {
root: null,
rootMargin: '1000px 0px 0px 0px',
threshold: 0
}
})
const element = ref(null)
const seen = ref(false)
const onVisible = () => {seen.value = true}
const onNotVisible = () => { /*do nothing*/ }
useVisibilityTracking(element, onVisible, onNotVisible, props.options )
</script>

<template>
<div ref="element">
<div v-if="seen">
<slot/>
</div>
</div>
</template>
58 changes: 2 additions & 56 deletions components/NewsletterArticle.vue
Original file line number Diff line number Diff line change
@@ -1,68 +1,14 @@
<script setup>
import { onMounted, onBeforeUnmount } from 'vue'
import { gsap } from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger.js'
import { useCurrentHeaderAdHeight } from '~/composables/states'
const props = defineProps({
triggerID: {
type: String,
default: '',
},
pinEndTriggerID: {
type: String,
default: '',
},
pinStartTopOffset: {
type: String,
default: `68px`, // height of the header-ish
},
})
const newsletterElm = ref(null)
const currentHeaderAdHeight = useCurrentHeaderAdHeight()
const uid = 'pinnedNewsletterID'
<script setup lang="ts">
const emit = defineEmits(['submit'])
onMounted(() => {
gsap.registerPlugin(ScrollTrigger)
setTimeout(() => {
// func for the scrollTrigger PIN on the newsletter
ScrollTrigger.create({
trigger: `#${props.triggerID}`,
id: uid,
pin: true,
start: `1px ${props.pinStartTopOffset}`,
endTrigger: `#${props.pinEndTriggerID}`,
end: `top 0%+=${newsletterElm.value.offsetHeight + 40}px`,
//markers: true,
pinSpacing: false,
})
}, 100)
})
onBeforeUnmount(() => {
ScrollTrigger.getById(uid).kill()
})
const refreshScrollTrigger = () => {
const scrollTriggerSelector = ScrollTrigger.getById(uid)
if (scrollTriggerSelector) {
scrollTriggerSelector.refresh()
}
}
watch(currentHeaderAdHeight, (height) => {
refreshScrollTrigger()
})
</script>

<template>
<div ref="newsletterElm" class="newsletter-article">
<div class="newsletter-article">
<newsletter-home
source='gothamist_articleBody'
@submit="emit('submit')"
small
:showBlurb="false"
showX
altDesign
outlined
submitButtonIcon="pi-arrow-right"
Expand Down
7 changes: 1 addition & 6 deletions composables/states.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const useSensitiveContent = () => useState<boolean>('sensitiveContent', (
export const useSidebarIsOpen = () => useState<boolean>('sidebarIsOpen', () => false)
export const useSidebarOpenedFrom = () => useState<HTMLElement>('sidebarOpenedFrom', () => null)
export const useMembershipStatus = () => useState<string>('membershipStatus', () => 'status-unknown')
export const useFixedHeaderVisible = () => useState<boolean>('fixedHeaderVisible', () => false)
export const useNavigation = () => useState<Navigation>('navigation', () => ({
id: 0,
primaryNavigation: [],
Expand Down Expand Up @@ -69,12 +70,6 @@ const currentHeaderAdHeight = 0
*/
export const useCurrentHeaderAdHeight = () => useState('useCurrentHeaderAdHeight', () => currentHeaderAdHeight)

const isArticlePage = false
/**
* Global state for the current AD height.
*/
export const useIsArticlePage = () => useState('useIsArticlePage', () => isArticlePage)

const currentSteamStation = 'wnyc-fm939'
/**
* Global state for the current streaming station.
Expand Down
Loading

0 comments on commit 53d5687

Please sign in to comment.