Skip to content

Commit

Permalink
Merge pull request #34 from michaelclapham/improve-session-page1
Browse files Browse the repository at this point in the history
Refactor + Improve session page
  • Loading branch information
michaelclapham authored Mar 31, 2024
2 parents 21f3fd6 + d9c6f29 commit 6255598
Show file tree
Hide file tree
Showing 14 changed files with 285 additions and 245 deletions.
7 changes: 0 additions & 7 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
body {
--ion-color-primary: #107c76;
--ion-background-color: rgb(39, 39, 39);
--ion-text-color: white;
--ion-text-color-rgb: 255, 255, 255;
}

.modal-wrapper {
Expand All @@ -12,8 +9,6 @@ body {
.App {
text-align: center;
height: 100vh;
background-color: #282c34;
color: white;
}

.app-title-container {
Expand Down Expand Up @@ -65,8 +60,6 @@ body {
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
border-bottom: 1px solid white;
}

.App-link {
Expand Down
28 changes: 25 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { WSClient } from "./WSClient";
import { ServerTypes } from "./ServerTypes";
import { SessionPage } from "./feature/session/SessionPage";
import { NavigateOnStateChange } from "./NavigateOnStateChange";
import { SessionMessage, mapSessionMsg } from "./feature/session/SessionMessage";

export const App: React.FC = () => {
let wsUrl = "wss://qrsync.org/api/v1/ws";
Expand All @@ -19,6 +20,8 @@ export const App: React.FC = () => {
const [clientMap, setClientMap] = useState<
Record<string, ServerTypes.Client>
>({});
const [sessionMessages, setSessionMessages] = useState<SessionMessage[]>([]);

// State used to navigate to route via a server sent event (not user link click)
const [changeToRoute, setChangeToRoute] = useState<string | undefined>();

Expand Down Expand Up @@ -73,15 +76,32 @@ export const App: React.FC = () => {
};

const onBroadcastFromSessionMsg = (
msg: ServerTypes.BroadcastFromSessionMsg
) => {};
serverMsg: ServerTypes.BroadcastFromSessionMsg
) => {
const newMsg = mapSessionMsg(serverMsg);
const newMsgs = sessionMessages.concat([newMsg]);
setSessionMessages(newMsgs);
};

const onLeaveSession = () => {
wsClient.leaveSession();
setSessionId(undefined);
setChangeToRoute("/index.html");
};

const onShare = (msg: SessionMessage) => {
let msgWithSender: SessionMessage = {
...msg,
senderId: wsClient.getId() ?? "",
senderName: wsClient.getName(),
}
let serverMsg: ServerTypes.BroadcastToSessionMsg = {
type: "BroadcastToSession",
payload: msgWithSender
};
wsClient.sendMessage(serverMsg);
}

return (
<IonApp>
<IonReactRouter>
Expand All @@ -99,10 +119,12 @@ export const App: React.FC = () => {
</Route>
<Route path="/session">
<SessionPage
wsClient={wsClient}
sessionMessages={sessionMessages}
userIsSessionOwner={wsClient.getId() === sessionOwnerId}
sessionId={sessionId}
clientMap={clientMap}
sessionOwnerId={sessionOwnerId}
onShare={onShare}
onLeaveSession={onLeaveSession}
></SessionPage>
</Route>
Expand Down
66 changes: 66 additions & 0 deletions src/feature/clients/ClientsCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
IonCard,
IonCardHeader,
IonCardTitle,
IonCardSubtitle,
IonCardContent,
IonButton,
} from "@ionic/react";
import React from "react";
import { ServerTypes } from "../../ServerTypes";

export type ClientsCardProps = {
ownerId: string | undefined;
clientMap: Record<string, ServerTypes.Client>;
addClientClicked: () => void;
};

export const ClientsCard: React.FC<ClientsCardProps> = ({
clientMap,
ownerId,
addClientClicked,
}) => {
const allClients = Object.values(clientMap);
const onlyOwner = ownerId && clientMap[ownerId] && allClients.length <= 1;

return (
<IonCard>
<IonCardHeader>
<IonCardTitle>Clients</IonCardTitle>
<IonCardSubtitle>Devices connected to this session</IonCardSubtitle>
</IonCardHeader>
<IonCardContent>
<div style={{ display: "flex", flexDirection: "row" }}>
{onlyOwner ? (
<p>You are the only client connected to this session.</p>
) : null}
{allClients.map((client) => (
<ClientCircle client={client}></ClientCircle>
))}
<IonButton onClick={addClientClicked}>Add Client</IonButton>
</div>
</IonCardContent>
</IonCard>
);
};

type ClientCircleProps = {
client: ServerTypes.Client;
};

const ClientCircle: React.FC<ClientCircleProps> = ({ client }) => {
return (
<div
style={{
minWidth: 32,
height: 32,
backgroundColor: "skyblue",
borderRadius: 32,
color: "white",
fontSize: 16,
}}
>
{client.id} : {client.name}
</div>
);
};
34 changes: 34 additions & 0 deletions src/feature/history/HistoryCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { IonCard, IonCardHeader, IonCardTitle, IonCardContent, IonItem } from "@ionic/react";
import React from "react";
import { SessionMessage } from "../session/SessionMessage";

export type HistoryCardProps = {
messages: SessionMessage[];
}

export const HistoryCard: React.FC<HistoryCardProps> = ({messages}) => {
return <IonCard>
<IonCardHeader>
<IonCardTitle>History</IonCardTitle>
</IonCardHeader>
<IonCardContent>
{ messages.length === 0 ? <NoMessages/> :
messages.map(msg => <Message key={msg.uuid ?? "" + Math.random()} 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>
}
2 changes: 1 addition & 1 deletion src/feature/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const HomePage: React.FC<HomePageProps> = ({
</IonButton>
</div>
<IntroSlides
style={{ height: "50%", maxWidth: "600px" }}
style={{ maxWidth: "600px" }}
></IntroSlides>
<IonModal isOpen={scanModalOpen} onDidDismiss={closeScannerModal}>
<ScanClientModal
Expand Down
3 changes: 3 additions & 0 deletions src/feature/intro-slides/slides.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.introSlider {
margin-bottom: 20px;
background-color: #222222;
border-radius: 16px;
color: white;
}

.slideDescription {
Expand Down
45 changes: 0 additions & 45 deletions src/feature/session-actions/OpenWebsiteModal.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions src/feature/session-actions/SessionActionModal.ts

This file was deleted.

107 changes: 0 additions & 107 deletions src/feature/session-actions/SessionActionsList.tsx

This file was deleted.

Loading

0 comments on commit 6255598

Please sign in to comment.