if fetching ? classname + woble

This commit is contained in:
djmil 2023-10-31 18:45:09 +01:00
parent 3eafcf302f
commit c007aec06e
4 changed files with 21 additions and 8 deletions

View File

@ -15,19 +15,31 @@ export default function Create() {
const request = ctx.get_GameProposalRequest() const request = ctx.get_GameProposalRequest()
ctx.setFetching(true)
postData("/api/gameproposal", request) postData("/api/gameproposal", request)
.then((responce) => { .then((responce) => {
console.log("responce", responce) // JSON data parsed by `data.json()` call console.log("responce", responce) // JSON data parsed by `data.json()` call
ctx.clear_Message2Opponent() ctx.clear_Message2Opponent()
ctx.setFetching(false)
}); });
} }
console.log("ctx", ctx)
return ( return (
<button <button
className={'game-action create' + (ctx.isEnabled ? ' enabled' : ' disabled')} className={'game-action create'
+ (ctx.isEnabled ? ' enabled' : ' disabled')
+ (ctx.isFetching === true ? ' woble' : '')
}
onClick={onClick} onClick={onClick}
> >
Create <span>C</span>
<span>r</span>
<span>e</span>
<span>a</span>
<span>t</span>
<span>e</span>
</button> </button>
) )
} }
@ -64,8 +76,11 @@ function Definitions() {
hasCurrentUser, hasCurrentUser,
isEnabled, isEnabled,
isFetching: ctx.newGame.isFetching,
setFetching: (status) => { console.log("setFetching: ", status); dispatchCtx({ update: "newGame", isFetching: status }) },
get_GameProposalRequest, get_GameProposalRequest,
clear_Message2Opponent: () => { dispatchCtx({ update: "newGame", message: '' }) } clear_Message2Opponent: () => { dispatchCtx({ update: "newGame", message: '' }) },
} }
} }

View File

@ -8,14 +8,14 @@ import Proposal from './GameSelector/GameProposal';
export default function GameSelector() { export default function GameSelector() {
const [data] = React.useContext(AppData) const [data] = React.useContext(AppData)
const [ctx, dispatchCtx] = React.useContext(AppContext) const [/*ctx*/, dispatchCtx] = React.useContext(AppContext)
const { pathname } = useLocation(); const { pathname } = useLocation();
const isProposalPath = matchPath("/game/proposal/*", pathname); const isProposalPath = matchPath("/game/proposal/*", pathname);
const isActivelPath = matchPath("/game/active/*", pathname); const isActivelPath = matchPath("/game/active/*", pathname);
const isArchivePath = matchPath("/game/archive/*", pathname); const isArchivePath = matchPath("/game/archive/*", pathname);
console.log("GameSelector appCtx", ctx) // console.log("GameSelector appCtx", ctx)
const onClick_proposal = (selectedGame) => { const onClick_proposal = (selectedGame) => {
dispatchCtx({ component: "game-selector", selectedGameProposal: selectedGame }) dispatchCtx({ component: "game-selector", selectedGameProposal: selectedGame })

View File

@ -2,9 +2,6 @@
.woble { .woble {
display: flex; display: flex;
cursor: pointer;
justify-content: center;
align-items: center;
} }
/* .wave > span { /* .wave > span {

View File

@ -25,6 +25,7 @@ export const initialState = {
whitePlayer: '', whitePlayer: '',
blackPlayer: '', blackPlayer: '',
message: '', message: '',
isFetching: false,
}, },
} }