Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sample dashboard page #98

Merged
merged 6 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
47 changes: 24 additions & 23 deletions app/dashboard/components/Information-icon-text.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { useState } from "react";
import {
Tooltip,
TooltipTrigger,
TooltipContent,
TooltipProvider,
} from "@/components/ui/tooltip";
import { FaInfoCircle } from "react-icons/fa";
import Link from "next/link";

Expand All @@ -15,42 +21,37 @@ const TooltipWithIcon: React.FC<TooltipWithIconProps> = ({
linkHref,
description,
}) => {
const [isTooltipVisible, setTooltipVisible] = useState(false);

return (
<span
className="ml-2 relative"
onMouseEnter={() => setTooltipVisible(true)}
onMouseLeave={() => setTooltipVisible(true)} // Keep tooltip open
>
{/* Information Icon */}
<FaInfoCircle className="text-black cursor-pointer" size={18} />
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<span className="ml-2 relative">
{/* Information Icon */}
<FaInfoCircle className="text-black cursor-pointer" size={18} />
</span>
</TooltipTrigger>

{/* Tooltip Box */}
{isTooltipVisible && (
<div className="absolute bg-white text-black text-sm rounded-lg shadow-lg py-3 px-5 left-full ml-2 w-64">
<TooltipContent
side="right"
align="center"
className="bg-white text-black rounded-lg shadow-lg p-4 w-64"
>
<div className="font-bold mb-2">{title}</div>
<div className="font-normal">
{description}{" "}
<Link
href="/tutorial"
href={linkHref}
target="_blank"
rel="noopener noreferrer"
className="text-blue-500 hover:underline"
>
Tutorial
{linkText}
</Link>
.
</div>
<button
className="mt-4 text-gray-500 hover:text-gray-700"
onClick={() => setTooltipVisible(false)}
>
Hide
</button>
</div>
)}
</span>
</TooltipContent>
</Tooltip>
</TooltipProvider>
);
};

Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/components/avatar-assign-color.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//avatar-assign-color.tsx
import React, { useEffect, useMemo, useState } from "react";
import useMultiWinnerDataStore from "@/store/MultiWinnerData";
import { AvatarColor } from "@/utils/avatarColor";
import useMultiWinnerDataStore from "@/store/multi-winner-data";
import { AvatarColor } from "@/utils/avatar-color";

