101 lines
2.9 KiB
TypeScript
101 lines
2.9 KiB
TypeScript
"use client";
|
|
import React, { useEffect, useState } from "react";
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import Link from "next/link";
|
|
import { FaRegChartBar } from "react-icons/fa6";
|
|
import { useRouter } from "next/navigation";
|
|
import { ThreeDots } from "react-loader-spinner";
|
|
import { getPolls } from "@/utils/CitizenPolls";
|
|
import { convertFullTime } from "@/lib/utils";
|
|
|
|
export class STR {
|
|
static removeTags(str = "") {
|
|
return str.replace(/(<([^>])+>)/gi, "").replace(/ /gi, "");
|
|
}
|
|
|
|
static parseHtml(str: any) {
|
|
const div = document.createElement("div");
|
|
div.innerHTML = str;
|
|
const images = div.getElementsByTagName("img");
|
|
// if (images.length > 0) {
|
|
// Array.from(images).forEach((image) => {
|
|
// let imageSrc = image.getAttribute("src");
|
|
// image.src = URI.createMediaUri(imageSrc);
|
|
// });
|
|
// }
|
|
return div.innerHTML;
|
|
}
|
|
}
|
|
|
|
interface Poll {
|
|
id: string;
|
|
title: string;
|
|
pollType: number;
|
|
question: string;
|
|
choices: any;
|
|
pollState: number;
|
|
created: string;
|
|
expiration: string;
|
|
answer: any;
|
|
isDeleted: boolean;
|
|
}
|
|
const Poll = () => {
|
|
const router = useRouter();
|
|
const [polls, setPolls] = useState<any | null>(null);
|
|
const { data, isLoading, isError, isSuccess, refetch } = useQuery({
|
|
queryKey: ["Polls"],
|
|
queryFn: () => getPolls(),
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (data) {
|
|
console.log(data);
|
|
console.log(data.data);
|
|
console.log(data.data[0]);
|
|
setPolls(data.data);
|
|
}
|
|
}, [data]);
|
|
|
|
return (
|
|
<div className="w-full h-full flex flex-row flex-wrap justify-between">
|
|
{isLoading ? (
|
|
<div className="flex justify-center items-center text-center w-full h-full">
|
|
<ThreeDots
|
|
visible={true}
|
|
height="50"
|
|
width="50"
|
|
color="#003778"
|
|
radius="9"
|
|
ariaLabel="three-dots-loading"
|
|
wrapperStyle={{}}
|
|
wrapperClass=""
|
|
/>
|
|
</div>
|
|
) : (
|
|
<>
|
|
{isSuccess &&
|
|
polls?.map((item: any) => (
|
|
<Link
|
|
href={`/User/Polls/${item.id}`}
|
|
className="flex flex-col items-start justify-around min-w-72 h-48 bg-white shadow-[0_0_2px_1px_rgba(0,0,0,0.1)] rounded-lg p-3 mb-4"
|
|
>
|
|
<FaRegChartBar className="text-2xl text-blue mb-3" />
|
|
<p className="text-lg font-bold text-black mb-3">
|
|
{item.title}
|
|
</p>
|
|
<p className="text-[15px] text-gray-400 mb-3">
|
|
{STR.removeTags(item.question)}
|
|
</p>
|
|
<p className="text-xs w-full mt-3 pt-3 border-t-[1px] border-t-gray-200 font-bold text-gray-400">
|
|
{/* {convertFullTime(item?.created)} */}
|
|
</p>
|
|
</Link>
|
|
))}
|
|
</>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Poll;
|