Skip to content

Commit

Permalink
feat: disable the plugin in collab mode
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewinci committed Mar 18, 2023
1 parent dd324da commit a461df1
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/components/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ const fontSizes = {
type TextProps = {
size: "xl" | "l" | "s" | "xs";
margin?: string;
textAlign?: "center";
};

export const Text = styled.p<TextProps>`
font-size: ${(props) => fontSizes[props.size]};
margin: ${(props) => props.margin ?? "0"};
text-align: ${(props) => props.textAlign ?? undefined};
`;

export const Input = styled.input`
Expand Down
6 changes: 3 additions & 3 deletions src/components/create-edit-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const CreateEditBar = (props: CreateEditBarProps) => {

const EditDrawing = (
<>
<Group margin="15px 0 0 0">
<Text size="s">{activeDrawingName}</Text>
</Group>
<Text textAlign="center" margin="15px 0 0 0" size="s">
{activeDrawingName}
</Text>
<Group margin="5px 0 20px 0">
<Button color="red" onClick={onClear}>
New
Expand Down
1 change: 0 additions & 1 deletion src/components/modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const Modal = (props: ModalProps) => {
>
Ignore
</Button>

</Group>
</ModalContainer>
</>
Expand Down
8 changes: 3 additions & 5 deletions src/components/title-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ export const TitleBar = () => {
src={floppy}
/>
</Group>
<Group margin="0" padding="0">
<Text size="xs" margin="0">
The Excalidraw drawings manager
</Text>
</Group>
<Text textAlign="center" size="xs" margin="0">
The Excalidraw drawings manager
</Text>
</>
);
};
9 changes: 8 additions & 1 deletion src/hooks/use-content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import { sendReceiveMessage } from "../browser";

export const useContentScript = () => {
const [isAlive, setIsAlive] = useState(false);
const [url, setUrl] = useState<string | null>(null);
const [activeDrawing, setActiveDrawing] = useState<{
name: string;
id: string;
} | null>(null);

const checkIsAlive = async (): Promise<void> => {
await sendReceiveMessage({ action: "ping" })
.then((response) => setIsAlive(response?.action === "pong"))
.then((response) => {
if (response?.action === "pong") {
setIsAlive(true);
setUrl(response.currentUrl);
}
})
.then(() => updateActiveDrawingName())
.catch((err) => {
console.debug(`Unable to communicate with the content-script`, err);
Expand Down Expand Up @@ -79,6 +85,7 @@ export const useContentScript = () => {
return {
isAlive,
activeDrawing,
url,
getDrawing,
setDrawing,
checkIsAlive,
Expand Down
40 changes: 33 additions & 7 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { GlobalStyles } from "./style";
const App = () => {
const { drawings, createDrawing, deleteDrawing, updateDrawing } =
useStorage();
const { isAlive, activeDrawing, getDrawing, setDrawing, checkIsAlive } =
const { isAlive, activeDrawing, url, getDrawing, setDrawing, checkIsAlive } =
useContentScript();
const { modalProps, closeModal, openModal } = useModal();
const [mode, setMode] = useState<"Create" | "Edit">("Create");
Expand Down Expand Up @@ -123,9 +123,10 @@ const App = () => {
title="Excalistore"
description={
<>
<Group>
<Text size="xs">{`This extensions only works on the Excalidraw website.`}</Text>
</Group>
<Text
textAlign="center"
size="xs"
>{`This extensions only works on the Excalidraw website.`}</Text>
<Group margin="25px 0 0 0">
<Button
color="green"
Expand All @@ -143,6 +144,31 @@ const App = () => {
);
}

console.debug("url", url);
console.debug("isAlive", isAlive);
if (url === null || url.substring(url.indexOf("#")).includes("#room=")) {
return (
<Modal
title="Excalistore"
description={
<div style={{ marginTop: "25px" }}>
<Text
textAlign="center"
size="xs"
>{`Live collaboration is not supported.`}</Text>
<Text
textAlign="center"
size="xs"
>{`Exit from the live collaboration to use Excalistore.`}</Text>
</div>
}
opened={true}
icons={"None"}
onSubmit={checkIsAlive}
/>
);
}

return (
<>
<TitleBar />
Expand All @@ -154,9 +180,9 @@ const App = () => {
onClear={onClearCanvas}
onSave={onSave}
/>
<Group margin="0px 0px 5px 0">
<Text size="l">Local drawings:</Text>
</Group>
<Text margin="0px 0px 5px 0" textAlign="center" size="l">
Local drawings:
</Text>
<div
style={{
maxHeight: "240px",
Expand Down
2 changes: 1 addition & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type PingRequest = { action: "ping" };
/**
* Reply to Ping from the script to pop-up
*/
type PingResponse = { action: "pong" };
type PingResponse = { action: "pong"; currentUrl: string };

/**
* Message from the pop-up to the script
Expand Down
2 changes: 1 addition & 1 deletion src/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ onMessageReceived<PopUpMessage, ScriptMessage>((request, sendResponse) => {
const reply = (message: ScriptMessage) => sendResponse(message);
switch (request.action) {
case "ping":
reply({ action: "pong" });
reply({ action: "pong", currentUrl: window.location.href });
break;
case "get-drawing":
reply({
Expand Down

0 comments on commit a461df1

Please sign in to comment.