Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
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: 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
15 changes: 10 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 @@ -27,11 +31,15 @@ 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 && (
<>
<div className={currentMeetingContainer}>
<div className={votePanelContainer}>
<VotePanel meeting={currentMeeting} />
</div>
<GridItem>
<MeetingInfoPanel
currentMeeting={currentMeeting}
Expand All @@ -41,10 +49,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
13 changes: 8 additions & 5 deletions src/components/votingAdmin/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ const VotingAdminPage = ({ pageContext: { title } }) => {
const [openCreateModal] = useModal(AddMeeting)
const closeModal = useCloseModal()

const create = async data => {
const create = async (data) => {
const { data: newMeeting } = await post('/voting/admin-meetings/', data)
mutate([...unorderedMeetings, newMeeting])
}
Comment on lines +22 to 25

const updatePatch = async data => {
const updatePatch = async (data) => {
const { data: updatedMeeting } = await patch(
`/voting/admin-meetings/${currentMeeting.id}/`,
data
)
mutate([
...unorderedMeetings.filter(meeting => meeting.id !== currentMeeting.id),
...unorderedMeetings.filter(
(meeting) => meeting.id !== currentMeeting.id
),
updatedMeeting,
])
}
Expand All @@ -40,7 +42,7 @@ const VotingAdminPage = ({ pageContext: { title } }) => {
// sync currentMeeting with updated meetings
useEffect(() => {
if (currentMeeting)
setCurrentMeeting(meetings.find(m => m.id === currentMeeting.id))
setCurrentMeeting(meetings.find((m) => m.id === currentMeeting.id))
}, [meetings])
Comment on lines 43 to 46

return (
Expand All @@ -53,9 +55,10 @@ const VotingAdminPage = ({ pageContext: { title } }) => {
setChoice={setCurrentMeeting}
choices={meetings}
label="name"
hintLabel="Välj ett möte"
action={() => {
openCreateModal('Nytt möte', {
create: async data => {
create: async (data) => {
await create(data)
closeModal()
},
Expand Down
20 changes: 10 additions & 10 deletions src/components/votingCounter/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,31 @@ const VotingAdminPage = ({ pageContext: { title } }) => {
const { data: unorderedMeetings, mutate } = useSWR('/voting/admin-meetings/')
const closeModal = useCloseModal()

const create = async data => {
const create = async (data) => {
const { data: newMeeting } = await post('/voting/admin-meetings/', data)
mutate([...unorderedMeetings, newMeeting])
}

const updatePatch = async data => {
const updatePatch = async (data) => {
const { data: updatedMeeting } = await patch(
`/voting/admin-meetings/${currentMeeting.id}/`,
data
)
mutate([
...unorderedMeetings.filter(meeting => meeting.id !== currentMeeting.id),
...unorderedMeetings.filter(
(meeting) => meeting.id !== currentMeeting.id
),
updatedMeeting,
])
}

const meetings = unorderedMeetings ? [...unorderedMeetings].reverse() : null

// sync currentMeeting with updated meetings
useEffect(
() => {
if (currentMeeting)
setCurrentMeeting(meetings.find(m => m.id === currentMeeting.id))
},
[meetings]
)
useEffect(() => {
if (currentMeeting)
setCurrentMeeting(meetings.find((m) => m.id === currentMeeting.id))
}, [meetings])

return (
<BigPixels>
Expand All @@ -54,6 +53,7 @@ const VotingAdminPage = ({ pageContext: { title } }) => {
setChoice={setCurrentMeeting}
choices={meetings}
label="name"
hintLabel="Välj ett möte"
noChoicesLabel="Det finns inga möten just nu."
/>
</GridItem>
Expand Down
Loading