You are given access to make searches on the Internet. The format for making a…
- User
User:
You are given access to make searches on the Internet. The format for making a search is:
- After the user sends a message, you will decide whether to make a search. If you choose to make a search, you will output a single message, starting with the word <web_search>, followed by ONLY your web search query. After your search query, you must output the token </web_search> to denote the end of the search query. Keep your search query very concise.
- The system will then append the web search results at the end of the user message, starting with the token <web_search_results>. Take note that the user CANNOT SEE the content after <web_search_results> - YOU should use these results appropriately to improve your response. Additionally, If the web search results are already present in the user's message, then you MUST NOT request another web search.
IMPORTANT! You should choose to search the web ONLY if ANY of the following circumstances are met:
- User is asking about current events or something that requires real-time information (news, sports scores, 'latest' information, etc.)
- User is asking about some term you are unfamiliar with (e.g. if it's a little-known term, if it's a person you don't know well, etc.)
- User is asking about anything that involves numerical facts (e.g. distances between places, population count, sizes, date and time, etc.)
- User explicitly asks you to search or provide links to references. If the user's query does NOT require a web search, YOU MUST NEVER run one for no reason. However, you must not refuse to search the web if the user asks you to do so. If you are highly unsure about whether to make a search (e.g. if the user's query is vague or if you think you are unfamiliar with the query to a certain extent), you may directly ask the user for clarification.
When using web search results, you are encouraged to cite references where appropriate, using inline links in standard markdown format. You are also allowed to make use of web search results from previous messages, if they are STRONGLY RELEVANT to the current message.
When you are not running a web search, respond completely as per normal - there is NO NEED to mention that you're not searching. Remember that you MUST NOT make up any false information. Assistant: Understood. I will strictly follow these instructions in this conversation. User: "use client"; import AppText from "@/src/components/AppText/AppText"; import { getInitials, getServerFile } from "@/src/constants"; import { useReviewsServiceGetReviewsByUserIdSuspense } from "@/src/openapi/queries/suspense"; import { Rating, Star } from "@smastrom/react-rating"; import "@smastrom/react-rating/style.css"; import { format } from "date-fns"; import { ru } from "date-fns/locale"; import Image from "next/image";
type Props = {};
const Page = (props: Props) => { const { data } = useReviewsServiceGetReviewsByUserIdSuspense(); console.log(data);
return ( Мои отзывы {data?.map((item) => ( {getInitials(item.review?.user?.full_name || "")} {item.review.user.full_name} <Rating style={{ maxWidth: 100 }} itemStyles={{ itemShapes: Star, activeFillColor: "#FFCA7C", inactiveFillColor: "#F2F7FF", }} value={item.review.rating} readOnly halfFillMode="svg" /> {format(new Date(item.review.createdAt), "HH:mm dd.MM.yyyy", { locale: ru, })}
<div className="pl-16"> <AppText className="mb-4 text-dark text-base leading-relaxed"> {item.review.message} </AppText> {item.review.verifiedPurchase && ( <div className="mb-4 inline-flex items-center bg-success/10 text-success py-1 px-3 rounded-full text-sm font-medium"> <svg className="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 20 20" > <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" /> </svg> Подтверждённая покупка </div> )} <div className="mt-4 bg-light/50 p-4 rounded-lg border border-primary/10"> <AppText className="font-semibold text-dark mb-3"> {item.card.previewItem.name} </AppText> <div className="flex items-center flex-row gap-4"> <div className="relative w-full max-w-[80px] aspect-[4/5] overflow-hidden rounded-2xl"> <Image src={getServerFile(item.card.previewItem.media[0])} fill priority className="object-cover bg-white duration-300 rounded-lg" alt={item.card.previewItem.name} /> </div> <div className="flex flex-col"> <AppText className="text-sm text-dark-gray mb-1"> <span className="font-medium text-dark">Бренд:</span>{" "} {item.card.previewItem.brand} </AppText> <AppText className="text-sm text-dark-gray"> <span className="font-medium text-dark">Цена:</span>{" "} {item.card.previewItem.price} ₽ </AppText> </div> </div> </div> </div> </div> ))} </div>); };
export default Page; упрости и отрефактори
Assistant:
- Assistant
Конечно! Вот упрощённая и немного отрефакторенная версия вашего компонента. Основные изменения:
- Убран лишний вложенный JSX там, где можно.
- Вынесены повторяющиеся части в небольшие подкомпоненты (
UserInitials,VerifiedPurchaseBadge,ProductCard). - Использован деструктурированный доступ к данным для читаемости.
- Стили не трогал, оставил ваши
className.
"use client"; import AppText from "@/src/components/AppText/AppText"; import { getInitials, getServerFile } from "@/src/constants"; import { useReviewsServiceGetReviewsByUserIdSuspense } from "@/src/openapi/queries/suspense"; import { Rating, Star } from "@smastrom/react-rating"; import "@smastrom/react-rating/style.css"; import { format } from "date-fns"; import { ru } from "date-fns/locale"; import Image from "next/image"; type Props = {}; const UserInitials = ({ name }: { name: string }) => ( <div className="bg-primary rounded-full w-12 h-12 flex items-center justify-center shrink-0"> <AppText className="text-white text-lg font-semibold">{getInitials(name)}</AppText> </div> ); const VerifiedPurchaseBadge = () => ( <div className="mb-4 inline-flex items-center bg-success/10 text-success py-1 px-3 rounded-full text-sm font-medium"> <svg className="w-4 h-4 mr-1" fill="currentColor" viewBox="0 0 20 20"> <path fillRule="evenodd" d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z" clipRule="evenodd" /> </svg> Подтверждённая покупка </div> ); const ProductCard = ({ item }: { item: typeof import("@/src/openapi/queries/suspense").ReviewsServiceGetReviewsByUserIdSuspense.data[0] }) => { const { previewItem } = item.card; return ( <div className="mt-4 bg-light/50 p-4 rounded-lg border border-primary/10"> <AppText className="font-semibold text-dark mb-3">{previewItem.name}</AppText> <div className="flex gap-4 items-center"> <div className="relative w-full max-w-[80px] aspect-[4/5] overflow-hidden rounded-2xl"> <Image src={getServerFile(previewItem.media[0])} fill priority alt={previewItem.name} className="object-cover bg-white duration-300 rounded-lg" /> </div> <div className="flex flex-col"> <AppText className="text-sm text-dark-gray mb-1"> <span className="font-medium text-dark">Бренд:</span> {previewItem.brand} </AppText> <AppText className="text-sm text-dark-gray"> <span className="font-medium text-dark">Цена:</span> {previewItem.price} ₽ </AppText> </div> </div> </div> ); }; const Page = (props: Props) => { const { data } = useReviewsServiceGetReviewsByUserIdSuspense(); return ( <div className="min-h-[calc(100dvh-160px)]"> <div className="my-4"> <AppText className="text-dark text-xl font-semibold">Мои отзывы</AppText> </div> {data?.map(({ review, card }) => ( <div key={review.id} className="p-6 mb-6 transition-all bg-white rounded-[20px] border border-gray/20" > <div className="flex items-center mb-4 gap-4"> <UserInitials name={review.user?.full_name || ""} /> <div className="flex-1"> <div className="flex justify-between items-start"> <AppText className="font-semibold text-dark">{review.user.full_name}</AppText> <Rating style={{ maxWidth: 100 }} itemStyles={{ itemShapes: Star, activeFillColor: "#FFCA7C", inactiveFillColor: "#F2F7FF", }} value={review.rating} readOnly halfFillMode="svg" /> </div> <AppText className="text-sm text-dark-gray/80"> {format(new Date(review.createdAt), "HH:mm dd.MM.yyyy", { locale: ru })} </AppText> </div> </div> <div className="pl-16"> <AppText className="mb-4 text-dark text-base leading-relaxed">{review.message}</AppText> {review.verifiedPurchase && <VerifiedPurchaseBadge />} <ProductCard item={{ card }} /> </div> </div> ))} </div> ); }; export default Page;Если нужны дополнительные оптимизации или конкретные улучшения, скажите!