Skip to content

Commit

Permalink
Merge pull request #408 from poap-xyz/release/v1.17.1
Browse files Browse the repository at this point in the history
Release v1.17.1
  • Loading branch information
jm42 authored Nov 25, 2024
2 parents 27a9752 + 8d34546 commit a03ff6b
Show file tree
Hide file tree
Showing 11 changed files with 390 additions and 53 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.17.0",
"version": "1.17.1",
"author": {
"name": "POAP",
"url": "https://poap.xyz"
Expand Down
4 changes: 3 additions & 1 deletion src/components/Loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function Loading({
rate,
count,
total,
totalFinal = true,
small = false,
title,
}: {
Expand All @@ -18,6 +19,7 @@ function Loading({
rate?: number
count?: number
total?: number
totalFinal?: boolean
small?: boolean
title?: ReactNode
}) {
Expand Down Expand Up @@ -47,7 +49,7 @@ function Loading({
<>
<div className="count">{count}</div>
{typeof total === 'number' && (
<div className="total">{total}</div>
<div className={clsx('total', { final: totalFinal })}>{total}</div>
)}
</>
)}
Expand Down
8 changes: 7 additions & 1 deletion src/components/Progress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import 'styles/progress.css'
function Progress({
value,
max,
maxFinal = true,
showValue = false,
showPercent = false,
eta,
rate,
}: {
value?: number
max?: number
maxFinal?: boolean
showValue?: boolean
showPercent?: boolean
eta?: number
Expand All @@ -30,7 +32,11 @@ function Progress({
value={typeof value === 'number' ? value : undefined}
max={typeof max === 'number' ? max : undefined}
/>
{showValue && <span className="progress-values">{value ?? 0}/{max}</span>}
{showValue && (
<span className="progress-values">
{value ?? 0}/<span className={clsx('max', { final: maxFinal })}>{max}</span>
</span>
)}
{showPercent && <span className="progress-percent">
{hasDetails && (
<button
Expand Down
69 changes: 61 additions & 8 deletions src/hooks/useEventInCommon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ function useEventInCommon(
): {
completedEventInCommon: boolean
loadingEventInCommon: boolean
loadedInCommon: CountProgress | null
loadedInCommonState: 'eventIds-a' | 'eventIds-z' | 'owners-a' | 'owners-z' | 'events-a' | 'events-z' | null
loadedInCommon: CountProgress & { totalFinal: boolean } | null
loadedInCommonEvents: CountProgress | null
loadedInCommonDownload: DownloadProgress | null
loadedOwners: number
ownersErrors: Array<{ address: string; error: Error }>
Expand All @@ -29,7 +31,9 @@ function useEventInCommon(
} {
const [completed, setCompleted] = useState<boolean>(false)
const [loading, setLoading] = useState<boolean>(false)
const [loadedInCommon, setLoadedInCommon] = useState<CountProgress | null>(null)
const [loadedInCommonState, setLoadedInCommonState] = useState<'eventIds-a' | 'eventIds-z' | 'owners-a' | 'owners-z' | 'events-a' | 'events-z' | null>(null)
const [loadedInCommon, setLoadedInCommon] = useState<CountProgress & { totalFinal: boolean } | null>(null)
const [loadedInCommonEvents, setLoadedInCommonEvents] = useState<CountProgress | null>(null)
const [loadedProgress, setLoadedProgress] = useState<DownloadProgress | null>(null)
const [loadedOwners, setLoadedOwners] = useState<number>(0)
const [errors, setErrors] = useState<Array<{ address: string; error: Error }>>([])
Expand Down Expand Up @@ -135,6 +139,7 @@ function useEventInCommon(

const fetchEventInCommon = useCallback(
() => {
const controller = new AbortController()
const controllers: Record<string, AbortController> = owners.reduce(
(ctrls, owner) => ({ ...ctrls, [owner]: new AbortController() }),
{}
Expand All @@ -149,21 +154,64 @@ function useEventInCommon(
setLoadedOwners(0)
setLoadedInCommon(null)
setLoadedProgress(null)
setLoadedInCommonState(null)
;(
stream
? getInCommonEventsWithEvents(
eventId,
/*refresh*/force,
/*onProgress*/(received, total) => {
setLoadedInCommon({
count: received,
total,
})
/*abortSignal*/controller.signal,
/*onProgress*/(
receivedOwners,
receivedEventIds,
totalInCommon,
receivedEvents,
totalEvents
) => {
if (receivedEventIds) {
setLoadedInCommonState(
(prevState) => prevState == null ? 'eventIds-a' : prevState
)
setLoadedInCommon({
count: receivedOwners ?? 0,
total: receivedEventIds,
totalFinal: receivedEventIds === totalInCommon,
})
if (receivedEventIds === totalInCommon) {
setLoadedInCommonState(
(prevState) => prevState === 'eventIds-a' ? 'eventIds-z' : prevState
)
}
}
if (receivedOwners) {
setLoadedInCommonState(
(prevState) => prevState === 'eventIds-z' ? 'owners-a' : prevState
)
if (receivedOwners === receivedEventIds) {
setLoadedInCommonState(
(prevState) => prevState === 'owners-a' ? 'owners-z' : prevState
)
}
}
if (totalEvents) {
setLoadedInCommonState(
(prevState) => prevState === 'owners-z' ? 'events-a' : prevState
)
setLoadedInCommonEvents({
count: receivedEvents ?? 0,
total: totalEvents,
})
if (receivedEvents === totalEvents) {
setLoadedInCommonState(
(prevState) => prevState === 'events-a' ? 'events-z' : prevState
)
}
}
},
)
: getInCommonEventsWithProgress(
eventId,
/*abortSignal*/undefined,
/*abortSignal*/controller.signal,
/*onProgress*/({ progress, estimated, rate }) => {
if (progress != null) {
setLoadedProgress({
Expand All @@ -179,6 +227,7 @@ function useEventInCommon(
)
).then(
(result) => {
setLoadedInCommonState(null)
setLoadedInCommon(null)
setLoadedProgress(null)
if (!result) {
Expand All @@ -203,13 +252,15 @@ function useEventInCommon(
})
}
return () => {
controller.abort()
for (const controller of Object.values(controllers)) {
controller.abort()
}
setCompleted(false)
setLoading(false)
setLoadedInCommon(null)
setLoadedProgress(null)
setLoadedInCommonState(null)
setLoadedOwners(0)
setErrors([])
setInCommon({})
Expand All @@ -232,7 +283,9 @@ function useEventInCommon(
return {
completedEventInCommon: completed,
loadingEventInCommon: loading,
loadedInCommonState,
loadedInCommon,
loadedInCommonEvents,
loadedInCommonDownload: loadedProgress,
loadedOwners,
ownersErrors: errors,
Expand Down
Loading

0 comments on commit a03ff6b

Please sign in to comment.