Skip to content

Commit

Permalink
Refactor buttons and improve auto scroll on pagination events (#119)
Browse files Browse the repository at this point in the history
* add new packages button component

* replace new packages button to component

* refactor auto scroll on page change

* rename property

* formatting

* refactor official package toggle

* Fix formatting

---------

Co-authored-by: HassanZahirnia <m.hassan.zahirnia@gmail.com>
  • Loading branch information
514sid and HassanZahirnia authored Aug 19, 2023
1 parent b2adb19 commit eaadb1d
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 78 deletions.
89 changes: 11 additions & 78 deletions components/package/list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ watch(
results.value = newPackagesSinceLastVisit.value
// if newPage is changed, scroll to #scroll-to-reference element
if (newPage !== oldPage) {
if (newPage !== oldPage && oldPage !== undefined) {
nextTick(() => {
// If device width is less than 640px (mobile), scroll to #scroll-to-reference element
if (process.client && window.innerWidth < 640)
if (process.client)
document.querySelector('#scroll-to-reference')?.scrollIntoView({ behavior: 'smooth' })
})
}
Expand Down Expand Up @@ -365,43 +364,12 @@ const categoriesForSelectboxWithAll = [
</div>
</transition>
<!-- New Since Last Visit Button -->
<ui-tooltip
<ui-new-packages-button
v-if="newPackagesSinceLastVisit.length"
:content="newPackagesSinceLastVisit.length + ' New packages were added since your last visit !'"
theme="emerald"
@click.stop.prevent="showNewPackagesSinceLastVisit = !showNewPackagesSinceLastVisit"
>
<div

class="py-1.5 px-4 select-none
rounded-full cursor-pointer
transition-all duration-300
flex gap-2 items-center
font-medium
hover:brightness-105
"
:class="{
'bg-slate-300/50 dark:bg-slate-700/50 text-slate-600 dark:text-slate-400': !showNewPackagesSinceLastVisit,
'bg-teal-200/70 text-teal-600 dark:text-teal-500 dark:bg-teal-500/20': showNewPackagesSinceLastVisit,
}"
>
<span class="relative flex h-2.5 w-2.5">
<span
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-teal-400"
:class="{
'opacity-75': !showNewPackagesSinceLastVisit,
'opacity-0': showNewPackagesSinceLastVisit,
}"
/>
<span class="relative inline-flex rounded-full h-2.5 w-2.5 bg-teal-500" />
</span>
<div class="">
{{ newPackagesSinceLastVisit.length }}
<span class="inline">New Item</span>
<span class="inline">{{ newPackagesSinceLastVisit.length > 1 ? 's' : '' }}</span>
</div>
</div>
</ui-tooltip>
:new-packages-count="newPackagesSinceLastVisit.length"
:is-active="showNewPackagesSinceLastVisit"
@toggle="showNewPackagesSinceLastVisit = !showNewPackagesSinceLastVisit"
/>
</div>
<div
class="xl:flex-1
Expand All @@ -413,45 +381,10 @@ const categoriesForSelectboxWithAll = [
"
>
<!-- Crown/Official package toggle -->
<div class="flex-1 flex justify-start min-[920px]:justify-end w-40">
<div
class="relative rounded-xl cursor-pointer group select-none
transition-all duration-300 ease-out
delay-100
overflow-hidden
w-[12.5rem] sm:w-40 lg:w-11 h-11
flex gap-2 items-center
lg:hover:w-40
"
:class="{
'bg-white/50 dark:bg-[#362B59]/30 dark:hover:bg-[#362B59]/40': showOfficialPackages !== '1',
'lg:w-40 bg-white hover:bg-white/80 dark:bg-indigo-500/20 dark:hover:bg-indigo-500/10': showOfficialPackages === '1',
}"
@click="showOfficialPackages = showOfficialPackages === '1' ? '0' : '1'"
>
<div
class="i-fluent-emoji-crown text-2xl
shrink-0
mb-1 ml-2.5
"
/>
<div
class="truncate
leading-5
sm:text-xs
transition duration-300
delay-100
lg:opacity-0
lg:group-hover:opacity-100
"
:class="{
'lg:opacity-100': showOfficialPackages === '1',
}"
>
Official Packages
</div>
</div>
</div>
<ui-official-package-toggle
:is-active="showOfficialPackages"
@toggle="showOfficialPackages = showOfficialPackages === '1' ? '0' : '1'"
/>
<!-- Search bar -->
<ui-search-input />
<!-- Sort -->
Expand Down
48 changes: 48 additions & 0 deletions components/ui/new-packages-button.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<script setup lang="ts">
defineProps<{
newPackagesCount: number,
isActive: boolean
}>()
const $emit = defineEmits<{
(e: 'toggle'): void
}>()
</script>

<template>
<ui-tooltip
:content="newPackagesCount + ' New packages were added since your last visit !'"
theme="emerald"
@click.stop.prevent="$emit('toggle')"
>
<div
class="py-1.5 px-4 select-none
rounded-full cursor-pointer
transition-all duration-300
flex gap-2 items-center
font-medium
hover:brightness-105
"
:class="{
'bg-slate-300/50 dark:bg-slate-700/50 text-slate-600 dark:text-slate-400': !isActive,
'bg-teal-200/70 text-teal-600 dark:text-teal-500 dark:bg-teal-500/20': isActive,
}"
>
<span class="relative flex h-2.5 w-2.5">
<span
class="animate-ping absolute inline-flex h-full w-full rounded-full bg-teal-400"
:class="{
'opacity-75': !isActive,
'opacity-0': isActive,
}"
/>
<span class="relative inline-flex rounded-full h-2.5 w-2.5 bg-teal-500" />
</span>
<div class="">
{{ newPackagesCount }}
<span class="inline">New Item</span>
<span class="inline">{{ newPackagesCount > 1 ? 's' : '' }}</span>
</div>
</div>
</ui-tooltip>
</template>
51 changes: 51 additions & 0 deletions components/ui/official-package-toggle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script setup lang="ts">
defineProps<{
isActive: '0' | '1' | ''
}>()
const $emit = defineEmits<{
(e: 'toggle'): void
}>()
</script>

<template>
<div class="flex-1 flex justify-start min-[920px]:justify-end w-40">
<div
class="relative rounded-xl cursor-pointer group select-none
transition-all duration-300 ease-out
delay-100
overflow-hidden
w-[12.5rem] sm:w-40 lg:w-11 h-11
flex gap-2 items-center
lg:hover:w-40
"
:class="{
'bg-white/50 dark:bg-[#362B59]/30 dark:hover:bg-[#362B59]/40': isActive !== '1',
'lg:w-40 bg-white hover:bg-white/80 dark:bg-indigo-500/20 dark:hover:bg-indigo-500/10': isActive === '1',
}"
@click="$emit('toggle')"
>
<div
class="i-fluent-emoji-crown text-2xl
shrink-0
mb-1 ml-2.5
"
/>
<div
class="truncate
leading-5
sm:text-xs
transition duration-300
delay-100
lg:opacity-0
lg:group-hover:opacity-100
"
:class="{
'lg:opacity-100': isActive === '1',
}"
>
Official Packages
</div>
</div>
</div>
</template>

0 comments on commit eaadb1d

Please sign in to comment.