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

[Bug] Fix save action on empty card #243

Merged
merged 4 commits into from
Jun 22, 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
11 changes: 7 additions & 4 deletions apps/web/components/dashboard/bookmarks/EditorCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useBookmarkLayout,
useBookmarkLayoutSwitch,
} from "@/lib/userLocalSettings/bookmarksLayout";
import { cn } from "@/lib/utils";
import { cn, getOS } from "@/lib/utils";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm } from "react-hook-form";
import { z } from "zod";
Expand Down Expand Up @@ -123,6 +123,7 @@ export default function EditorCard({ className }: { className?: string }) {

const onSubmit: SubmitHandler<z.infer<typeof formSchema>> = (data) => {
const text = data.text.trim();
if (!text.length) return;
try {
tryToImportUrls(text);
} catch (e) {
Expand Down Expand Up @@ -162,12 +163,14 @@ export default function EditorCard({ className }: { className?: string }) {
}
};

const OS = getOS();

return (
<Form {...form}>
<form
className={cn(
className,
"flex flex-col gap-2 rounded-xl bg-card p-4",
"relative flex flex-col gap-2 rounded-xl bg-card p-4",
cardHeight,
)}
onSubmit={form.handleSubmit(onSubmit, onError)}
Expand All @@ -187,7 +190,7 @@ export default function EditorCard({ className }: { className?: string }) {
ref={inputRef}
disabled={isPending}
className={cn(
"h-full w-full border-none text-lg focus-visible:ring-0",
"h-full w-full border-none p-0 text-lg focus-visible:ring-0",
{ "resize-none": bookmarkLayout !== "list" },
)}
placeholder={
Expand Down Expand Up @@ -216,7 +219,7 @@ export default function EditorCard({ className }: { className?: string }) {
{form.formState.dirtyFields.text
? demoMode
? "Submissions are disabled"
: "Press ⌘ + Enter to Save"
: `Save (${OS === "macos" ? "⌘" : "Ctrl"} + Enter)`
mdsaban marked this conversation as resolved.
Show resolved Hide resolved
: "Save"}
</ActionButton>

Expand Down
6 changes: 5 additions & 1 deletion apps/web/components/ui/info-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export default function InfoTooltip({
<Tooltip>
<TooltipTrigger asChild>
{variant === "tip" ? (
<Info className={cn("cursor-pointer", className)} size={size} />
<Info
color="#494949"
className={cn("cursor-pointer", className)}
size={size}
/>
) : (
<HelpCircle className={cn("cursor-pointer", className)} size={size} />
)}
Expand Down
24 changes: 24 additions & 0 deletions apps/web/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,27 @@ import { twMerge } from "tailwind-merge";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
}

export type OS = "macos" | "ios" | "windows" | "android" | "linux" | null;

export function getOS() {
if (typeof window === "undefined") return;
const userAgent = window.navigator.userAgent.toLowerCase();
const macosPlatforms = /(macintosh|macintel|macppc|mac68k|macos)/i;
const windowsPlatforms = /(win32|win64|windows|wince)/i;
const iosPlatforms = /(iphone|ipad|ipod)/i;
let os: OS = null;

if (macosPlatforms.test(userAgent)) {
os = "macos";
} else if (iosPlatforms.test(userAgent)) {
os = "ios";
} else if (windowsPlatforms.test(userAgent)) {
os = "windows";
} else if (/android/.test(userAgent)) {
os = "android";
} else if (!os && /linux/.test(userAgent)) {
os = "linux";
}
return os;
}
Loading