Skip to content

feat: add support for insiders channel to "VS Code Desktop" button #7730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make fmt
  • Loading branch information
matifali committed May 31, 2023
commit 661152ad2b3d58707ded636d68c5523186f21e70
18 changes: 16 additions & 2 deletions site/src/components/Icons/VSCodeInsidersIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ import SvgIcon, { SvgIconProps } from "@mui/material/SvgIcon"

export const VSCodeInsidersIcon = (props: SvgIconProps) => (
<SvgIcon {...props} viewBox="0 0 256 256">
<svg width="256" height="256" viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg">
<mask id="mask0" mask-type="alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="256" height="256">
<svg
width="256"
height="256"
viewBox="0 0 256 256"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<mask
id="mask0"
mask-type="alpha"
maskUnits="userSpaceOnUse"
x="0"
y="0"
width="256"
height="256"
>
<path
d="M176.049 250.669C180.838 255.459 188.13 256.7 194.234 253.764L246.94 228.419C252.478 225.755 256 220.154 256 214.008V42.1479C256 36.0025 252.478 30.4008 246.94 27.7374L194.234 2.39089C188.13 -0.544416 180.838 0.696607 176.049 5.48572C181.95 -0.41506 192.039 3.76413 192.039 12.1091V244.046C192.039 252.391 181.95 256.57 176.049 250.669Z"
fill="white"
Expand Down
76 changes: 37 additions & 39 deletions site/src/components/VSCodeDesktopButton/VSCodeDesktopButton.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { FC, PropsWithChildren, useState, useEffect } from "react";
import { getApiKey } from "api/api";
import { VSCodeIcon } from "components/Icons/VSCodeIcon";
import { VSCodeInsidersIcon } from "components/Icons/VSCodeInsidersIcon";
import { PrimaryAgentButton } from "components/Resources/AgentButton";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import React, { FC, PropsWithChildren, useState, useEffect } from "react"
import { getApiKey } from "api/api"
import { VSCodeIcon } from "components/Icons/VSCodeIcon"
import { VSCodeInsidersIcon } from "components/Icons/VSCodeInsidersIcon"
import { PrimaryAgentButton } from "components/Resources/AgentButton"
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"

export interface VSCodeDesktopButtonProps {
userName: string;
workspaceName: string;
agentName?: string;
folderPath?: string;
userName: string
workspaceName: string
agentName?: string
folderPath?: string
}

enum VSCodeVariant {
Expand All @@ -18,69 +18,69 @@ enum VSCodeVariant {
}

const getSelectedVariantFromLocalStorage = (): VSCodeVariant | null => {
const storedVariant = localStorage.getItem("selectedVariant");
const storedVariant = localStorage.getItem("selectedVariant")
if (
storedVariant &&
Object.values(VSCodeVariant).includes(storedVariant as VSCodeVariant)
) {
return storedVariant as VSCodeVariant;
return storedVariant as VSCodeVariant
}
return null;
};
return null
}

export const VSCodeDesktopButton: FC<
PropsWithChildren<VSCodeDesktopButtonProps>
> = ({ userName, workspaceName, agentName, folderPath }) => {
const [loading, setLoading] = useState(false);
const [loading, setLoading] = useState(false)
const [selectedVariant, setSelectedVariant] = useState<VSCodeVariant | null>(
getSelectedVariantFromLocalStorage()
);
const [dropdownOpen, setDropdownOpen] = useState(false);
getSelectedVariantFromLocalStorage(),
)
const [dropdownOpen, setDropdownOpen] = useState(false)

useEffect(() => {
if (selectedVariant) {
localStorage.setItem("selectedVariant", selectedVariant);
localStorage.setItem("selectedVariant", selectedVariant)
} else {
localStorage.removeItem("selectedVariant");
localStorage.removeItem("selectedVariant")
}
}, [selectedVariant]);
}, [selectedVariant])

const handleButtonClick = () => {
setLoading(true);
setLoading(true)
getApiKey()
.then(({ key }) => {
const query = new URLSearchParams({
owner: userName,
workspace: workspaceName,
url: location.origin,
token: key,
});
})
if (agentName) {
query.set("agent", agentName);
query.set("agent", agentName)
}
if (folderPath) {
query.set("folder", folderPath);
query.set("folder", folderPath)
}

const vscodeCommand =
selectedVariant === VSCodeVariant.VSCode
? "vscode://"
: "vscode-insiders://";
: "vscode-insiders://"

location.href = `${vscodeCommand}coder.coder-remote/open?${query.toString()}`;
location.href = `${vscodeCommand}coder.coder-remote/open?${query.toString()}`
})
.catch((ex) => {
console.error(ex);
console.error(ex)
})
.finally(() => {
setLoading(false);
});
};
setLoading(false)
})
}

const handleVariantChange = (variant: VSCodeVariant) => {
setSelectedVariant(variant);
setDropdownOpen(false);
};
setSelectedVariant(variant)
setDropdownOpen(false)
}

return (
<div style={{ position: "relative", display: "inline-flex" }}>
Expand All @@ -99,9 +99,7 @@ export const VSCodeDesktopButton: FC<
? "VS Code Desktop"
: "VS Code Insiders"}
</PrimaryAgentButton>
<PrimaryAgentButton
onClick={() => setDropdownOpen(!dropdownOpen)}
>
<PrimaryAgentButton onClick={() => setDropdownOpen(!dropdownOpen)}>
<KeyboardArrowDownIcon
style={{
transition: "transform 0.3s ease-in-out",
Expand Down Expand Up @@ -134,5 +132,5 @@ export const VSCodeDesktopButton: FC<
</div>
)}
</div>
);
};
)
}