Skip to content
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

feature: Enhance the bookmark textarea in the list layout #247

Merged
merged 5 commits into from
Jun 22, 2024
Merged
Changes from 2 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
25 changes: 23 additions & 2 deletions apps/web/components/dashboard/bookmarks/EditorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { Textarea } from "@/components/ui/textarea";
import { toast } from "@/components/ui/use-toast";
import BookmarkAlreadyExistsToast from "@/components/utils/BookmarkAlreadyExistsToast";
import { useClientConfig } from "@/lib/clientConfig";
import { useBookmarkLayoutSwitch } from "@/lib/userLocalSettings/bookmarksLayout";
import {
useBookmarkLayout,
useBookmarkLayoutSwitch,
} from "@/lib/userLocalSettings/bookmarksLayout";
import { cn } from "@/lib/utils";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
Expand Down Expand Up @@ -48,6 +51,7 @@ export default function EditorCard({ className }: { className?: string }) {
React.useState<MultiUrlImportState | null>(null);

const demoMode = !!useClientConfig().demoMode;
const bookmarkLayout = useBookmarkLayout();
const formSchema = z.object({
text: z.string(),
});
Expand Down Expand Up @@ -163,7 +167,10 @@ export default function EditorCard({ className }: { className?: string }) {
<Textarea
ref={inputRef}
disabled={isPending}
className="h-full w-full resize-none border-none text-lg focus-visible:ring-0"
className={cn(
"h-full w-full border-none text-lg focus-visible:ring-0",
{ "resize-none": bookmarkLayout !== "list" },
AhmadMuj marked this conversation as resolved.
Show resolved Hide resolved
)}
placeholder={
"Paste a link or an image, write a note or drag and drop an image in here ..."
}
Expand All @@ -181,6 +188,20 @@ export default function EditorCard({ className }: { className?: string }) {
}
handlePaste(e);
}}
onInput={(e: React.FormEvent<HTMLTextAreaElement>) => {
// Expand the textarea to a max of half the screen size in the list layout only
if (bookmarkLayout === "list") {
const target = e.target as HTMLTextAreaElement;
const maxHeight = window.innerHeight * 0.5;
target.style.height = "auto";

if (target.scrollHeight <= maxHeight) {
target.style.height = `${target.scrollHeight}px`;
} else {
target.style.height = `${maxHeight}px`;
}
}
}}
AhmadMuj marked this conversation as resolved.
Show resolved Hide resolved
{...textFieldProps}
/>
</FormControl>
Expand Down
Loading