Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #1306 Lets you page through your own messages. I also make it easier to show your own deleted messages (there's now an optional include_deleted=true param). But I don't turn this on, because we don't properly currently apply the badge correct to such deleted messages (not sure why) --------- Co-authored-by: notmd <tinhmeo10@gmail.com>
- Loading branch information
Showing
5 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Button, CircularProgress, Flex, Spacer } from "@chakra-ui/react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { get } from "src/lib/api"; | ||
import { FetchUserMessagesCursorResponse } from "src/types/Conversation"; | ||
import useSWRImmutable from "swr/immutable"; | ||
|
||
import { useCursorPagination } from "./DataTable/useCursorPagination"; | ||
import { MessageConversation } from "./Messages/MessageConversation"; | ||
|
||
const UserMessageConversation = () => { | ||
const { pagination, toNextPage, toPreviousPage } = useCursorPagination(); | ||
const { t } = useTranslation("leaderboard"); | ||
|
||
const { data, error, isLoading } = useSWRImmutable<FetchUserMessagesCursorResponse>( | ||
`/api/messages/user?cursor=${encodeURIComponent(pagination.cursor)}&direction=${pagination.direction}`, // If we want to show own deleted messages, add: &include_deleted=true | ||
get, | ||
{ | ||
revalidateOnMount: true, | ||
} | ||
); | ||
|
||
if (isLoading && !data) { | ||
return <CircularProgress isIndeterminate />; | ||
} | ||
|
||
if (error) { | ||
return <>Unable to load messages.</>; | ||
} | ||
|
||
const userMessages = data?.items || []; | ||
|
||
return ( | ||
<div> | ||
<Flex mb="2"> | ||
<Button onClick={() => toPreviousPage(data)} isDisabled={!data?.prev}> | ||
{t("previous")} | ||
</Button> | ||
<Spacer /> | ||
<Button onClick={() => toNextPage(data)} isDisabled={!data?.next}> | ||
{t("next")} | ||
</Button> | ||
</Flex> | ||
<MessageConversation enableLink messages={userMessages} /> | ||
</div> | ||
); | ||
}; | ||
export default UserMessageConversation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters