Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

MOC-276: chat history #178

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/mocksi-lite-next/src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ chrome.runtime.onMessageExternal.addListener(
}
} else {
const tab = await getCurrentTab();
if (!tab.id) {
if (!tab?.id) {
sendResponse({ message: request.message, status: "no-tab" });
console.log("No active tab found, could not send message");
return true;
Expand Down
75 changes: 21 additions & 54 deletions apps/mocksi-lite-next/src/pages/content/mocksi-extension.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,25 +85,8 @@ function getIframeStyles(message: string): Partial<CSSStyleDeclaration> {
display: "block",
height: "150px",
inset: "0px 10px auto auto",
width: "400px",
};
case "CHAT":
return {
bottom: "0px",
display: "block",
height: "500px",
left: "calc(50%-150px)",
right: "auto",
top: "auto",
width: "300px",
};
case "DEMO_ACTIVE":
return {
display: "block",
height: "250px",
inset: "88% 42% 0px",
width: "200px",
};
case "EDITING":
case "INIT":
case "LIST":
Expand Down Expand Up @@ -172,12 +155,6 @@ chrome.runtime.onMessage.addListener((request) => {
(async () => {
let data = null;

if (request.message === "CHAT_NEW_MESSAGE") {
sendResponse({
message: request.message,
status: "ok",
});
}
// reactor
if (request.message === "EDITING" || request.message === "PLAY") {
for (const mod of request.data.edits) {
Expand All @@ -202,31 +179,10 @@ chrome.runtime.onMessage.addListener((request) => {
reactor.detach();
}

// Resize iframe with the new styles
if (iframeRef.current) {
if (request.data?.iframe) {
// v1 iframe size / position pattern
const styles = getIframeSizePosition(request.data.iframe);
Object.assign(iframeRef.current.style, styles);
} else {
// v0+
const styles = getIframeStyles(request.message);
Object.assign(iframeRef.current.style, styles);
}
}

if (request.message === "CHAT") {
sendResponse({
data: reactor.exportDOM(),
message: request.message,
status: "ok",
});
}

// chat actions
if (request.message === "CHAT") {
reactor.attach(document, getHighlighter());
}

if (request.message === "CHAT_MESSAGE") {
data = reactor.exportDOM();
}
Expand All @@ -237,6 +193,18 @@ chrome.runtime.onMessage.addListener((request) => {
);
}

// Resize iframe with the new styles
if (iframeRef.current) {
if (request.data?.iframe) {
// v1 iframe size / position pattern
const styles = getIframeSizePosition(request.data.iframe);
Object.assign(iframeRef.current.style, styles);
} else {
// v0+
const styles = getIframeStyles(request.message);
Object.assign(iframeRef.current.style, styles);
}
}
sendResponse({
data,
message: request.message,
Expand All @@ -253,24 +221,23 @@ chrome.runtime.onMessage.addListener((request) => {
{ReactDOM.createPortal(
<>
<iframe
loading="lazy"
ref={iframeRef}
seamless={true}
src={`${import.meta.env.VITE_NEST_APP}/extension`}
style={{
backgroundColor: "transparent",
border: "none",
bottom: "10px",
boxShadow: "none",
colorScheme: "light",
position: "fixed",
display: "block",
height: "600px",
width: "500px",
top: "auto",
right: "10px",
bottom: "10px",
left: "auto",
boxShadow: "none",
position: "fixed",
right: "10px",
top: "auto",
width: "500px",
zIndex: 99998,
border: "none",
backgroundColor: "transparent",
}}
/>
</>,
Expand Down
Loading