interface AvatarProps {
onComplete: () => void;
Expand Down
30 changes: 27 additions & 3 deletions app/dashboard/components/elimination-tree/candidate-list-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { Candidate } from "./constants";
import SearchDropdown from "./search-dropdown";
import { TooltipTrigger } from "@radix-ui/react-tooltip";
import { useState } from "react";

type CandidateListBarProps = {
selectedWinnerId: number;
Expand All @@ -20,16 +21,35 @@ function CandidateListBar({
useAvatar,
candidateList,
}: CandidateListBarProps) {
const [selectedCandidateId, setSelectedCandidateId] = useState<number | null>(
null,
);

Copy link
Collaborator

Choose a reason for hiding this comment

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

为什么不能用外部传入的selectedWinnerId呢?

Copy link
Collaborator

Choose a reason for hiding this comment

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

现在这种会有Bug,第一次展示tree的时候,当前展示的树并没有一圈蓝色

const handleCandidateSelect = (candidateId: number) => {
setSelectedCandidateId(candidateId);
handleSelectWinner(candidateId); // Call to display the tree or other action
};
return (
<div className="flex justify-center mb-5 gap-10">
<div className="flex">
{candidateList.map((candidate) => (
<div key={candidate.id} className="flex flex-col items-center w-12">
<TooltipProvider>
<Tooltip>
{/*<TooltipTrigger*/}
{/* onClick={() => handleSelectWinner(candidate.id)}*/}
{/* className="leading-9 w-10 h-10 rounded-full cursor-pointer text-center border-2 border-black text-xs overflow-hidden whitespace-nowrap text-ellipsis"*/}
{/*>*/}
{/* {candidate.name}*/}
{/*</TooltipTrigger>*/}

<TooltipTrigger
onClick={() => handleSelectWinner(candidate.id)}
className="leading-9 w-10 h-10 rounded-full cursor-pointer text-center border-2 border-black text-xs overflow-hidden whitespace-nowrap text-ellipsis"
onClick={() => handleCandidateSelect(candidate.id)}
className={`leading-9 w-10 h-10 rounded-full cursor-pointer text-center border-2 text-xs overflow-hidden whitespace-nowrap text-ellipsis ${
selectedCandidateId === candidate.id
? "border-blue-500" // Outer blue circle when selected
: "border-black"
}`}
>
{candidate.name}
</TooltipTrigger>
Expand All @@ -39,7 +59,11 @@ function CandidateListBar({
</div>
))}
</div>
<SearchDropdown candidateList={candidateList} />
{/*<SearchDropdown candidateList={candidateList} />*/}
<SearchDropdown
candidateList={candidateList}
onSelect={handleCandidateSelect}
/>
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/dashboard/components/elimination-tree/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Switch } from "@/components/ui/switch";
import useTreeSettingsStore from "@/store/useTreeSettingStore";
import useTreeSettingsStore from "@/store/use-tree-setting-store";
import { ChevronDown } from "lucide-react";

function Dropdown() {
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/components/elimination-tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import Tree from "../../../../components/tree";
import { useEffect, useMemo, useState } from "react";
import { Button } from "@/components/ui/button";
import { ArrowLeft, ArrowRight, Undo2 } from "lucide-react";
import useMultiWinnerDataStore from "@/store/MultiWinnerData";
import TooltipWithIcon from "@/app/dashboard/components/Information-icon-text";
import useMultiWinnerDataStore from "@/store/multi-winner-data";

function EliminationTree() {
const { multiWinner } = useMultiWinnerDataStore();
Expand Down Expand Up @@ -104,7 +104,7 @@ function EliminationTree() {
/>
</div>

{/* <Dropdown /> */}
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个按钮已经删掉了!!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

嗷嗷嗷 我以为你最后才删现在还有用我就没选这个 sorry 这就注释掉 :(

<Dropdown />
</div>
<div>
<CandidateListBar
Expand Down
36 changes: 29 additions & 7 deletions app/dashboard/components/elimination-tree/search-dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,49 @@ import { Candidate } from "./constants";
import { Card, CardContent } from "@/components/ui/card";
import Image from "next/image";

function SearchDropdown({ candidateList }: { candidateList: Candidate[] }) {
// function SearchDropdown({ candidateList }: { candidateList: Candidate[] }) {
// const [searchTerm, setSearchTerm] = useState("");
// const [selectedCandidate, setSelectedCandidate] = useState<Candidate | null>(
// null,
// );
// const [isOpen, setIsOpen] = useState(false);
// //不能用shadcn的popover,因为他的popover弹出瞬间会让input失去焦点
//
// const filteredList = candidateList.filter((candidate) =>
// candidate.name.toLowerCase().includes(searchTerm.toLowerCase()),
// );
// const handleSelect = (candidate: Candidate) => {
// setSelectedCandidate(candidate);
// setSearchTerm(candidate.name);
// console.log("Selected Candidate:", candidate.name);
// setIsOpen(false);
// };

function SearchDropdown({
candidateList,
onSelect,
}: {
candidateList: Candidate[];
onSelect: (candidateId: number) => void;
}) {
const [searchTerm, setSearchTerm] = useState("");
const [selectedCandidate, setSelectedCandidate] = useState<Candidate | null>(
null,
);
const [isOpen, setIsOpen] = useState(false);
//不能用shadcn的popover,因为他的popover弹出瞬间会让input失去焦点

const filteredList = candidateList.filter((candidate) =>
candidate.name.toLowerCase().includes(searchTerm.toLowerCase()),
);

const handleSelect = (candidate: Candidate) => {
setSelectedCandidate(candidate);
setSearchTerm(candidate.name);
console.log("Selected Candidate:", candidate.name);
onSelect(candidate.id);
setIsOpen(false);
};
return (
<div className="relative">
<Input
value={searchTerm}
type="search"
placeholder="Search for candidate"
onChange={(e) => setSearchTerm(e.target.value)}
onFocus={() => setIsOpen(true)}
onBlur={() => setIsOpen(false)}
Expand Down
4 changes: 2 additions & 2 deletions app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { ChevronRight, FilePenLine } from "lucide-react";

import EliminationTree from "./components/elimination-tree";
import AvatarAssignColor from "./components/avatar-assign-color"; // 引入 Avatar 组件
import useMultiWinnerDataStore from "@/store/MultiWinnerData";
import multiWinnerData from "@/store/MultiWinnerData"; // 引入 zustand store
import useMultiWinnerDataStore from "@/store/multi-winner-data";
import multiWinnerData from "@/store/multi-winner-data"; // 引入 zustand store

const Dashboard: React.FC = () => {
const { candidateList, assertionList, winnerInfo } =
Expand Down
6 changes: 3 additions & 3 deletions app/sample/components/sample-selector.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import Image from "next/image";
import useMultiWinnerDataStore from "../../../store/MultiWinnerData";
import { AvatarColor } from "@/utils/avatarColor";
import useMultiWinnerDataStore from "../../../store/multi-winner-data";
import { AvatarColor } from "@/utils/avatar-color";
import { explainAssertions } from "../../explain-assertions/components/explain-process";
import { useRouter } from "next/navigation";

Expand All @@ -18,7 +18,7 @@ const sampleFiles: SampleFile[] = [
description: "NEB assertions example",
imageUrl: "/sample-images/img.png",
// fileUrl: "/sample-jsons/a_guide_to_RAIRE_eg_NEB_assertions.json",
fileUrl: "/sample-jsons/City of Coffs Harbour Mayoral.json",
fileUrl: "/sample-jsons/a_guide_to_RAIRE_eg_NEB_assertions.json",
},
{
name: "One candidate dominates example",
Expand Down
4 changes: 2 additions & 2 deletions app/upload/components/uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React, { useState, useEffect, useCallback } from "react";
import { CloudUpload, File, ArrowLeft, Link } from "lucide-react";
import CustomAlertDialog from "./alert-dialog";
import UploadProgress from "./progress";
import useMultiWinnerDataStore from "../../../store/MultiWinnerData";
import useMultiWinnerDataStore from "../../../store/multi-winner-data";
import { explainAssertions } from "../../explain-assertions/components/explain-process";
import { useRouter } from "next/navigation";
import { AvatarColor } from "@/utils/avatarColor";
import { AvatarColor } from "@/utils/avatar-color";

interface UploaderProps {
className?: string;
Expand Down
2 changes: 1 addition & 1 deletion components/ui/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import * as React from "react";
import * as AvatarPrimitive from "@radix-ui/react-avatar";
import { cn } from "@/lib/utils";
import useMultiWinnerDataStore from "@/store/MultiWinnerData"; // 引入 zustand store
import useMultiWinnerDataStore from "@/store/multi-winner-data"; // 引入 zustand store

// 定义 AvatarProps 接口,明确指定 candidateId 的类型
interface AvatarProps
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion utils/avatarColor.ts → utils/avatar-color.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// utils/avatarColor.ts
// utils/avatar-color.ts

export class AvatarColor {
private colors: string[] = [
Expand Down
Loading