Skip to content

Commit

Permalink
Merge pull request #285 from poap-xyz/release/v1.13.12
Browse files Browse the repository at this point in the history
Release v1.13.12
  • Loading branch information
jm42 authored May 21, 2024
2 parents e530707 + 780ba8d commit 1451daa
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 143 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poap-family",
"version": "1.13.11",
"version": "1.13.12",
"author": {
"name": "POAP",
"url": "https://poap.xyz"
Expand Down
14 changes: 7 additions & 7 deletions src/components/EventCount.js → src/components/EventPower.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import PropTypes from 'prop-types'
import { DropProps } from 'models/drop'
import TokenImage from 'components/TokenImage'
import 'styles/event-count.css'
import 'styles/event-power.css'

/**
* @param {PropTypes.InferProps<EventCount.propTypes>} props
* @param {PropTypes.InferProps<EventPower.propTypes>} props
*/
function EventCount({ event, count, size = 64 }) {
function EventPower({ event, count, size = 64 }) {
return (
<div className="event-count">
<div className="event-power">
<TokenImage event={event} size={size} />
<span className="count">{count}</span>
<span className="power">{count}</span>
</div>
)
}

EventCount.propTypes = {
EventPower.propTypes = {
event: PropTypes.shape(DropProps).isRequired,
count: PropTypes.number.isRequired,
size: PropTypes.number,
}

export default EventCount
export default EventPower
81 changes: 81 additions & 0 deletions src/components/EventsPowers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import PropTypes from 'prop-types'
import { Link } from 'react-router-dom'
import { clsx } from 'clsx'
import { DropProps } from 'models/drop'
import TokenImage from 'components/TokenImage'
import EventPower from 'components/EventPower'
import 'styles/events-powers.css'

/**
* @param {PropTypes.InferProps<EventsPowers.propTypes>} props
*/
function EventsPowers({
showAll = false,
perfectPower,
selectedEventIds,
onSelect,
events,
powers,
size = 64,
children,
}) {
return (
<div className={clsx('events-powers', showAll && 'show-all')}>
{powers.map(({ eventId, power }) => (
<div
key={eventId}
className={clsx('event-power-card', {
selected: selectedEventIds.includes(eventId),
perfect: perfectPower === power,
})}
title={events[eventId].name}
>
<button
className="event-select-button"
onClick={() => onSelect(eventId)}
style={{
width: `${size}px`,
height: `${size}px`,
}}
>
{perfectPower === power
? <TokenImage event={events[eventId]} size={size} />
: <EventPower
event={events[eventId]}
count={power}
size={size}
/>
}
</button>
<Link
to={`/event/${eventId}`}
className="event-id"
>
#{eventId}
</Link>
</div>
))}
{children}
</div>
)
}

EventsPowers.propTypes = {
showAll: PropTypes.bool,
perfectPower: PropTypes.number,
selectedEventIds: PropTypes.arrayOf(PropTypes.number.isRequired).isRequired,
onSelect: PropTypes.func.isRequired,
events: PropTypes.objectOf(
PropTypes.shape(DropProps).isRequired
).isRequired,
powers: PropTypes.arrayOf(
PropTypes.shape({
eventId: PropTypes.number.isRequired,
power: PropTypes.number.isRequired,
}).isRequired
).isRequired,
size: PropTypes.number,
children: PropTypes.node,
}

export default EventsPowers
151 changes: 66 additions & 85 deletions src/components/InCommon.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import PropTypes from 'prop-types'
import { createRef, useContext, useEffect, useMemo, useState } from 'react'
import { Link } from 'react-router-dom'
import { clsx } from 'clsx'
import { SettingsContext } from 'stores/cache'
import { DropProps } from 'models/drop'
import {
Expand All @@ -15,13 +13,12 @@ import { intersection } from 'utils/array'
import { getColorForSeed } from 'utils/color'
import ButtonLink from 'components/ButtonLink'
import Card from 'components/Card'
import EventHeader from 'components/EventHeader'
import ErrorMessage from 'components/ErrorMessage'
import EventCount from 'components/EventCount'
import EventHeader from 'components/EventHeader'
import EventsPowers from 'components/EventsPowers'
import EventButtonGroup from 'components/EventButtonGroup'
import AddressOwner from 'components/AddressOwner'
import ButtonGroup from 'components/ButtonGroup'
import TokenImage from 'components/TokenImage'
import ButtonClose from 'components/ButtonClose'
import 'styles/in-common.css'

Expand All @@ -32,7 +29,7 @@ function InCommon({
children,
inCommon: initialInCommon = {},
events = {},
showCount = 0,
showCount,
showActive = true,
createButtons =
/**
Expand Down Expand Up @@ -85,27 +82,41 @@ function InCommon({
[inCommonEntries]
)

let inCommonEventsAddresses = inCommonEntries.slice()
let inCommonLimit = INCOMMON_EVENTS_LIMIT

if (showCount != null && showCount > 0) {
inCommonLimit = inCommonEventsAddresses.reduce(
(limit, [, addresses]) => {
if (addresses.length === showCount) {
return limit + 1
}
return limit
},
0
)
}
const inCommonLimit = useMemo(
() => {
if (showCount == null) {
return INCOMMON_EVENTS_LIMIT
}
return inCommonEntries.reduce(
(limit, [, addresses]) => {
if (addresses.length === showCount) {
return limit + 1
}
return limit
},
0
)
},
[inCommonEntries, showCount]
)

const inCommonTotal = inCommonEventsAddresses.length
const hasMore = inCommonTotal > inCommonLimit
const inCommonEventsAddresses = useMemo(
() => {
if (!showAll && inCommonEntries.length > inCommonLimit) {
return inCommonEntries.slice(0, inCommonLimit)
}
return inCommonEntries.slice()
},
[inCommonEntries, inCommonLimit, showAll]
)

if (hasMore && !showAll) {
inCommonEventsAddresses = inCommonEventsAddresses.slice(0, inCommonLimit)
}
const powers = useMemo(
() => inCommonEventsAddresses.map(([eventId, addresses]) => ({
eventId,
power: addresses.length,
})),
[inCommonEventsAddresses]
)

/**
* @param {number} eventId
Expand Down Expand Up @@ -139,19 +150,26 @@ function InCommon({
}
}

const activeAdressesColors = activeEventIds.length < 2 ? {} :
Object.fromEntries(
intersection(
// @ts-ignore
...activeEventIds.map((activeEventId) => inCommon[activeEventId])
)
.map(
(address) => [
address,
getColorForSeed(address),
]
)
)
const activeAdressesColors = useMemo(
() => activeEventIds.length < 2
? {}
: Object.fromEntries(
intersection(
// @ts-ignore
...activeEventIds.map((activeEventId) => inCommon[activeEventId])
)
.map(
(address) => [
address,
getColorForSeed(address),
]
)
),
[activeEventIds, inCommon]
)

const inCommonTotal = inCommonEntries.length
const hasMore = inCommonTotal > inCommonLimit

useEffect(
() => {
Expand Down Expand Up @@ -244,57 +262,20 @@ function InCommon({
)}
{inCommonTotal > 0 && (
<h4>
{showCount != null && showCount > 0 && `${inCommonLimit} of `}
{showCount != null && `${inCommonLimit} of `}
{inCommonTotal}{' '}
drop{inCommonTotal === 1 ? '' : 's'}{' '}
in common
</h4>
)}
<div className={clsx('in-common-events', showAll && 'show-all')}>
{inCommonEventsAddresses.map(
([eventId, addresses]) => (
<div
key={eventId}
className={clsx('in-common-event', {
selected: activeEventIds.indexOf(eventId) !== -1,
perfect:
showCount != null &&
showCount > 0 &&
showCount === addresses.length,
})}
title={events[eventId].name}
>
<button
className="event-button"
onClick={() => toggleActiveEventId(eventId)}
>
{
showCount != null &&
showCount > 0 &&
showCount === addresses.length
? (
<div className="event-image">
<TokenImage event={events[eventId]} size={64} />
</div>
)
: (
<EventCount
event={events[eventId]}
count={addresses.length}
size={64}
/>
)
}
</button>
<Link
to={`/event/${eventId}`}
className="event-id"
>
#{eventId}
</Link>
</div>
)
)}
<EventsPowers
showAll={showAll}
perfectPower={showCount}
selectedEventIds={activeEventIds}
onSelect={toggleActiveEventId}
events={events}
powers={powers}
>
{hasMore && (
<div className="show-more">
<ButtonLink
Expand All @@ -307,7 +288,7 @@ function InCommon({
</ButtonLink>
</div>
)}
</div>
</EventsPowers>
{inCommonTotal > 0 && (
<ButtonGroup right={true}>
{createButtons != null &&
Expand Down
8 changes: 2 additions & 6 deletions src/styles/event-count.css → src/styles/event-power.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
.event-count {
.event-power {
position: relative;
display: inline-block;
margin: 4px;
width: 64px;
height: 64px;
}

.event-count .count {
.event-power .power {
position: absolute;
top: 32px;
right: 0;
Expand Down
39 changes: 39 additions & 0 deletions src/styles/events-powers.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.events-powers .event-power-card {
display: inline-block;
border: .1rem solid transparent;
border-radius: 12px;
margin: .2rem;
overflow-wrap: break-word;
width: 72px;
}

.events-powers.show-all .event-power-card.perfect {
background-color: #eee;
border-color: #cdcdcd;
}

.events-powers .event-power-card.selected {
background-color: #7d73e2 !important;
border-color: #473e6b !important;
}

.events-powers .event-power-card .event-select-button {
background: transparent;
border-width: 0;
cursor: pointer;
display: inline-block;
margin: 4px;
outline: none;
}

.events-powers .event-power-card .event-id {
text-align: center;
display: block;
cursor: pointer;
font-size: 80%;
margin: 1px;
}

.events-powers .event-power-card.selected .event-id {
color: white;
}
Loading

0 comments on commit 1451daa

Please sign in to comment.