Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #1881 Barebones chat list UI. The chats we have only contain the ID, we need to expand them to show more stuff so that the users can recongnise which chat it is. Maybe showing the last message and the date of the message would be helpful. I tried as much as possible to avoid potential conflicts with #1913. Known issues: Currently we don't fetch all messages for a given chat ID & therefore we cannot continue a previous chat (because we need the id of the last message), this could be fixed easily by adding a fetch call to `ChatConversion` or whichever equivalent component. ![image](https://user-images.githubusercontent.com/24505302/221964414-42a904bd-7ae7-4448-99e3-61e2892063d0.png) ![image](https://user-images.githubusercontent.com/24505302/221965689-3a38d7a6-6a33-4353-8a07-91e9f5ce73c4.png)
- Loading branch information
Showing
8 changed files
with
148 additions
and
50 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,4 @@ | ||
{ | ||
"back_to_chat_list": "Back to chat list", | ||
"your_chats": "Your chats" | ||
} |
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 was deleted.
Oops, something went wrong.
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,48 @@ | ||
import { Button, Flex } from "@chakra-ui/react"; | ||
import { List } from "lucide-react"; | ||
import { GetServerSideProps } from "next"; | ||
import Head from "next/head"; | ||
import Link from "next/link"; | ||
import { useTranslation } from "next-i18next"; | ||
import { serverSideTranslations } from "next-i18next/serverSideTranslations"; | ||
import { Flags } from "react-feature-flags"; | ||
import { ChatConversation } from "src/components/Chat/ChatConversation"; | ||
import { getDashboardLayout } from "src/components/Layout"; | ||
|
||
const Chat = ({ id }: { id: string }) => { | ||
const { t } = useTranslation(["common", "chat"]); | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>{t("chat")}</title> | ||
</Head> | ||
|
||
<Flags authorizedFlags={["chat"]}> | ||
<Flex direction="column" gap="2"> | ||
<Link href="/chat"> | ||
<Button leftIcon={<List />} size="lg"> | ||
{t("chat:back_to_chat_list")} | ||
</Button> | ||
</Link> | ||
|
||
<ChatConversation chatId={id} /> | ||
</Flex> | ||
</Flags> | ||
</> | ||
); | ||
}; | ||
|
||
Chat.getLayout = getDashboardLayout; | ||
|
||
export const getServerSideProps: GetServerSideProps<{ id: string }, { id: string }> = async ({ | ||
locale = "en", | ||
params, | ||
}) => ({ | ||
props: { | ||
id: params.id, | ||
...(await serverSideTranslations(locale)), | ||
}, | ||
}); | ||
|
||
export default Chat; |
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,71 @@ | ||
import { Button, Divider, Flex, Progress, Text } from "@chakra-ui/react"; | ||
import Head from "next/head"; | ||
import { useTranslation } from "next-i18next"; | ||
import { useCallback, useMemo } from "react"; | ||
import { getDashboardLayout } from "src/components/Layout"; | ||
import { get, post } from "src/lib/api"; | ||
export { getDefaultStaticProps as getStaticProps } from "src/lib/default_static_props"; | ||
import Link from "next/link"; | ||
import { useRouter } from "next/router"; | ||
import { Flags } from "react-feature-flags"; | ||
import { SurveyCard } from "src/components/Survey/SurveyCard"; | ||
import { GetChatsResponse } from "src/types/Chat"; | ||
import useSWRImmutable from "swr/immutable"; | ||
import useSWRMutation from "swr/mutation"; | ||
|
||
const Chat = () => { | ||
const { t } = useTranslation(["common", "chat"]); | ||
const router = useRouter(); | ||
|
||
const { data } = useSWRImmutable<GetChatsResponse>("/api/chat", get); | ||
|
||
const { trigger: newChatTrigger } = useSWRMutation<{ id: string }>("/api/chat", post); | ||
|
||
const createChat = useCallback(async () => { | ||
const { id } = await newChatTrigger(); | ||
router.push(`/chat/${id}`); | ||
}, [newChatTrigger, router]); | ||
|
||
const content = useMemo(() => { | ||
if (!data) { | ||
return <Progress size="sm" isIndeterminate />; | ||
} | ||
return ( | ||
<SurveyCard> | ||
<Flex direction="column" gap="4"> | ||
<Text fontSize="xl" fontWeight="bold"> | ||
{t("chat:your_chats")} | ||
</Text> | ||
<Divider /> | ||
{data.chats.map(({ id }) => ( | ||
<Link key={id} href={`/chat/${id}`}> | ||
{/* TODO: we really only the have the id for each case our users will probably have no idea which is which | ||
maybe we could show the last message & its date, this is not provided by the API right now */} | ||
<Text as={Button} py={2} display="block" bg="inherit" w="full" textAlign="start" borderRadius="sm"> | ||
{id} | ||
</Text> | ||
</Link> | ||
))} | ||
<Divider /> | ||
<Button maxW="2xs" onClick={createChat}> | ||
{t("create_chat")} | ||
</Button> | ||
</Flex> | ||
</SurveyCard> | ||
); | ||
}, [data, createChat, t]); | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>{t("chat")}</title> | ||
</Head> | ||
|
||
<Flags authorizedFlags={["chat"]}>{content}</Flags> | ||
</> | ||
); | ||
}; | ||
|
||
Chat.getLayout = getDashboardLayout; | ||
|
||
export default Chat; |
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