@@ -19,7 +19,7 @@ export function useImageBotPagination(deviceType: Device) { const [messages, setMessages] = useState([]) - const [loading, setLoading] = useState(false) + const [loading, setLoading] = useState(true) const { showError } = useShowData() @@ -53,19 +53,16 @@ export function useImageBotPagination(deviceType: Device) { offset.current, count || 10 ) - setLoading(false) if (response.status >= 400 || !Array.isArray(answer)) return showError('Ошибка загрузки чата') if (deviceType === 'desktop') { setMessages((prev) => [...prev, ...answer]) - offset.current = offset.current + answer.length return } setMessages((prev) => [...answer.reverse(), ...prev]) - offset.current = offset.current + answer.length } const callback = async function (entries: IntersectionObserverEntry[]) { @@ -79,19 +76,30 @@ export function useImageBotPagination(deviceType: Device) { fetchMessages(active?.firstLimit) } - if (!mobileScrollContainer.current) return + const { current } = mobileScrollContainer - const scrollBottom = - mobileScrollContainer.current.scrollHeight - mobileScrollContainer.current.scrollTop + if (!current) return + + const scrollBottom = current.scrollHeight - current.scrollTop await fetchMessages() setTimeout(() => { - if (!mobileScrollContainer.current) return - mobileScrollContainer.current!.scroll({ - top: mobileScrollContainer.current!.scrollHeight - scrollBottom, - behavior: 'smooth', - }) + const { current } = mobileScrollContainer + + if (!current) return + + if (offset.current === 0) current.scrollTop = current.scrollHeight - scrollBottom + else { + current.scroll({ + top: current.scrollHeight - scrollBottom, + behavior: 'smooth', + }) + } + + offset.current = offset.current + 10 + + setLoading(false) }, 500) } @@ -113,6 +121,7 @@ export function useImageBotPagination(deviceType: Device) { messages, loading, setLoading, + offset, setMessages, fetchMessages, mobileScrollContainer, @@ -0,0 +1,17 @@ +.container { + width: 100%; + border-radius: 15px; + height: 100%; + position: absolute; + bottom: 0; + left: 0; + background-color: var(--new-ui-main-color); + opacity: 0; + z-index: -1; + transition: all 0.3s ease-in-out; + + &_active { + opacity: 1; + z-index: 100; + } +} @@ -8,7 +8,7 @@ import { useImagesBotFilters } from '@/src/features/image-bot-filters' import { useImagesUniqInput } from '@/src/features/image-bot-input' import { useImageBotPagination } from '@/src/features/image-bot-pagination' import Title from '@/src/features/title/title' -import { useShowData, DrawerCustom, Error } from '@/src/shared' +import { useShowData, DrawerCustom, Error, Loader } from '@/src/shared' import { useThemeAndDevice } from '@/src/shared/lib/hooks' import { ArrowDownScroll } from '@/src/shared/ui/icon-components/scroll-down-arrow' import { useImagesPagination, ImageMessagesList } from '@/src/widgets/messages' @@ -18,9 +18,11 @@ import { useSession } from 'next-auth/react' import Head from 'next/head' import { useRouter } from 'next/router' import { useEffect } from 'react' -import { getDeviceType, getOs } from '@/src/shared/lib/helpers' +import { c, getDeviceType, getOs } from '@/src/shared/lib/helpers' import { Device, DeviceOs } from '@/src/shared/lib/types/entities' +import styles from './image-model.module.scss' + export interface ImageModelPageProps { deviceType: Device deviceOs: DeviceOs @@ -58,6 +60,7 @@ const ImageModelPage = ({ deviceType, deviceOs }: ImageModelPageProps) => { setMessages, fetchMessages, loading, + offset, messages, } = useImageBotPagination(deviceType) @@ -79,10 +82,6 @@ const ImageModelPage = ({ deviceType, deviceOs }: ImageModelPageProps) => { await Promise.all([fetchBotParams()]) } - useEffect(() => { - console.log(createLoading) - }, [createLoading]) - useEffect(() => { onFetch() onObserverMounted() @@ -139,10 +138,13 @@ const ImageModelPage = ({ deviceType, deviceOs }: ImageModelPageProps) => { { ) : ( - + +
+
+ +
+
+ { ref={refScrollMobile} > { device: 'mobile' | 'desktop' images: Message[] getMessagesPagination?: () => Promise @@ -23,7 +23,7 @@ interface MessagesList { } export const ImageMessagesList: React.FC = memo( - ({ device, images, getMessagesPagination }) => { + ({ device, images, isComplete, ...props }) => { const { error, showError, isError } = useShowData() const [modal, setModal] = useState(false) const theme = useAppSelector((state) => state.theme.theme) @@ -35,7 +35,7 @@ export const ImageMessagesList: React.FC = memo( <> - + = memo( ГЕНЕРАЦИИ + {/* {isComplete && ( +
+ +
+ )} */} +