Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions src/actions/candidate-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
genders,
} from "@/db/schema";
import { Candidate, Candidates, Status } from "@/types/candidate";
import { Ratings } from "@/types/ratings";
import { Ratings, RatingValue } from "@/types/ratings";
import { safeParseUrl } from "@/lib/url-utils";

export async function getVotedCandidates(
Expand Down Expand Up @@ -100,7 +100,7 @@ export async function getVotedCandidates(
.filter((vote) => vote.candidateId === candidate.id)
.reduce<Ratings>((r, vote) => {
r[String(vote.statementId)] = {
value: Math.max(0, Math.min(vote.value, 100)) / 100,
value: convertRatingValue(vote.value),
isFavorite: false,
explanation: vote.explanation,
};
Expand Down Expand Up @@ -134,3 +134,8 @@ function convertGender(genderId: number): Candidate["gender"] {
return "prefer-not-to-say";
}
}

function convertRatingValue(value: number): RatingValue {
if (value < 0) return "skipped";
return Math.max(0, Math.min(value, 100)) / 100;
}
9 changes: 7 additions & 2 deletions src/actions/party-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { eq, and } from "drizzle-orm";
import { db } from "@/db/drizzle";
import { parties, partyVotes } from "@/db/schema";
import { Parties, Status } from "@/types/party";
import { Ratings } from "@/types/ratings";
import { Ratings, RatingValue } from "@/types/ratings";
import { safeParseUrl } from "@/lib/url-utils";

export async function getVotedParties(instanceId: number): Promise<Parties> {
Expand Down Expand Up @@ -56,7 +56,7 @@ export async function getVotedParties(instanceId: number): Promise<Parties> {
.filter((vote) => vote.partyId === party.id)
.reduce<Ratings>((r, vote) => {
r[String(vote.statementId)] = {
value: Math.max(0, Math.min(vote.value, 100)) / 100,
value: convertRatingValue(vote.value),
isFavorite: false,
explanation: vote.explanation,
};
Expand All @@ -76,3 +76,8 @@ function getStatusFromNumber(statusNum: number): Status {

return statusMap[statusNum] || "created";
}

function convertRatingValue(value: number): RatingValue {
if (value < 0) return "skipped";
return Math.max(0, Math.min(value, 100)) / 100;
}
6 changes: 1 addition & 5 deletions src/app/[locale]/faq/faq-search-launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ export default function FAQSearchLauncher({
<div className="shrink-0">
{configId ? (
<Button asChild size="lg" className="w-full md:w-auto">
<Link
href="/faq/chat"
target="_blank"
rel="noopener noreferrer"
>
<Link href="/faq/chat" target="_blank" rel="noopener noreferrer">
{openInNewTab}
<ArrowUpRight aria-hidden="true" />
</Link>
Expand Down
4 changes: 3 additions & 1 deletion src/app/[locale]/faq/faq-search-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ export default function FAQSearchWidget({
const authToken = data.authToken ?? data.token ?? data.access_token;

if (!authToken) {
throw new Error("Search widget token response did not include token.");
throw new Error(
"Search widget token response did not include token.",
);
}

if (!cancelled) {
Expand Down