Skip to content
Open
Show file tree
Hide file tree
Changes from 12 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
32 changes: 28 additions & 4 deletions src/components/ui/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,47 @@ 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}>
<Link
className={button}
to={to}
onClick={onClick}
aria-disabled={disabled}
>
{children}
</Link>
)

if (href)
return (
<a className={button} href={href} target={target} onClick={onClick}>
<a
className={button}
href={href}
target={target}
onClick={onClick}
aria-disabled={disabled}
>
{children}
</a>
)
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: 2 additions & 1 deletion src/components/ui/titleChooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const TitleChooser = ({
choice = null,
setChoice = () => {},
label = '',
hintLabel = 'Välj ett objekt',
action = null,
actionLabel = '',
noChoicesLabel = '',
Comment on lines 15 to 21

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 44d76f4. Added hintLabel: PropTypes.string to TitleChooser.propTypes.

Expand Down Expand Up @@ -91,7 +92,7 @@ const TitleChooser = ({
</optgroup>
))}
</select>
{choice === null && <div className={hint}>Välj ett objekt</div>}
{choice === null && <div className={hint}>{hintLabel}</div>}
</div>
) : (
<span>{noChoicesLabel}</span>
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
22 changes: 13 additions & 9 deletions src/components/vote/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import TitleChooser from '../ui/titleChooser'
import SpeakerPanel from './speakerPanel'
import MeetingInfoPanel from './meetingInfoPanel'
import VotePanel from './votePanel'
import {
currentMeetingContainer,
votePanelContainer,
othersContainer,
} from '../../scss/votePage.module.scss'

export default function VotePage({ pageContext: { title } }) {
const [currentMeeting, setCurrentMeeting] = useState(null)
Expand All @@ -27,24 +32,23 @@ export default function VotePage({ pageContext: { title } }) {
setChoice={setCurrentMeeting}
choices={meetings}
label="name"
hintLabel="Välj ett möte"
noChoicesLabel="Det finns inga möten just nu."
/>
</GridItem>
{currentMeeting && (
<>
<GridItem>
<div className={currentMeetingContainer}>
<div className={votePanelContainer}>
<VotePanel meeting={currentMeeting} />
</div>
<div className={othersContainer}>
<MeetingInfoPanel
currentMeeting={currentMeeting}
setCurrentMeeting={setCurrentMeeting}
/>
</GridItem>
<GridItem>
<SpeakerPanel meeting={currentMeeting} />
</GridItem>
<GridItem>
<VotePanel meeting={currentMeeting} />
</GridItem>
</>
</div>
</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
65 changes: 42 additions & 23 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 React, { useState } from 'react'
import { post } from '../request'
import { Button } from '../ui/buttons'
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,52 @@ 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 ?? 'Ett fel uppstod vid röstningen.',
})
})
}
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: <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)}
className={voteInput}
/>
{` ${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
14 changes: 10 additions & 4 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/votePanel.module.scss'

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

return (
<div>
<h2>Rösta</h2>
{errors && <div className={formError}>{errors.voteError}</div>}
<h2 className={votePanelHeader}>Rösta</h2>
{errors.voteError && <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
19 changes: 11 additions & 8 deletions src/components/votingAdmin/addVote.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ const AddVote = ({ currentMeeting, create, updateData, update }) => {
)
const [alternatives, setAlternatives] = useState(
updateData
? updateData.alternatives.map(alt => createAlternative(alt))
: [createAlternative({text: 'Vakant'}), createAlternative({text: 'Blankt'})]
? updateData.alternatives.map((alt) => createAlternative(alt))
: [
createAlternative({ text: 'Vakant' }),
createAlternative({ text: 'Blankt' }),
]
)
const [currentQuestion, setCurrentQuestion] = useState(
updateData ? updateData.open : true
Expand All @@ -27,7 +30,7 @@ const AddVote = ({ currentMeeting, create, updateData, update }) => {
Fråga
<input
value={question}
onChange={e => {
onChange={(e) => {
setQuestion(e.target.value)
}}
/>
Expand All @@ -38,9 +41,9 @@ const AddVote = ({ currentMeeting, create, updateData, update }) => {
<li key={alt.key}>
<input
value={alt.text}
onChange={e => {
onChange={(e) => {
const newVal = e.target.value
setAlternatives(prev => [
setAlternatives((prev) => [
...prev.slice(0, i),
{ ...prev[i], text: newVal },
...prev.slice(i + 1),
Expand All @@ -50,7 +53,7 @@ const AddVote = ({ currentMeeting, create, updateData, update }) => {
<button
type="button"
onClick={() => {
setAlternatives(prev => [
setAlternatives((prev) => [
...prev.slice(0, i),
...prev.slice(i + 1),
])
Expand All @@ -64,7 +67,7 @@ const AddVote = ({ currentMeeting, create, updateData, update }) => {
<button
type="button"
onClick={() => {
setAlternatives(prev => [...prev, createAlternative()])
setAlternatives((prev) => [...prev, createAlternative()])
}}
>
Lägg till alternativ
Expand All @@ -74,7 +77,7 @@ const AddVote = ({ currentMeeting, create, updateData, update }) => {
<input
type="checkbox"
checked={currentQuestion}
onChange={() => setCurrentQuestion(prev => !prev)}
onChange={() => setCurrentQuestion((prev) => !prev)}
/>
Nuvarande frågan
</label>
Expand Down
Loading