⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
feat(extension): improved ux by moving the options page into the main view
daniel31x136f47ba7ea820
diff --git a/apps/extension/src/@/components/NotConfigured.tsx b/apps/extension/src/@/components/NotConfigured.tsxindex c3c83046..0da78796 100644--- a/apps/extension/src/@/components/NotConfigured.tsx+++ b/apps/extension/src/@/components/NotConfigured.tsx@@ -1,12 +1,14 @@import { FC } from 'react';-import { openOptions } from '../lib/utils.ts';import { Button } from './ui/Button.tsx';-const NotConfigured: FC<{ open: boolean }> = ({ open }) => {+const NotConfigured: FC<{ open: boolean; onConfigure: () => void }> = ({+ open,+ onConfigure,+}) => {if (!open) return null;return (- <div className="fixed top-0 bottom-0 left-0 right-0 inset-0 bg-white z-10">+ <div className="fixed top-0 bottom-0 left-0 right-0 inset-0 bg-background z-10"><div className="container flex flex-col gap-3 justify-center items-center h-full max-w-lg mx-auto"><imgsrc="./128.png"@@ -15,19 +17,12 @@ const NotConfigured: FC<{ open: boolean }> = ({ open }) => {className="rounded"alt="Linkwarden Logo"/>- <h1- className="font-medium text-lg text-zinc-700"- style={{ fontSize: '1.65rem' }}- >+ <h1 className="font-medium text-lg" style={{ fontSize: '1.65rem' }}>Initial Setup</h1><div className="flex justify-center items-center">- <Button- onClick={() => openOptions()}- className="w-40"- variant="outline"- >+ <Button onClick={onConfigure} className="w-40" variant="outline">Configure</Button></div>diff --git a/apps/extension/src/@/components/OptionsForm.tsx b/apps/extension/src/@/components/OptionsForm.tsxindex 415b1f2a..3c811c63 100644--- a/apps/extension/src/@/components/OptionsForm.tsx+++ b/apps/extension/src/@/components/OptionsForm.tsx@@ -19,7 +19,7 @@ import {import { Input } from "./ui/Input.tsx";import { Button } from "./ui/Button.tsx";import { useMutation } from "@tanstack/react-query";-import { useEffect } from "react";+import { useEffect, useState } from "react";import {clearConfig,getConfig,@@ -39,7 +39,19 @@ import {SelectValue,} from "./ui/Select.tsx";-const OptionsForm = () => {+interface OptionsFormProps {+ onSaved?: () => void;+ onCleared?: () => void;+}++const displayInstance = (baseUrl: string) =>+ baseUrl.replace(/^https?:\/\//, "").replace(/\/$/, "");++const OptionsForm = ({ onSaved, onCleared }: OptionsFormProps) => {+ const [signedInTo, setSignedInTo] = useState<string | undefined | null>(+ undefined+ );+const form = useForm<optionsFormInput, unknown, optionsFormValues>({resolver: zodResolver(optionsFormSchema),defaultValues: {@@ -53,7 +65,7 @@ const OptionsForm = () => {},});- const { mutate: onReset, isPending: resetLoading } = useMutation({+ const { mutate: onSignOut, isPending: signOutLoading } = useMutation({mutationFn: async () => {const configured = await isConfigured();@@ -67,7 +79,7 @@ const OptionsForm = () => {toast({title: "Error",description:- "Either you didn't configure the extension or there was an error while trying to log out. Please try again.",+ "Either you didn't configure the extension or there was an error while trying to sign out. Please try again.",variant: "destructive",});return;@@ -85,6 +97,8 @@ const OptionsForm = () => {});await clearConfig();await clearBookmarksMetadata();+ setSignedInTo(null);+ onCleared?.();return;},});@@ -164,12 +178,15 @@ const OptionsForm = () => {: values.data.response.token,});+ setSignedInTo(values.baseUrl);+toast({title: "Saved",- description:- "Your settings have been saved, you can now close this tab.",+ description: "Your settings have been saved.",variant: "default",});++ onSaved?.();},});@@ -179,6 +196,9 @@ const OptionsForm = () => {if (configured) {const cachedOptions = await getConfig();form.reset(cachedOptions);+ setSignedInTo(cachedOptions.baseUrl);+ } else {+ setSignedInTo(null);}})();}, [form]);@@ -186,12 +206,37 @@ const OptionsForm = () => {const { handleSubmit, control, watch } = form;const method = watch("method");+ if (signedInTo === undefined) return null;++ if (signedInTo) {+ return (+ <div className="px-2 space-y-4">+ <p className="text-sm">+ Signed in to{" "}+ <span className="font-medium break-all">+ {displayInstance(signedInTo)}+ </span>+ </p>+ <Button+ type="button"+ variant="outline"+ className="w-full"+ onClick={() => onSignOut()}+ disabled={signOutLoading}+ >+ Sign Out+ </Button>+ <Toaster />+ </div>+ );+ }+return (<div><Form {...form}><formonSubmit={handleSubmit((data) => onSubmit(data))}- className="space-y-3 p-2"+ className="space-y-3 px-2"><FormFieldcontrol={control}@@ -346,19 +391,7 @@ const OptionsForm = () => {/>*/}- <div className="flex justify-between">- <div>- {/* eslint-disable-next-line @typescript-eslint/ban-ts-comment */}- {/*@ts-ignore*/}- <Button- type="button"- className="mb-2"- onClick={() => onReset()}- disabled={resetLoading}- >- Reset- </Button>- </div>+ <div className="flex justify-end pb-2"><Button disabled={isPending} type="submit">Save</Button>diff --git a/apps/extension/src/@/lib/utils.ts b/apps/extension/src/@/lib/utils.tsindex 71e73408..dce2307f 100644--- a/apps/extension/src/@/lib/utils.ts+++ b/apps/extension/src/@/lib/utils.ts@@ -58,10 +58,6 @@ export async function setStorageItem(key: string, value: string) {}}-export function openOptions() {- getBrowser().runtime.openOptionsPage();-}-export function isSafari(): boolean {try {return /^safari-web-extension:/.test(getBrowser().runtime.getURL(''));diff --git a/apps/extension/src/pages/Popup/App.tsx b/apps/extension/src/pages/Popup/App.tsxindex f92f0cb8..9f1d9033 100644--- a/apps/extension/src/pages/Popup/App.tsx+++ b/apps/extension/src/pages/Popup/App.tsx@@ -1,28 +1,33 @@-import Container from '../../@/components/Container.tsx';-import WholeContainer from '../../@/components/WholeContainer.tsx';-import BookmarkForm from '../../@/components/BookmarkForm.tsx';-import { openOptions } from '../../@/lib/utils.ts';-import { useEffect, useState } from 'react';-import { getConfig, isConfigured } from '../../@/lib/config.ts';-import NotConfigured from '../../@/components/NotConfigured.tsx';-import { ModeToggle } from '../../@/components/ModeToggle.tsx';-import { Button } from '@/@/components/ui/Button.tsx';-import { Settings } from 'lucide-react';+import Container from "../../@/components/Container.tsx";+import WholeContainer from "../../@/components/WholeContainer.tsx";+import BookmarkForm from "../../@/components/BookmarkForm.tsx";+import OptionsForm from "../../@/components/OptionsForm.tsx";+import { useCallback, useEffect, useState } from "react";+import { getConfig, isConfigured } from "../../@/lib/config.ts";+import NotConfigured from "../../@/components/NotConfigured.tsx";+import { ModeToggle } from "../../@/components/ModeToggle.tsx";+import { Button } from "@/@/components/ui/Button.tsx";+import { Settings, X } from "lucide-react";function App() {const [isAllConfigured, setIsAllConfigured] = useState<boolean>();const [baseUrl, setBaseUrl] = useState<string>();+ const [showSettings, setShowSettings] = useState(false);- useEffect(() => {- (async () => {- const cachedOptions = await isConfigured();- const cachedConfig = await getConfig();+ const refreshConfig = useCallback(async () => {+ const cachedOptions = await isConfigured();+ const cachedConfig = await getConfig();++ setBaseUrl(cachedConfig.baseUrl);+ setIsAllConfigured(cachedOptions);- setBaseUrl(cachedConfig.baseUrl);- setIsAllConfigured(cachedOptions);- })();+ return cachedOptions;}, []);+ useEffect(() => {+ refreshConfig();+ }, [refreshConfig]);+return (<WholeContainer><Container>@@ -43,7 +48,9 @@ function App() {alt="Linkwarden Logo"/></a>- <h1 className="text-lg">Add Link</h1>+ <h1 className="text-lg">+ {showSettings ? "Settings" : "Add Link"}+ </h1></div><div className="flex items-center justify-center space-x-2"><ModeToggle />@@ -51,14 +58,39 @@ function App() {variant="ghost"size="icon"className="ring-0 focus:ring-0 outline-none focus:outline-none ring-offset-0 focus:ring-offset-0 focus-visible:ring-offset-0 focus-visible:ring-0 focus-visible:outline-none"- onClick={openOptions}+ onClick={() => setShowSettings((prevState) => !prevState)}>- <Settings className="h-[1.2rem] w-[1.2rem] transition-colors" />+ {showSettings ? (+ <X className="h-[1.2rem] w-[1.2rem] transition-colors" />+ ) : (+ <Settings className="h-[1.2rem] w-[1.2rem] transition-colors" />+ )}+ <span className="sr-only">+ {showSettings ? "Close settings" : "Open settings"}+ </span></Button></div></div>- <BookmarkForm />- <NotConfigured open={!isAllConfigured} />++ {showSettings ? (+ <div className="max-h-[500px] overflow-y-auto mt-1">+ <OptionsForm+ onSaved={async () => {+ const configured = await refreshConfig();+ if (configured) setShowSettings(false);+ }}+ onCleared={refreshConfig}+ />+ </div>+ ) : (+ <>+ <BookmarkForm />+ <NotConfigured+ open={isAllConfigured === false}+ onConfigure={() => setShowSettings(true)}+ />+ </>+ )}</Container></WholeContainer>);