Skip to content

Commit

Permalink
Merge pull request #15600 from bastianpedersen/if-challenge-has-rules…
Browse files Browse the repository at this point in the history
…-dont-accept-immediately

Display "view" button if challenge has rules
  • Loading branch information
ornicar committed Jun 27, 2024
2 parents 59fdaaf + 3a92966 commit f725c2a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
17 changes: 15 additions & 2 deletions ui/challenge/css/_challenge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

.buttons {
@extend %flex-between-nowrap;

align-items: stretch;
@media (hover: hover) {
display: none;
}
Expand All @@ -47,7 +47,17 @@
width: 33%;
}

a.view {
font-size: 1.5rem;
color: $c-primary;
&:hover {
background: $c-primary;
color: $c-over;
}
}

button {
border-radius: 0;
cursor: pointer;
color: $c-good;
width: 100%;
Expand Down Expand Up @@ -88,7 +98,8 @@
}
}

button::before {
button::before,
a.view::before {
line-height: 3rem;
}

Expand Down Expand Up @@ -126,9 +137,11 @@
display: block;
font-weight: bold;
margin-bottom: 0.1em;

.user-link {
margin-inline-start: -5px;
}

signal {
margin-inline-start: 5px;
}
Expand Down
1 change: 1 addition & 0 deletions ui/challenge/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface Challenge {
status: ChallengeStatus;
challenger?: ChallengeUser;
destUser?: ChallengeUser;
rules?: unknown[];
variant: Variant;
initialFen: FEN;
rated: boolean;
Expand Down
12 changes: 10 additions & 2 deletions ui/challenge/src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function challenge(ctrl: ChallengeCtrl, dir: ChallengeDirection) {
}

function inButtons(ctrl: ChallengeCtrl, c: Challenge): VNode[] {
return [
const viewInsteadOfAccept = (c.rules?.length ?? 0) > 0;
const acceptElement = () =>
h('form', { attrs: { method: 'post', action: `/challenge/${c.id}/accept` } }, [
h('button.button.accept', {
attrs: {
Expand All @@ -85,7 +86,14 @@ function inButtons(ctrl: ChallengeCtrl, c: Challenge): VNode[] {
},
hook: onClick(ctrl.onRedirect),
}),
]),
]);
const viewElement = () =>
h('a.view', {
attrs: { 'data-icon': licon.Eye, href: '/' + c.id, title: ctrl.trans('viewInFullSize') },
});

return [
viewInsteadOfAccept ? viewElement() : acceptElement(),
h('button.button.decline', {
attrs: { type: 'submit', 'data-icon': licon.X, title: ctrl.trans('decline') },
hook: onClick(() => ctrl.decline(c.id, 'generic')),
Expand Down

0 comments on commit f725c2a

Please sign in to comment.