Skip to content

Commit

Permalink
Fix up bug with channel creation, clean up some LPCSS
Browse files Browse the repository at this point in the history
  • Loading branch information
bubner committed Aug 17, 2023
1 parent 346e8a4 commit 074a6fa
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 87 deletions.
4 changes: 4 additions & 0 deletions src/Firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const db = getDatabase(app);
export let currentChannel = "main";

export function setCurrentChannel(channel: string): void {
const invalidChars = /[$#\[\]/.]/;
if (!channel || invalidChars.test(channel)) {
throw new Error("Invalid channel name!");
}
currentChannel = channel;
}

Expand Down
60 changes: 30 additions & 30 deletions src/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,38 +157,38 @@ function Chat() {
<Navbar />
<div className="chat">
<div className="menu">
{/* Menu element for changing channels */}
<Channels />
{/* Menu element for changing channels */}
<Channels />
</div>
<div className="messages">
{/* Allow space for Navbar to fit */}
<br /> <br /> <br /> <br /> <br />
{/* Load more button to support pagination */}
{messages && Object.keys(messages).length > paginationIndex * PAGINATION_LIMIT ? (
<button className="moreitems" onClick={() => updatePagination()} />
) : (
<>
<p className="top">
Welcome to the Bunyip Bellower! <br /> This is the start of the <b>{channel}</b>{" "}
channel.
</p>
<hr />
</>
)}
{/* Leading dummy for pagination support */}
<div id="paginationdummy" ref={pdummy}></div>
{/* Display all messages currently in Firebase */}
{messages &&
Object.keys(messages).length > 0 &&
Object.entries(messages)
.slice(paginationIndex * -PAGINATION_LIMIT)
.map(([muid, msg]) => <Message message={msg} key={muid} />)}
{/* Dummy element for fluid interface */}
<div id="dummy" ref={dummy}></div>
<br /> <br /> <br />
{/* Message bar with end-user options to add files and message */}
<MessageBar />
</div>
{/* Allow space for Navbar to fit */}
<br /> <br /> <br /> <br /> <br />
{/* Load more button to support pagination */}
{messages && Object.keys(messages).length > paginationIndex * PAGINATION_LIMIT ? (
<button className="moreitems" onClick={() => updatePagination()} />
) : (
<>
<p className="top">
Welcome to the Bunyip Bellower! <br /> This is the start of the <b>{channel}</b>{" "}
channel.
</p>
<hr />
</>
)}
{/* Leading dummy for pagination support */}
<div id="paginationdummy" ref={pdummy}></div>
{/* Display all messages currently in Firebase */}
{messages &&
Object.keys(messages).length > 0 &&
Object.entries(messages)
.slice(paginationIndex * -PAGINATION_LIMIT)
.map(([muid, msg]) => <Message message={msg} key={muid} />)}
{/* Dummy element for fluid interface */}
<div id="dummy" ref={dummy}></div>
<br /> <br /> <br />
{/* Message bar with end-user options to add files and message */}
<MessageBar />
</div>
</div>
</>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/chat/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ function Message(props: { message: MessageData; key: string }) {
<img
className="pfp"
src={message.photoURL}
onError={() => {
(document.getElementsByClassName("pfp")[0] as HTMLImageElement).src = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjg4IiBoZWlnaHQ9IjI4OCIgdmlld0JveD0iMCAwIDI4OCAyODgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIyODgiIGhlaWdodD0iMjg4IiBmaWxsPSIjRTlFOUU5Ii8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMjIyIDEwOUMyMjIgMTM5LjM2NiAyMDQuNjQ3IDE2NS42OCAxNzkuMzE3IDE3OC41NjVDMjIzLjk4MSAxODcuNzE4IDI2Mi40NDMgMjEzLjg4NiAyODcuNjMzIDI1MEgyODhWMjg4SDBWMjUwSDAuMzY3MTg4QzI1LjU1NzQgMjEzLjg4NiA2NC4wMTkzIDE4Ny43MTggMTA4LjY4MyAxNzguNTY1QzgzLjM1MjggMTY1LjY4IDY2IDEzOS4zNjYgNjYgMTA5QzY2IDY1LjkyMTkgMTAwLjkyMiAzMSAxNDQgMzFDMTg3LjA3OCAzMSAyMjIgNjUuOTIxOSAyMjIgMTA5WiIgZmlsbD0iIzAwMDAwMCIvPgo8L3N2Zz4K";
}}
alt={`Profile of ${message.displayName}`}
referrerPolicy="no-referrer"
/>
Expand Down
25 changes: 0 additions & 25 deletions src/css/Channels.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@
* Author: Lachlan Paul, 2023
*/

.chat {
display: grid;
grid-template-columns: 30% 70%;
grid-template-rows: 100%;
grid-auto-columns: 1fr;
gap: 0px 0px;
grid-auto-flow: row;
grid-template-areas:
"menu messages";
}

.messages {
grid-area: messages;
}

.menu {
grid-area: menu;
position: fixed;
background: rgb(0, 52, 14);
height: 100%;
width: 20%;
z-index: 1;
overflow: auto;
}

.buttons {
height: 50px;
width: 90%;
Expand Down
50 changes: 37 additions & 13 deletions src/css/Chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,51 @@
* Author: Lucas Bubner, 2023
*/

.chat {
.chat {
display: grid;
grid-template-columns: 30% 70%;
grid-template-columns: 22% 70%;
grid-template-rows: 100%;
grid-auto-columns: 1fr;
gap: 0px 0px;
grid-auto-flow: row;
grid-template-areas:
"menu messages";
}

.menu {
grid-template-areas: "menu messages";
}

.menu {
grid-area: menu;
}

.messages {
grid-area: messages;
position: fixed;
background: rgb(0, 52, 14);
height: calc(100% - 132px);
border-radius: 12px;
width: 20%;
top: 120px;
left: 15px;
z-index: 1;
overflow: auto;
}

@media screen and (max-width: 950px) {
.menu {
display: none;
}
.chat {
grid-template-columns: 100%;
grid-template-rows: 100%;
grid-template-areas: "messages";
}
.msginput {
width: calc(100vw - 28px);
}
.message {
width: 100%;
}
}

.messages {
grid-area: messages;
position: relative;
right: 13%;
}

.moreitems {
transition: background-color 0.5s;
color: inherit;
Expand Down
3 changes: 3 additions & 0 deletions src/css/Message.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
.message {
animation: gen 0.5s;
border-radius: 15px;

/* what on earth is this */
width: 111%;

transition: background-color 0.3s;
display: grid;
margin: 0;
Expand Down
3 changes: 1 addition & 2 deletions src/css/MessageBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
display: flex;
position: fixed;
bottom: 0;
width: 100%;
}

.msginput {
Expand All @@ -17,7 +16,7 @@
background-color: rgb(0, 90, 31);
height: auto;
flex: 1;
width: calc(71vw - 28px);
width: 70vw;
border: 0;
outline: none;
}
Expand Down
2 changes: 1 addition & 1 deletion src/css/Navbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
grid-template-areas:
"img"
"name";

position: fixed;
margin: 8px;
width: calc(100vw - 20px);
Expand All @@ -21,6 +20,7 @@
height: 100px;
border-radius: 12px;
z-index: 2;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.5);
}

.navbar-brand {
Expand Down
42 changes: 26 additions & 16 deletions src/layout/Channels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,35 @@ function Channels() {

return (
<div className="menu">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<center>
<form onSubmit={(e) => { e.preventDefault(); setCurrentChannel((document.getElementById("channelName") as HTMLInputElement).value); (document.getElementById("channelName") as HTMLInputElement).value = ""; }}>
<form onSubmit={(e) => {
e.preventDefault();
try {
setCurrentChannel((document.getElementById("channelName") as HTMLInputElement).value);
} catch (e) {
alert(e);
}
(document.getElementById("channelName") as HTMLInputElement).value = "";
}}>
<input type="text" id="channelName" placeholder="Enter a channel name" />
</form>
{channels.map((channel) => (
<Fragment key={channel}>
<button className="buttons" onClick={() => setCurrentChannel(channel)}>
{channel}
</button>
<button onClick={() => { if (window.confirm(`Confirm removal of ${channel}?`)) removeChannel(channel);}} className="oblbutton">
obliterate {channel}
</button>
</Fragment>
))}
<button className="buttons" onClick={() => setCurrentChannel("main")}>
main
</button>
<hr />
{channels.map((channel) => {
if (channel === "main") return;
return (
<Fragment key={channel}>
<button className="buttons" onClick={() => setCurrentChannel(channel)}>
{channel}
</button>
<button onClick={() => { if (window.confirm(`Confirm removal of ${channel}?`)) removeChannel(channel);}} className="oblbutton">
obliterate {channel}
</button>
</Fragment>
);
})}
</center>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions src/layout/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ function Navbar() {
<img
className="navbar-brand"
src={auth.currentUser?.photoURL?.toString()}
onError={() => {
(document.getElementsByClassName("pfp")[0] as HTMLImageElement).src = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjg4IiBoZWlnaHQ9IjI4OCIgdmlld0JveD0iMCAwIDI4OCAyODgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIyODgiIGhlaWdodD0iMjg4IiBmaWxsPSIjRTlFOUU5Ii8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMjIyIDEwOUMyMjIgMTM5LjM2NiAyMDQuNjQ3IDE2NS42OCAxNzkuMzE3IDE3OC41NjVDMjIzLjk4MSAxODcuNzE4IDI2Mi40NDMgMjEzLjg4NiAyODcuNjMzIDI1MEgyODhWMjg4SDBWMjUwSDAuMzY3MTg4QzI1LjU1NzQgMjEzLjg4NiA2NC4wMTkzIDE4Ny43MTggMTA4LjY4MyAxNzguNTY1QzgzLjM1MjggMTY1LjY4IDY2IDEzOS4zNjYgNjYgMTA5QzY2IDY1LjkyMTkgMTAwLjkyMiAzMSAxNDQgMzFDMTg3LjA3OCAzMSAyMjIgNjUuOTIxOSAyMjIgMTA5WiIgZmlsbD0iIzAwMDAwMCIvPgo8L3N2Zz4K";
}}
referrerPolicy="no-referrer"
alt={`Profile of ${auth.currentUser?.displayName}`}
/>
Expand Down

0 comments on commit 074a6fa

Please sign in to comment.