вернула запрос 100 вопросов
This commit is contained in:
parent
e54475bfe9
commit
38b67c9412
@ -75,8 +75,52 @@ export const publicationMakeRequest = ({ url, body }: PublicationMakeRequestPara
|
||||
// Глобальные переменные для хранения состояния между вызовами
|
||||
let globalStatus: string | null = null;
|
||||
let isFirstRequest = true;
|
||||
export async function getData({ quizId }: { quizId: string }): Promise<{
|
||||
data: GetQuizDataResponse | null;
|
||||
isRecentlyCompleted: boolean;
|
||||
error?: AxiosError;
|
||||
}> {
|
||||
try {
|
||||
const { data, headers } = await axios<GetQuizDataResponse>(
|
||||
domain + `/answer/v1.0.0/settings${window.location.search}`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"X-Sessionkey": SESSIONS,
|
||||
"Content-Type": "application/json",
|
||||
DeviceType: DeviceType,
|
||||
Device: Device,
|
||||
OS: OSDevice,
|
||||
Browser: userAgent,
|
||||
},
|
||||
data: {
|
||||
quiz_id: quizId,
|
||||
limit: 100,
|
||||
page: 0,
|
||||
need_config: true,
|
||||
},
|
||||
}
|
||||
);
|
||||
const sessions = JSON.parse(localStorage.getItem("sessions") || "{}");
|
||||
|
||||
export async function getData({ quizId, page }: { quizId: string; page?: number }): Promise<{
|
||||
//Тут ещё проверка на антифрод без парса конфига. Нам не интересно время если не нужно запрещать проходить чаще чем в сутки
|
||||
if (typeof sessions[quizId] === "number" && data.settings.cfg.includes('antifraud":true')) {
|
||||
// unix время. Если меньше суток прошло - выводить ошибку, иначе пустить дальше
|
||||
if (Date.now() - sessions[quizId] < 86400000) {
|
||||
return { data, isRecentlyCompleted: true };
|
||||
}
|
||||
}
|
||||
|
||||
SESSIONS = headers["x-sessionkey"] ? headers["x-sessionkey"] : SESSIONS;
|
||||
|
||||
return { data, isRecentlyCompleted: false };
|
||||
} catch (nativeError) {
|
||||
const error = nativeError as AxiosError;
|
||||
|
||||
return { data: null, isRecentlyCompleted: false, error: error };
|
||||
}
|
||||
}
|
||||
export async function getDataSingle({ quizId, page }: { quizId: string; page?: number }): Promise<{
|
||||
data: GetQuizDataResponse | null;
|
||||
isRecentlyCompleted: boolean;
|
||||
error?: AxiosError;
|
||||
@ -231,7 +275,7 @@ export async function getQuizDataAI(quizId: string) {
|
||||
while (resultRetryCount < maxRetries) {
|
||||
try {
|
||||
console.log(`[getQuizDataAI] Attempt ${resultRetryCount + 1} for result questions, page: ${page}`);
|
||||
const response = await getData({ quizId, page });
|
||||
const response = await getData({ quizId });
|
||||
console.log("[getQuizDataAI] Response from getData:", response);
|
||||
|
||||
if (response.error) {
|
||||
@ -286,7 +330,7 @@ export async function getQuizDataAI(quizId: string) {
|
||||
try {
|
||||
console.log(`[getQuizDataAI] Empty items retry ${emptyRetryCount + 1}`);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
const response = await getData({ quizId, page });
|
||||
const response = await getData({ quizId });
|
||||
|
||||
if (response.error) {
|
||||
console.error("[getQuizDataAI] Error in empty items check:", response.error);
|
||||
|
@ -0,0 +1,122 @@
|
||||
import { Box, ButtonBase, Typography, useTheme } from "@mui/material";
|
||||
import { useMemo, useState } from "react";
|
||||
import { useRootContainerSize } from "@contexts/RootContainerWidthContext";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { enqueueSnackbar } from "notistack";
|
||||
import { ACCEPT_SEND_FILE_TYPES_MAP } from "@/components/ViewPublicationPage/tools/fileUpload";
|
||||
import UploadIcon from "@icons/UploadIcon";
|
||||
import { uploadFile } from "@/utils/fileUpload";
|
||||
import { useQuizStore } from "@/stores/useQuizStore";
|
||||
|
||||
interface ImageCardProps {
|
||||
questionId: string;
|
||||
imageUrl: string;
|
||||
isOwn?: boolean;
|
||||
onImageUpload?: (fileUrl: string) => void;
|
||||
}
|
||||
|
||||
const useFileUpload = (questionId: string, onImageUpload?: (fileUrl: string) => void) => {
|
||||
const { t } = useTranslation();
|
||||
const [isSending, setIsSending] = useState(false);
|
||||
const [currentImageUrl, setCurrentImageUrl] = useState<string | null>(null);
|
||||
const { quizId, preview } = useQuizStore();
|
||||
|
||||
const handleFileUpload = async (file: File | undefined) => {
|
||||
if (isSending || !file) return;
|
||||
|
||||
const result = await uploadFile({
|
||||
file,
|
||||
questionId,
|
||||
quizId,
|
||||
fileType: "picture",
|
||||
preview,
|
||||
onSuccess: (fileUrl) => {
|
||||
setCurrentImageUrl(URL.createObjectURL(file));
|
||||
onImageUpload?.(fileUrl);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
enqueueSnackbar(t(error.message));
|
||||
},
|
||||
onProgress: () => {
|
||||
setIsSending(true);
|
||||
},
|
||||
});
|
||||
|
||||
setIsSending(false);
|
||||
};
|
||||
|
||||
return {
|
||||
isSending,
|
||||
currentImageUrl,
|
||||
handleFileUpload,
|
||||
};
|
||||
};
|
||||
|
||||
export const ImageCard = ({ questionId, imageUrl, isOwn, onImageUpload }: ImageCardProps) => {
|
||||
const theme = useTheme();
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useRootContainerSize() < 450;
|
||||
const isTablet = useRootContainerSize() < 850;
|
||||
const [isDropzoneHighlighted, setIsDropzoneHighlighted] = useState(false);
|
||||
const { currentImageUrl, handleFileUpload } = useFileUpload(questionId, onImageUpload);
|
||||
|
||||
const onDrop = (event: React.DragEvent<HTMLLabelElement>) => {
|
||||
event.preventDefault();
|
||||
setIsDropzoneHighlighted(false);
|
||||
|
||||
const file = event.dataTransfer.files[0];
|
||||
handleFileUpload(file);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ width: "100%", height: "300px", position: "relative" }}>
|
||||
<img
|
||||
src={currentImageUrl || imageUrl}
|
||||
style={{
|
||||
display: "block",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
objectFit: "cover",
|
||||
borderRadius: "12px 12px 0 0",
|
||||
}}
|
||||
alt=""
|
||||
/>
|
||||
{isOwn && (
|
||||
<Box
|
||||
component="label"
|
||||
sx={{
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
||||
opacity: isDropzoneHighlighted ? 1 : 0,
|
||||
transition: "opacity 0.2s",
|
||||
"&:hover": {
|
||||
opacity: 1,
|
||||
},
|
||||
borderRadius: "12px 12px 0 0",
|
||||
cursor: "pointer",
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
onDragEnter={() => setIsDropzoneHighlighted(true)}
|
||||
onDragLeave={() => setIsDropzoneHighlighted(false)}
|
||||
onDragOver={(event) => event.preventDefault()}
|
||||
onDrop={onDrop}
|
||||
>
|
||||
<input
|
||||
onChange={({ target }) => handleFileUpload(target.files?.[0])}
|
||||
hidden
|
||||
accept={ACCEPT_SEND_FILE_TYPES_MAP.picture.join(",")}
|
||||
type="file"
|
||||
/>
|
||||
<UploadIcon color="#FFFFFF" />
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
Loading…
Reference in New Issue
Block a user