mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-09-11 22:51:05 +00:00
Merge pull request #285 from supermemoryai/extension/drag-and-dismiss
feat: Drag and Dismiss extension features
This commit is contained in:
commit
e706488813
1 changed files with 123 additions and 19 deletions
|
|
@ -57,6 +57,8 @@ export default function ContentApp({
|
|||
|
||||
const [userNotLoggedIn, setUserNotLoggedIn] = useState(false);
|
||||
|
||||
const [position, setPosition] = useState({ x: 0, y: 80 });
|
||||
|
||||
const showLoginToast = async () => {
|
||||
setUserNotLoggedIn(true);
|
||||
|
||||
|
|
@ -169,7 +171,7 @@ export default function ContentApp({
|
|||
useEffect(() => {
|
||||
document.addEventListener("mousemove", (e) => {
|
||||
const percentageX = (e.clientX / window.innerWidth) * 100;
|
||||
const percentageY = (e.clientY / window.innerHeight) * 100;
|
||||
const percentageY = ((e.clientY + position.y) / window.innerHeight) * 100;
|
||||
|
||||
if (percentageX > 75 && percentageY > 75) {
|
||||
setHover(true);
|
||||
|
|
@ -218,7 +220,7 @@ export default function ContentApp({
|
|||
document.removeEventListener("mousemove", () => {});
|
||||
document.removeEventListener("keydown", handleKeyDown, true);
|
||||
};
|
||||
}, []);
|
||||
}, [position.y]);
|
||||
|
||||
const getSpaces = async () => {
|
||||
const response = await fetch(`${BACKEND_URL}/api/spaces`, {
|
||||
|
|
@ -324,6 +326,29 @@ export default function ContentApp({
|
|||
return null;
|
||||
}
|
||||
|
||||
const svgDragCursor = `
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="white"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
width="20"
|
||||
height="20"
|
||||
>
|
||||
<path d="M5 9l-3 3 3 3M9 5l3-3 3 3M15 19l-3 3-3-3M19 9l3 3-3 3M2 12h20M12 2v20" />
|
||||
</svg>
|
||||
`;
|
||||
|
||||
const encodedSvgCursor = encodeURIComponent(svgDragCursor);
|
||||
|
||||
const dismissExtension = () => {
|
||||
const extension = document.querySelector("#supermemory-extension-host");
|
||||
extension?.remove();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex justify-end items-end min-h-screen h-full w-full">
|
||||
<Toaster />
|
||||
|
|
@ -334,24 +359,52 @@ export default function ContentApp({
|
|||
>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger onClick={async () => await getSpaces()} asChild>
|
||||
<PopoverTrigger
|
||||
className={`${hover || isPopoverOpen ? "opacity-100" : "opacity-75 pointer-events-none translate-x-3/4"} focus-within:translate-x-0 focus-visible:translate-x-0 size-12 hover:bg-black p-2 rounded-l-2xl transition bg-secondary border-2 border-border opacity-0 absolute flex bottom-20 items-center text-lg`}
|
||||
>
|
||||
<svg
|
||||
className={`w-full h-full size-8 ${loading && "animate-spin"}`}
|
||||
width={24}
|
||||
height={24}
|
||||
viewBox="0 0 42 42"
|
||||
fill="currentColor"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
<TooltipTrigger
|
||||
onClick={async () => await getSpaces()}
|
||||
asChild
|
||||
style={{
|
||||
position: "absolute",
|
||||
right: "10px",
|
||||
bottom: `${position.y}px`,
|
||||
}}
|
||||
>
|
||||
<div className="flex">
|
||||
{hover && (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="10"
|
||||
height="10"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
className="hover:cursor-pointer"
|
||||
onClick={dismissExtension}
|
||||
>
|
||||
<line x1="18" y1="6" x2="6" y2="18"></line>
|
||||
<line x1="6" y1="6" x2="18" y2="18"></line>
|
||||
</svg>
|
||||
)}
|
||||
<PopoverTrigger
|
||||
className={`${hover || isPopoverOpen ? "opacity-100" : "opacity-75 pointer-events-none translate-x-3/4"} focus-within:translate-x-0 focus-visible:translate-x-0 size-12 hover:bg-black p-1 rounded-l-2xl transition bg-secondary border-2 border-border opacity-0 flex last:items-center text-lg right-3 `}
|
||||
>
|
||||
<path
|
||||
d="M19.0357 8C20.5531 8 21 9.27461 21 10.8438V16.3281H23.5536V14.2212C23.5536 13.1976 23.9468 12.216 24.6467 11.4922L25.0529 11.0721C24.9729 10.8772 24.9286 10.6627 24.9286 10.4375C24.9286 9.54004 25.6321 8.8125 26.5 8.8125C27.3679 8.8125 28.0714 9.54004 28.0714 10.4375C28.0714 11.335 27.3679 12.0625 26.5 12.0625C26.2822 12.0625 26.0748 12.0167 25.8863 11.9339L25.4801 12.354C25.0012 12.8492 24.7321 13.5209 24.7321 14.2212V16.3281H28.9714C29.2045 15.7326 29.7691 15.3125 30.4286 15.3125C31.2964 15.3125 32 16.04 32 16.9375C32 17.835 31.2964 18.5625 30.4286 18.5625C29.7691 18.5625 29.2045 18.1424 28.9714 17.5469H21V21.2031H25.0428C25.2759 20.6076 25.8405 20.1875 26.5 20.1875C27.3679 20.1875 28.0714 20.915 28.0714 21.8125C28.0714 22.71 27.3679 23.4375 26.5 23.4375C25.8405 23.4375 25.2759 23.0174 25.0428 22.4219H21V26.0781H24.4125C25.4023 26.0781 26.3516 26.4847 27.0515 27.2085L29.0292 29.2536C29.2177 29.1708 29.4251 29.125 29.6429 29.125C30.5107 29.125 31.2143 29.8525 31.2143 30.75C31.2143 31.6475 30.5107 32.375 29.6429 32.375C28.775 32.375 28.0714 31.6475 28.0714 30.75C28.0714 30.5248 28.1157 30.3103 28.1958 30.1154L26.2181 28.0703C25.7392 27.5751 25.0897 27.2969 24.4125 27.2969H21V31.1562C21 32.7254 20.5531 34 19.0357 34C17.6165 34 16.4478 32.8879 16.3004 31.4559C16.0451 31.527 15.775 31.5625 15.5 31.5625C13.7665 31.5625 12.3571 30.1051 12.3571 28.3125C12.3571 27.9367 12.421 27.5711 12.5339 27.2359C11.0509 26.657 10 25.1742 10 23.4375C10 21.8176 10.9183 20.416 12.2491 19.766C11.8219 19.2125 11.5714 18.5117 11.5714 17.75C11.5714 16.191 12.6321 14.891 14.0464 14.5711C13.9679 14.2918 13.9286 13.9922 13.9286 13.6875C13.9286 12.1691 14.9402 10.8895 16.3004 10.534C16.4478 9.11211 17.6165 8 19.0357 8Z"
|
||||
fill={loading ? "gray" : "#fff"}
|
||||
/>
|
||||
</svg>
|
||||
</PopoverTrigger>
|
||||
<svg
|
||||
className={`w-full h-full size-8 ${loading && "animate-spin"}`}
|
||||
width={24}
|
||||
height={24}
|
||||
viewBox="0 0 42 42"
|
||||
fill="currentColor"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<path
|
||||
d="M19.0357 8C20.5531 8 21 9.27461 21 10.8438V16.3281H23.5536V14.2212C23.5536 13.1976 23.9468 12.216 24.6467 11.4922L25.0529 11.0721C24.9729 10.8772 24.9286 10.6627 24.9286 10.4375C24.9286 9.54004 25.6321 8.8125 26.5 8.8125C27.3679 8.8125 28.0714 9.54004 28.0714 10.4375C28.0714 11.335 27.3679 12.0625 26.5 12.0625C26.2822 12.0625 26.0748 12.0167 25.8863 11.9339L25.4801 12.354C25.0012 12.8492 24.7321 13.5209 24.7321 14.2212V16.3281H28.9714C29.2045 15.7326 29.7691 15.3125 30.4286 15.3125C31.2964 15.3125 32 16.04 32 16.9375C32 17.835 31.2964 18.5625 30.4286 18.5625C29.7691 18.5625 29.2045 18.1424 28.9714 17.5469H21V21.2031H25.0428C25.2759 20.6076 25.8405 20.1875 26.5 20.1875C27.3679 20.1875 28.0714 20.915 28.0714 21.8125C28.0714 22.71 27.3679 23.4375 26.5 23.4375C25.8405 23.4375 25.2759 23.0174 25.0428 22.4219H21V26.0781H24.4125C25.4023 26.0781 26.3516 26.4847 27.0515 27.2085L29.0292 29.2536C29.2177 29.1708 29.4251 29.125 29.6429 29.125C30.5107 29.125 31.2143 29.8525 31.2143 30.75C31.2143 31.6475 30.5107 32.375 29.6429 32.375C28.775 32.375 28.0714 31.6475 28.0714 30.75C28.0714 30.5248 28.1157 30.3103 28.1958 30.1154L26.2181 28.0703C25.7392 27.5751 25.0897 27.2969 24.4125 27.2969H21V31.1562C21 32.7254 20.5531 34 19.0357 34C17.6165 34 16.4478 32.8879 16.3004 31.4559C16.0451 31.527 15.775 31.5625 15.5 31.5625C13.7665 31.5625 12.3571 30.1051 12.3571 28.3125C12.3571 27.9367 12.421 27.5711 12.5339 27.2359C11.0509 26.657 10 25.1742 10 23.4375C10 21.8176 10.9183 20.416 12.2491 19.766C11.8219 19.2125 11.5714 18.5117 11.5714 17.75C11.5714 16.191 12.6321 14.891 14.0464 14.5711C13.9679 14.2918 13.9286 13.9922 13.9286 13.6875C13.9286 12.1691 14.9402 10.8895 16.3004 10.534C16.4478 9.11211 17.6165 8 19.0357 8Z"
|
||||
fill={loading ? "gray" : "#fff"}
|
||||
/>
|
||||
</svg>
|
||||
</PopoverTrigger>
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="left">
|
||||
{userNotLoggedIn ? (
|
||||
|
|
@ -434,6 +487,57 @@ export default function ContentApp({
|
|||
)}
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
<div
|
||||
className={`${hover ? "opacity-100" : "pointer-events-none translate-x-3/4"} focus-within:translate-x-0 focus-visible:translate-x-0 h-12 w-5 hover:bg-yellow-300 transition pl-2 bg-secondary border-2 border-border opacity-0 flex items-center text-lg`}
|
||||
style={{
|
||||
cursor: `url("data:image/svg+xml,${encodedSvgCursor}"), auto`,
|
||||
position: "absolute",
|
||||
bottom: `${position.y}px`,
|
||||
right: "0px",
|
||||
}}
|
||||
onDrag={(e) => {
|
||||
e.preventDefault();
|
||||
const viewportHeight = window.innerHeight;
|
||||
const elementHeight = 48; // Adjust this value based on your element's height
|
||||
|
||||
let newY = viewportHeight - e.clientY;
|
||||
|
||||
// Ensure the element stays within the viewport
|
||||
newY = Math.max(0, Math.min(newY, viewportHeight - elementHeight));
|
||||
|
||||
setPosition((prevPosition) => ({ ...prevPosition, y: newY }));
|
||||
}}
|
||||
onDragEnd={(e) => {
|
||||
e.preventDefault();
|
||||
console.log("drag end");
|
||||
console.log(e.clientY);
|
||||
const viewportHeight = window.innerHeight;
|
||||
const elementHeight = 48; // Adjust this value based on your element's height
|
||||
|
||||
let newY = viewportHeight - e.clientY;
|
||||
|
||||
// Ensure the element stays within the viewport
|
||||
newY = Math.max(0, Math.min(newY, viewportHeight - elementHeight));
|
||||
console.log("mouse end " + newY);
|
||||
|
||||
setPosition((prevPosition) => ({ ...prevPosition, y: newY }));
|
||||
}}
|
||||
draggable
|
||||
>
|
||||
<svg
|
||||
className="w-6 h-6 text-white opacity-50"
|
||||
viewBox="0 0 64 64"
|
||||
fill="currentColor"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<circle cx="16" cy="1" r="5"></circle>
|
||||
<circle cx="16" cy="27" r="5"></circle>
|
||||
<circle cx="16" cy="50" r="5"></circle>
|
||||
<circle cx="40" cy="1" r="5"></circle>
|
||||
<circle cx="40" cy="27" r="5"></circle>
|
||||
<circle cx="40" cy="50" r="5"></circle>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
{(window.location.host === "twitter.com" ||
|
||||
window.location.host === "x.com") && (
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue