Skip to content

Commit

Permalink
Merge branch 'main' into follow-up-notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
daiagi committed Apr 12, 2023
2 parents 5426161 + 922eb95 commit b92bb03
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 36 deletions.
26 changes: 23 additions & 3 deletions components/collection/activity/OwnerInsights.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
<div
class="mr-4 is-clickable"
:class="{ 'has-text-weight-bold': activeTab === Tabs.holders }"
@click="activeTab = Tabs.holders">
@click="changeTab(Tabs.holders)">
{{ $t('holders') }}
</div>
<div
class="is-clickable"
:class="{ 'has-text-weight-bold': activeTab === Tabs.flippers }"
@click="activeTab = Tabs.flippers">
@click="changeTab(Tabs.flippers)">
{{ $t('flippers') }}
</div>
</div>
<div class="py-4 limit-height is-scrollable">
<div ref="container" class="py-4 limit-height is-scrollable">
<HoldersTab v-if="activeTab === Tabs.holders" :owners="owners" />
<FlippersTab v-if="activeTab === Tabs.flippers" :flippers="flippers" />
</div>
Expand All @@ -36,6 +36,26 @@ defineProps<{
flippers?: Flippers
}>()
const activeTab = ref(Tabs.holders)
const container = ref<HTMLDivElement | null>(null)
const scrollPositions = {
[Tabs.holders]: 0,
[Tabs.flippers]: 0,
}
const changeTab = (tab: Tabs) => {
// Store the current scroll position
if (container.value) {
scrollPositions[activeTab.value] = container.value.scrollTop
}
// Set the new active tab and restore the previous scroll position
// this is done in order to optimize performance and prevent unnecessary loading
// since HolderTab and FlippersTab are lazy loaded
activeTab.value = tab
if (container.value) {
container.value.scrollTop = scrollPositions[tab]
}
}
</script>

<style lang="scss" scoped>
Expand Down
26 changes: 18 additions & 8 deletions components/collection/activity/ownerInsightsTabs/FlipperTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
v-for="[
flipperId,
{ bestFlip, owned, totalBought, totalsold, latestflipTimestamp, flips },
] in flippers"
] in displayedFlippers"
:key="flipperId"
class="hide-last-hr">
<div class="is-flex is-flex-direction-column gap">
Expand Down Expand Up @@ -67,6 +67,7 @@
</div>
<hr class="my-3 mx-5" />
</div>
<div ref="target" />
</div>
</template>

Expand All @@ -78,6 +79,13 @@ import { format } from '@/components/collection/activity/utils'
import NFTsDetaislDropdown from './NFTsDetaislDropdown.vue'
import { timeAgo } from '@/components/collection/utils/timeAgo'
import { Flippers } from '@/composables/collectionActivity/types'
const props = defineProps<{
flippers?: Flippers
}>()
const target = ref<HTMLElement | null>(null)
const offset = ref(4)
const flippers = computed(() => Object.entries(props.flippers || {}))
const toggleNFTDetails = (flipperId: string) => {
const isOpen = isNFTDetailsOpen.value[flipperId]
Expand All @@ -86,22 +94,24 @@ const toggleNFTDetails = (flipperId: string) => {
[flipperId]: !isOpen,
}
}
const flippers = computed(() => Object.entries(props.flippers || {}))
useIntersectionObserver(target, ([{ isIntersecting }]) => {
if (isIntersecting) {
offset.value += 4
}
})
const displayedFlippers = computed(() => flippers.value.slice(0, offset.value))
// map of flipper id to bolean, is the NFT details section of that flipper open or nor
// {id0: false, id1: true, id3: false, ...}
const isFlipperMoreNFTSectionOpen = flippers.value.reduce(
(accumelator, [holderId, _]) => ({
(accumelator, [flipperId, _]) => ({
...accumelator,
[holderId]: false,
[flipperId]: false,
}),
{}
)
const isNFTDetailsOpen = ref(isFlipperMoreNFTSectionOpen)
const props = defineProps<{
flippers?: Flippers
}>()
</script>

<style lang="scss" scoped>
Expand Down
22 changes: 18 additions & 4 deletions components/collection/activity/ownerInsightsTabs/HolderTab.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div>
<div v-for="[holderId, holdings] in holders" :key="holderId" class="">
<div
v-for="[holderId, holdings] in displayedHolders"
:key="holderId"
class="">
<div class="is-flex is-flex-direction-column gap">
<div class="px-5">
<ProfileLink
Expand Down Expand Up @@ -53,6 +56,7 @@
</div>
<hr class="my-3 mx-5" />
</div>
<div ref="target" />
</div>
</template>

Expand All @@ -64,13 +68,15 @@ import { NeoIcon } from '@kodadot1/brick'
import NFTsDetaislDropdown from './NFTsDetaislDropdown.vue'
import { timeAgo } from '@/components/collection/utils/timeAgo'
const toggleNFTDetails = (flipperId: string) => {
const isOpen = isNFTDetailsOpen.value[flipperId]
const toggleNFTDetails = (holderId: string) => {
const isOpen = isNFTDetailsOpen.value[holderId]
isNFTDetailsOpen.value = {
...isNFTDetailsOpen.value,
[flipperId]: !isOpen,
[holderId]: !isOpen,
}
}
const target = ref<HTMLElement | null>(null)
const offset = ref(4)
const holders = computed(() =>
Object.entries(props.owners || {}).sort(
Expand All @@ -79,6 +85,14 @@ const holders = computed(() =>
)
)
useIntersectionObserver(target, ([{ isIntersecting }]) => {
if (isIntersecting) {
offset.value += 4
}
})
const displayedHolders = computed(() => holders.value.slice(0, offset.value))
// map of owner id to bolean, is the NFT details section of that owner open or nor
// {id0: false, id1: true, id3: false, ...}
const isNFTDetailsOpen = ref(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div v-if="ready" class="">
<div
v-for="{ avatar, boughtPrice, soldPrice, profit, nft } in flips"
v-for="{ avatar, boughtPrice, soldPrice, profit, nft } in displayedFlips"
:key="nft.id"
class="is-flex py-2 px-5 is-justify-content-start is-hoverable-item is-flex-direction-column">
<div class="is-flex">
Expand All @@ -11,8 +11,13 @@
:alt="nft.name"
width="40"
height="40"
class="border mr-5" />
<img v-else src="/placeholder.webp" class="border mr-5" />
class="border mr-5 image-size" />
<img
v-else
src="/placeholder.webp"
class="border mr-5 image-size"
width="40"
height="40" />
<span>{{ nft.name }}</span>
</div>
<div
Expand Down Expand Up @@ -41,6 +46,7 @@
</div>
</div>
</div>
<div ref="target" />
</div>
</template>

Expand All @@ -59,13 +65,20 @@ const props = defineProps<{
const flips = ref(props.flips)
const ready = ref(false)
onMounted(() => {
processNFTImages()
const target = ref<HTMLElement | null>(null)
const offset = ref(4)
useIntersectionObserver(target, ([{ isIntersecting }]) => {
if (isIntersecting) {
offset.value += 4
}
})
const displayedFlips = computed(() => flips.value.slice(0, offset.value))
const processNFTImages = async () => {
if (props.flips) {
const promises = props.flips.map(async ({ nft }, i) => {
const promises = displayedFlips.value.map(async ({ nft }, i) => {
let avatar
if (nft.meta?.image) {
avatar = sanitizeIpfsUrl(nft.meta.image)
Expand All @@ -82,4 +95,19 @@ const processNFTImages = async () => {
ready.value = true
}
}
watch(
offset,
() => {
processNFTImages()
},
{ immediate: true }
)
</script>

<style lang="scss" scoped>
.image-size {
width: 40px !important;
height: 40px !important;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div v-if="ready" class="">
<div
v-for="{ avatar, id, name, updatedAt } in nfts"
v-for="{ avatar, id, name, updatedAt } in displayedNFTs"
:key="id"
class="is-flex pt-2 px-5 is-justify-content-start is-hoverable-item">
<div class="mr-5">
Expand All @@ -11,8 +11,13 @@
:alt="name"
width="40"
height="40"
class="border" />
<img v-else src="/placeholder.webp" class="border mr-5" />
class="border image-size" />
<img
v-else
src="/placeholder.webp"
class="border mr-5 image-size"
width="40"
height="40" />
</div>
<div class="is-flex is-flex-direction-column">
{{ name }}
Expand All @@ -21,6 +26,7 @@
}}</span>
</div>
</div>
<div ref="target" />
</div>
</template>

Expand All @@ -38,13 +44,20 @@ const props = defineProps<{
const nfts = ref(props.nfts)
const ready = ref(false)
onMounted(() => {
processNFTImages()
const target = ref<HTMLElement | null>(null)
const offset = ref(4)
useIntersectionObserver(target, ([{ isIntersecting }]) => {
if (isIntersecting) {
offset.value += 4
}
})
const displayedNFTs = computed(() => nfts.value.slice(0, offset.value))
const processNFTImages = async () => {
if (props.nfts) {
const promises = props.nfts.map(async (nft, i) => {
const promises = displayedNFTs.value.map(async (nft, i) => {
let avatar
if (nft.meta?.image) {
avatar = sanitizeIpfsUrl(nft.meta.image)
Expand All @@ -53,12 +66,27 @@ const processNFTImages = async () => {
avatar = sanitizeIpfsUrl(meta?.image)
}
nfts.value[i].avatar = avatar
displayedNFTs.value[i].avatar = avatar
})
await Promise.all(promises)
ready.value = true
}
}
watch(
offset,
() => {
processNFTImages()
},
{ immediate: true }
)
</script>

<style lang="scss" scoped>
.image-size {
width: 40px !important;
height: 40px !important;
}
</style>
9 changes: 1 addition & 8 deletions components/common/IdentityForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ type IdentityFields = Record<string, string>
const { $store, $i18n } = useNuxtApp()
const { apiUrl, apiInstance } = useApi()
const { urlPrefix } = usePrefix()
const { accountId } = useAuth()
const { howAboutToExecute, isLoading, initTransactionLoader, status } =
useMetaTransaction()
Expand All @@ -121,13 +120,7 @@ const identity = ref<Record<string, string>>({
legal: '',
})
const deposit = ref('0')
const inputLengthLimit = computed(() => {
if (urlPrefix.value === 'bsx' || urlPrefix.value === 'snek') {
return 32
}
return undefined
})
const inputLengthLimit = ref(32)
onBeforeMount(async () => {
onApiConnect(apiUrl.value, async (api) => {
Expand Down

0 comments on commit b92bb03

Please sign in to comment.