Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | import { List } from "@mui/material"; import Alert from "components/Alert"; import Button from "components/Button"; import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner"; import TextBody from "components/TextBody"; import HostRequestListItem from "features/messages/requests/HostRequestListItem"; import useMessageListStyles from "features/messages/useMessageListStyles"; import { hostRequestsListKey } from "features/queryKeys"; import { RpcError } from "grpc-web"; import { useTranslation } from "i18n"; import { MESSAGES } from "i18n/namespaces"; import Link from "next/link"; import { GroupChat } from "proto/conversations_pb"; import { ListHostRequestsRes } from "proto/requests_pb"; import * as React from "react"; import { useInfiniteQuery } from "react-query"; import { routeToHostRequest } from "routes"; import { service } from "service"; export interface GroupChatListProps { groupChats: Array<GroupChat.AsObject>; } export default function RequestsTab({ type, onlyActive = false, }: { type: "all" | "hosting" | "surfing"; onlyActive?: boolean; }) { const { t } = useTranslation(MESSAGES); const { data, isLoading, error, fetchNextPage, hasNextPage, isFetchingNextPage, } = useInfiniteQuery<ListHostRequestsRes.AsObject, RpcError>( hostRequestsListKey({ onlyActive, type }), ({ pageParam: lastRequestId }) => service.requests.listHostRequests({ lastRequestId, onlyActive, type }), { getNextPageParam: (lastPage) => lastPage.noMore ? undefined : lastPage.lastRequestId, } ); const loadMoreRequests = () => fetchNextPage(); const classes = useMessageListStyles(); return ( <div className={classes.root}> {error && <Alert severity="error">{error.message}</Alert>} {isLoading ? ( <CenteredSpinner /> ) : ( <List className={classes.list}> {data && data.pages.map((hostRequestsRes, pageNumber) => pageNumber === 0 && hostRequestsRes.hostRequestsList.length === 0 ? ( <TextBody key="no-requests-text"> {t("requests_tab.no_requests_message")} </TextBody> ) : ( <React.Fragment key={`host-requests-page-${pageNumber}`}> {hostRequestsRes.hostRequestsList.map((hostRequest) => ( <Link href={routeToHostRequest(hostRequest.hostRequestId)} key={hostRequest.hostRequestId} > <HostRequestListItem hostRequest={hostRequest} className={classes.listItem} /> </Link> ))} </React.Fragment> ) )} {hasNextPage && ( <Button onClick={loadMoreRequests} loading={isFetchingNextPage}> {t("requests_tab.load_more_button_label")} </Button> )} </List> )} </div> ); } |