Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: another pixel placement control flow #206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ function App() {
const [isEraserMode, setIsEraserMode] = React.useState(false);
const [isExtraDeleteMode, setIsExtraDeleteMode] = React.useState(false);

const [placementTimer, setPlacementTimer] = useState('XX:XX');

useEffect(() => {
const getLastPlacedPixel = `get-last-placed-time?address=${queryAddress}`;
async function fetchGetLastPlacedPixel() {
Expand Down Expand Up @@ -303,6 +305,11 @@ function App() {
setSelectedPositionX(x);
setSelectedPositionY(y);
setPixelSelectedMode(true);

if (placementTimer == 'Place Pixel') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking against a string here would be bad practice because the string can change. For instance, when the user has multiple pixels, the button says 'Place Pixels' instead.

I'd recommend using availablePixels > 0 for this check.

setSelectorMode(true);
setIsEraserMode(false);
}
// TODO: move http fetch for pixel data here?
};

Expand Down Expand Up @@ -536,6 +543,8 @@ function App() {
basePixelTimer={basePixelTimer}
queryAddress={queryAddress}
setActiveTab={setActiveTab}
placementTimer={placementTimer}
setPlacementTimer={setPlacementTimer}
/>
<TabsFooter
tabs={tabs}
Expand Down
16 changes: 7 additions & 9 deletions frontend/src/footer/PixelSelector.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import React, { useEffect, useState } from 'react';
import React, { useEffect } from 'react';
import './PixelSelector.css';
import '../utils/Styles.css';

const PixelSelector = (props) => {
// Track when a placement is available

const [placementTimer, setPlacementTimer] = useState('XX:XX');

useEffect(() => {
if (props.queryAddress === '0') {
setPlacementTimer('Connect Wallet');
props.setPlacementTimer('Connect Wallet');
return;
}
if (props.availablePixels > 0) {
let amountAvailable = props.availablePixels - props.availablePixelsUsed;
if (amountAvailable > 1) {
setPlacementTimer('Place Pixels');
props.setPlacementTimer('Place Pixels');
return;
} else if (amountAvailable === 1) {
setPlacementTimer('Place Pixel');
props.setPlacementTimer('Place Pixel');
return;
} else {
setPlacementTimer('Out of Pixels');
props.setPlacementTimer('Out of Pixels');
return;
}
} else {
setPlacementTimer(props.basePixelTimer);
props.setPlacementTimer(props.basePixelTimer);
}
}, [
props.availablePixels,
Expand Down Expand Up @@ -93,7 +91,7 @@ const PixelSelector = (props) => {
}
onClick={toSelectorMode}
>
<p className='PixelSelector__text'>{placementTimer}</p>
<p className='PixelSelector__text'>{props.placementTimer}</p>
{props.availablePixels > (props.basePixelUp ? 1 : 0) && (
<div className='PixelSelector__extras'>
<div
Expand Down