-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bubble of a growing population (#627)
Closes #607 #### What else should be done - [x] Setting the correct animation for bubbles. - [x] If possible, add animations for `RealmsBar`. `RealmBarIcon` should move more smoothly when the population is changed. - [ ] After joining the realm, show a bubble instantly. - [ ] Improve intervals for realms. - [x] Adding bubble to the modal window. ### What The app should be more lively. This PR adds +1 bubble over a realm every time somebody joins. The bubble should be visible over the realm on the map but also in the modal window. The population is fetched from the contracts every minute. We shouldn't show 20 bubbles at the same time and then not show anything for 1 minute. We should spread out the number of bubbles we show. - So let's add a variable `displayedPopulation` to increment it and show the bubbles with the correct interval. - Intervals should be different for the realms to make the app more lively. - When we init game data, we should refresh the `displayedPopulation` and align it with the true number. ### Testing Let's use a patch file to increase the population and do tests. Use the following file: [increase-population.patch](https://github.com/tahowallet/dapp/files/13249010/increase-population.patch) The population is increased randomly every minute. ``` git apply increase-population.patch ``` - [ ] When a user joins the region, a bubble should show up immediately in the modal. - [ ] Bubbles should occur at different intervals between realms. - [ ] After refreshing the page, the population should show the correct number.
- Loading branch information
Showing
33 changed files
with
643 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { RealmData } from "shared/types" | ||
|
||
export const getPopulationOfRealms = (realms: RealmData[]) => | ||
realms.map((realm) => realm.population) | ||
|
||
export const getDisplayedPopulationOfRealms = (realms: RealmData[]) => | ||
realms.map((realm) => realm.displayedPopulation) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { animated, easings, useSpring } from "@react-spring/web" | ||
import React, { useEffect, useState } from "react" | ||
import { getRealmPopulationIcon } from "shared/constants" | ||
import { usePopulationBubble } from "shared/hooks" | ||
|
||
export const STYLE = { | ||
default: { opacity: 0, transform: "translateY(150px)" }, | ||
highlight: { opacity: 1, transform: "translateY(50px)" }, | ||
} | ||
|
||
export const BUBBLE_CONFIG = { | ||
precision: 0.1, | ||
duration: 2000, | ||
easing: easings.easeOutCubic, | ||
} | ||
|
||
export default function Bubble({ realmId }: { realmId: string }) { | ||
const { showBubble, setShowBubble } = usePopulationBubble(realmId) | ||
|
||
const [iconSrc, setIconSrc] = useState<string | null>(null) | ||
|
||
useEffect(() => { | ||
const icon = getRealmPopulationIcon(realmId) | ||
setIconSrc(icon) | ||
}, [realmId]) | ||
|
||
const [bubbleProps] = useSpring( | ||
() => ({ | ||
from: STYLE.default, | ||
to: showBubble ? STYLE.highlight : STYLE.default, | ||
config: BUBBLE_CONFIG, | ||
onRest: () => setShowBubble(false), | ||
}), | ||
[showBubble] | ||
) | ||
|
||
if (!iconSrc) return null | ||
|
||
return ( | ||
<animated.div | ||
style={{ ...bubbleProps, left: "220px", position: "absolute", zIndex: 2 }} | ||
> | ||
<div> | ||
<img src={iconSrc} height={24} width={24} alt="Bubble" /> | ||
</div> | ||
</animated.div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.