Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 15 additions & 2 deletions src/components/ui/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ const IconButton = ({ onClick, iconComponent: Icon, text, disabled }) => {
)
}

const Button = ({ onClick, to, href, target, children, type = 'button' }) => {
const Button = ({
onClick,
to,
href,
target,
children,
disabled,
type = 'button',
}) => {
if (to)
return (
<Link className={button} to={to} onClick={onClick}>
Expand All @@ -34,7 +42,12 @@ const Button = ({ onClick, to, href, target, children, type = 'button' }) => {
)
Comment thread
OttoRoming marked this conversation as resolved.
Comment thread
OttoRoming marked this conversation as resolved.
Comment on lines 30 to 69

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in f77c4de. When disabled is true, the <Link>/<a> variants now:

  • Remove the to/href attribute (prevents keyboard Enter, middle-click, and right-click → open-in-new-tab navigation)
  • Replace the onClick with a handler that calls preventDefault() + stopPropagation() (blocks any remaining click navigation)
  • Set tabIndex={-1} (removes the element from the tab order)
  • aria-disabled={true} was already in place from the previous fix


return (
<button className={button} type={type} onClick={onClick}>
<button
className={button}
type={type}
onClick={onClick}
disabled={disabled}
>
{children}
</button>
)
Expand Down
3 changes: 3 additions & 0 deletions src/components/vote/meetingInfoPanel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { Button } from '../ui/buttons'
import { post, del } from '../request'
import { FiLogOut, FiLogIn } from 'react-icons/fi'

export default function MeetingInfoPanel({
currentMeeting,
Expand Down Expand Up @@ -34,6 +35,7 @@ export default function MeetingInfoPanel({
}
}}
>
<FiLogOut />
Lämna röstlängden
</Button>
) : (
Expand All @@ -49,6 +51,7 @@ export default function MeetingInfoPanel({
}
}}
>
<FiLogIn />
Gå med i röstlängden
</Button>
)}
Expand Down
14 changes: 9 additions & 5 deletions src/components/vote/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import TitleChooser from '../ui/titleChooser'
import SpeakerPanel from './speakerPanel'
import MeetingInfoPanel from './meetingInfoPanel'
import VotePanel from './votePanel'
import {
currentMeetingContainer,
votePanelContainer,
} from '../../scss/votePage.module.scss'

export default function VotePage({ pageContext: { title } }) {
const [currentMeeting, setCurrentMeeting] = useState(null)
Expand All @@ -31,7 +35,10 @@ export default function VotePage({ pageContext: { title } }) {
/>
</GridItem>
{currentMeeting && (
<>
<div className={currentMeetingContainer}>
<div className={votePanelContainer}>
<VotePanel meeting={currentMeeting} />
</div>
<GridItem>
<MeetingInfoPanel
currentMeeting={currentMeeting}
Expand All @@ -41,10 +48,7 @@ export default function VotePage({ pageContext: { title } }) {
<GridItem>
<SpeakerPanel meeting={currentMeeting} />
</GridItem>
<GridItem>
<VotePanel meeting={currentMeeting} />
</GridItem>
</>
</div>
)}
</GridContainer>
</BigPixels>
Expand Down
8 changes: 6 additions & 2 deletions src/components/vote/speakerPanel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useState, useEffect, useContext } from 'react'

import { MdOutlineFrontHand } from 'react-icons/md'
import { RiMegaphoneLine } from 'react-icons/ri'
import { FiTrash2 } from 'react-icons/fi'
import { List, ListButton, ListItem } from '../ui/list'
import { Button, ButtonGroup } from '../ui/buttons'
import { UserContext } from '../layout/layout'
import { speakerPanelList } from '../../scss/vote.module.scss'
import { speakerPanelList } from '../../scss/voteSpeakerPanel.module.scss'

import socket, { joinRoom, leaveRoom } from '../request/socket'
import backendService from '../request/backendService'
Expand Down Expand Up @@ -80,6 +82,7 @@ const SpeakerPanel = ({ meeting }) => {
})
}}
>
<MdOutlineFrontHand />
Comment thread
OttoRoming marked this conversation as resolved.
Jag vill tala!
</Button>
<Button
Expand All @@ -90,6 +93,7 @@ const SpeakerPanel = ({ meeting }) => {
})
}}
>
<RiMegaphoneLine />
Comment thread
OttoRoming marked this conversation as resolved.
Replik!
</Button>
</ButtonGroup>
Expand All @@ -101,7 +105,7 @@ const SpeakerPanel = ({ meeting }) => {
speakers.map((s) => (
<ListItem
title={s.user.pretty_name}
subtitle={s.prioritized ? 'Replik' : null}
subtitle={s.prioritized ? 'Replik' : 'Tala'}
key={s.id}
buttons={[
<ListButton
Expand Down
61 changes: 39 additions & 22 deletions src/components/vote/voteForm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import React, { Component, useState } from 'react'
import { post } from '../request'
import { IconButton, Button, ButtonGroup } from '../ui/buttons'
Comment thread
OttoRoming marked this conversation as resolved.
Outdated
Comment thread
OttoRoming marked this conversation as resolved.
Outdated
import { MdOutlineHowToVote } from 'react-icons/md'
import {
questionHeader,
votesContainer,
voteInput,
voteLabel,
placeVoteContainer,
} from '../../scss/voteForm.module.scss'

const VoteForm = ({ vote, setErrors }) => {
const [checkedId, setCheckedId] = useState(-1)
Expand All @@ -17,42 +26,50 @@ const VoteForm = ({ vote, setErrors }) => {
}

await post('/voting/made_votes/', voteData)
.then(() => setSuccessfullyVoted(true))
.catch(err => {
setSentVote(false)
setErrors({ voteError: err.response.data.error })
})
.then(() => setSuccessfullyVoted(true))
.catch((err) => {
setSentVote(false)
setErrors({ voteError: err.response.data.error })
Comment thread
OttoRoming marked this conversation as resolved.
Outdated
})
}
const votingDisabled = checkedId === -1
const buttonText = votingDisabled ? 'Välj ett alternativ' : 'Rösta'
const placeVoteButtonText = votingDisabled ? 'Välj ett alternativ' : 'Rösta'
const alreadyVotedText = successfullyVoted
? 'Tack för din röst!'
: 'Du har röstat i omröstningen.'

return (
<div>
<strong>{vote.question}</strong>
<h3 className={questionHeader}>
Fråga:&nbsp;
<strong>{vote.question}</strong>
</h3>
{vote.has_voted || successfullyVoted ? (
<p>{alreadyVotedText}</p>
) : (
<>
<ul>
<div className={votesContainer}>
{vote.alternatives.map(({ text, id }) => (
<li key={id}>
<label>
<input
type="radio"
checked={checkedId === id}
onChange={() => setCheckedId(id)}
/>
{` ${text}`}
</label>
</li>
<label key={id} className={voteLabel}>
<input
type="radio"
checked={checkedId === id}
onChange={() => setCheckedId(id)}
class={voteInput}
Comment thread
OttoRoming marked this conversation as resolved.
Outdated
Comment thread
OttoRoming marked this conversation as resolved.
Outdated
/>
{` ${text}`}
</label>
Comment on lines +56 to +64
))}
</ul>
<button type="button" disabled={votingDisabled || successfullyVoted || sentVote} onClick={placeVote}>
{buttonText}
</button>
</div>
<div className={placeVoteContainer}>
<Button
disabled={votingDisabled || successfullyVoted || sentVote}
onClick={placeVote}
>
<MdOutlineHowToVote />
{placeVoteButtonText}
</Button>
</div>
</>
)}
</div>
Expand Down
12 changes: 9 additions & 3 deletions src/components/vote/votePanel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import React, { useEffect, useState } from 'react'
import VoteForm from './voteForm'
import { formError } from '../../scss/vote.module.scss'
import backendService from '../request/backendService'
import socket, { joinRoom, leaveRoom } from '../request/socket'
import {
formError,
votePanelHeader,
noActiveVoting,
} from '../../scss/votePage.module.scss'
Comment thread
OttoRoming marked this conversation as resolved.
Outdated
Comment thread
OttoRoming marked this conversation as resolved.
Outdated

const VotePanel = ({ meeting }) => {
const [votes, setVotes] = useState([])
Expand Down Expand Up @@ -116,11 +120,13 @@ const VotePanel = ({ meeting }) => {

return (
<div>
<h2>Rösta</h2>
<h2 className={votePanelHeader}>Rösta</h2>
{errors && <div className={formError}>{errors.voteError}</div>}
{votes && (
Comment thread
OttoRoming marked this conversation as resolved.
<>
{votes.length === 0 && <p>Det finns ingen aktiv omröstning</p>}
{votes.length === 0 && (
<h3 className={noActiveVoting}>Det finns ingen aktiv omröstning</h3>
)}
{votes.map((vote) => (
<VoteForm key={vote.id} vote={vote} setErrors={setFormErrors} />
))}
Expand Down
29 changes: 19 additions & 10 deletions src/scss/ui.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
border: none;
background-color: $background-color-3;
color: $foreground-color-3;
cursor: pointer;
padding: $base-padding $base-padding * 2;
margin-bottom: $base-padding;

Expand All @@ -16,8 +15,22 @@
justify-content: center;
gap: calc($base-padding / 2);

&:hover {
background-color: $dsek-blue;
> svg {
height: calc(1.5 * $base-padding);
width: calc(1.5 * $base-padding);
}

&:enabled {
cursor: pointer;

&:hover {
background-color: $dsek-blue;
}
}

&:disabled {
cursor: not-allowed;
opacity: 0.6;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in 86d3ae7. Replaced &:enabled/&:disabled pseudo-classes (which only apply to form controls) with [disabled]/[aria-disabled='true'] attribute selectors, and moved cursor: pointer outside the :enabled block so hover and cursor styling now works correctly for both <button> and <a>/Gatsby <Link> variants.

Comment thread
OttoRoming marked this conversation as resolved.

&:focus {
Expand Down Expand Up @@ -89,7 +102,6 @@
.gridItem {
background-color: rgba($background-color-2, 0.95);
padding: $base-padding;
// z-index: 10;
backdrop-filter: blur(5px);
}

Expand Down Expand Up @@ -119,7 +131,7 @@

h3 {
margin: 0;
font-size: 1rem;
font-size: 1.2rem;
}
p {
font-size: 0.9rem;
Expand Down Expand Up @@ -293,11 +305,8 @@
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(
0deg,
rgba(0, 0, 0, 0.6) 0%,
rgba(0, 0, 0, 0) 100%
),
background:
linear-gradient(0deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 100%),
linear-gradient(0deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0) 30%);
}
}
53 changes: 53 additions & 0 deletions src/scss/voteForm.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
@import 'vars';

.votesContainer {
display: grid;
grid-template-columns: 1fr 1fr;
gap: $base-padding;

&:has(> :nth-child(3)) {
grid-template-columns: 1fr 1fr 1fr;
}
}

.voteInput {
/* hide the radio button */
/* https://stackoverflow.com/questions/18078871/hide-check-radio-button-with-css */
position: fixed;
opacity: 0;
pointer-events: none;
}
Comment thread
OttoRoming marked this conversation as resolved.

.voteLabel {
text-align: center;
font-size: 1.2em;
padding: $base-padding calc($base-padding / 2);
transition: all 100ms;
background-color: $background-color-4;
cursor: pointer;

word-break: normal;
overflow-wrap: anywhere;
hyphens: auto;

&:hover {
background-color: $dsek-blue;
}

&:has(.voteInput:checked) {
background-color: $dsek-green !important;
color: $background-color-2;
font-weight: 800;
}
Comment on lines +24 to +52
}

.placeVoteContainer {
display: flex;
justify-content: center;
align-items: center;
padding-top: $base-padding;
}

.questionHeader {
text-align: center;
}
19 changes: 19 additions & 0 deletions src/scss/votePage.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@import 'vars';

.formError {
color: $red;
}

.currentMeetingContainer {
grid-column: 1 / -1;
background-color: transparent;
display: grid;
gap: $base-padding;
grid-template-columns: 1fr 1fr;
}

.votePanelContainer {
background-color: $background-color-2;
grid-column: 1 / -1;
padding: $base-padding;
}
8 changes: 8 additions & 0 deletions src/scss/votePanel.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.votePanelHeader {
text-align: center;
}

.noActiveVoting {
text-align: center;
font-style: italic;
}
Loading