Skip to content

Instantly share code, notes, and snippets.

@karno
Created October 16, 2019 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karno/8c51a3f6faf2e7acb9104cca16e674e8 to your computer and use it in GitHub Desktop.
Save karno/8c51a3f6faf2e7acb9104cca16e674e8 to your computer and use it in GitHub Desktop.
sushiro gacha test
import React, { useState, useEffect } from 'react';
import SushiInfo from './common/SushiInfo';
import './SushiSlot.css';
interface SushiSingleSlotProps {
sushies: SushiInfo[],
sushi: SushiInfo,
delay: number,
}
const SushiSingleSlot: React.FC<SushiSingleSlotProps> = props => {
return <p>{props.delay} {props.sushi.category} {props.sushi.name}</p>
}
interface SushiSlotProps {
sushies: SushiInfo[]
}
export const SushiSlot: React.FC<SushiSlotProps> = props => {
const DrawSingle = () => DrawN(1);
const DrawQuintuple = () => DrawN(5);
const DrawDecuple = () => DrawN(10);
const DrawN = (n: number) => {
if (props.sushies.length == 0) {
setSlots([]);
} else {
setSlots([...Array(n)].map(_ =>
props.sushies[Math.floor(Math.random() * props.sushies.length)]
));
}
};
const [slots, setSlots] = useState<SushiInfo[]>([]);
if (props.sushies.length == 0) {
return (<p>Loading...</p>);
} else {
return (
<div>
<div>
<p>
<button onClick={DrawSingle}>1回引く</button>
<button onClick={DrawQuintuple}>5回引く</button>
<button onClick={DrawDecuple}>10回引く</button>
</p>
{slots.map((m: SushiInfo, i: number) =>
<SushiSingleSlot sushies={props.sushies} sushi={m} delay={i} />)}
</div>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment