-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show received messages in history card
- Loading branch information
1 parent
fb678a5
commit 1389376
Showing
4 changed files
with
60 additions
and
38 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
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 |
---|---|---|
@@ -1,13 +1,34 @@ | ||
import { IonCard, IonCardHeader, IonCardTitle, IonCardContent } from "@ionic/react"; | ||
import { IonCard, IonCardHeader, IonCardTitle, IonCardContent, IonItem } from "@ionic/react"; | ||
import React from "react"; | ||
import { SessionMessage } from "../session/SessionMessage"; | ||
|
||
export const HistoryCard: React.FC<{}> = () => { | ||
export type HistoryCardProps = { | ||
messages: SessionMessage[]; | ||
} | ||
|
||
export const HistoryCard: React.FC<HistoryCardProps> = ({messages}) => { | ||
return <IonCard> | ||
<IonCardHeader> | ||
<IonCardTitle>History</IonCardTitle> | ||
</IonCardHeader> | ||
<IonCardContent> | ||
<p>Shared content will show up here .</p> | ||
{ messages.length === 0 ? <NoMessages/> : | ||
messages.map(msg => <Message msg={msg} />) } | ||
</IonCardContent> | ||
</IonCard>; | ||
}; | ||
|
||
type MessageProps = { | ||
msg: SessionMessage; | ||
} | ||
|
||
const Message: React.FC<MessageProps> = ({msg}) => { | ||
return <IonItem> | ||
<b>{msg.senderName}: </b> | ||
{msg.text} | ||
</IonItem> | ||
} | ||
|
||
const NoMessages: React.FC = () => { | ||
return <div>Shared content will show up here.</div> | ||
} |
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 |
---|---|---|
@@ -1,12 +1,28 @@ | ||
export type SessionMessageType = "TEXT_MESSAGE" | "FILE" | "OPEN_WEBSITE"; | ||
import { ServerTypes } from "../../ServerTypes"; | ||
|
||
export const sessionMessageTypes = ["TEXT_MESSAGE", "FILE", "OPEN_WEBSITE"] as const; | ||
export type SessionMessageType = typeof sessionMessageTypes[number]; | ||
|
||
export interface SessionMessage { | ||
type: SessionMessageType; | ||
type?: SessionMessageType; | ||
senderId: string; | ||
senderName: string; | ||
text: string; | ||
text?: string; | ||
} | ||
|
||
export interface OpenWebsiteSessionMessage extends SessionMessage { | ||
type: "OPEN_WEBSITE" | ||
} | ||
|
||
export function mapSessionMsg(serverMsg: ServerTypes.BroadcastFromSessionMsg): SessionMessage { | ||
let sessionMsgType = serverMsg.payload["type"] as SessionMessageType | undefined; | ||
if (sessionMessageTypes.indexOf(sessionMsgType as SessionMessageType) < 0) { | ||
sessionMsgType = undefined; | ||
} | ||
return { | ||
type: sessionMsgType, | ||
senderId: serverMsg.senderId, | ||
senderName: serverMsg.payload["senderName"] ?? "", | ||
text: serverMsg.payload["text"] ?? "" | ||
}; | ||
} |
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