From 04572a8e5081b1e4871e273cde9dbaaa44c52fe0 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 13 Mar 2024 21:43:44 +0000 Subject: structure: Create apps dir and copy tooling dir from t3-turbo repo --- apps/browser-extension/.eslintrc.cjs | 3 + apps/browser-extension/.gitignore | 24 ++ apps/browser-extension/index.html | 13 + apps/browser-extension/manifest.json | 19 ++ apps/browser-extension/package.json | 55 +++++ apps/browser-extension/postcss.config.js | 6 + apps/browser-extension/public/logo-128.png | Bin 0 -> 2362 bytes apps/browser-extension/public/logo-16.png | Bin 0 -> 287 bytes apps/browser-extension/public/logo-48.png | Bin 0 -> 780 bytes apps/browser-extension/public/logo.png | Bin 0 -> 412 bytes apps/browser-extension/src/BookmarkDeletedPage.tsx | 3 + apps/browser-extension/src/BookmarkSavedPage.tsx | 62 +++++ apps/browser-extension/src/Layout.tsx | 51 ++++ apps/browser-extension/src/Logo.tsx | 10 + apps/browser-extension/src/NotConfiguredPage.tsx | 47 ++++ apps/browser-extension/src/OptionsPage.tsx | 60 +++++ apps/browser-extension/src/SavePage.tsx | 60 +++++ apps/browser-extension/src/SignInPage.tsx | 89 +++++++ apps/browser-extension/src/Spinner.tsx | 18 ++ apps/browser-extension/src/assets/react.svg | 1 + apps/browser-extension/src/index.css | 72 ++++++ apps/browser-extension/src/main.tsx | 40 ++++ apps/browser-extension/src/utils/providers.tsx | 46 ++++ apps/browser-extension/src/utils/settings.ts | 22 ++ apps/browser-extension/src/utils/trpc.ts | 4 + apps/browser-extension/src/vite-env.d.ts | 1 + apps/browser-extension/tailwind.config.js | 10 + apps/browser-extension/tsconfig.json | 25 ++ apps/browser-extension/tsconfig.node.json | 11 + apps/browser-extension/vite.config.ts | 9 + apps/mobile/.eslintrc.js | 4 + apps/mobile/.gitignore | 39 +++ apps/mobile/.npmrc | 1 + apps/mobile/app.json | 57 +++++ apps/mobile/app/+not-found.tsx | 6 + apps/mobile/app/_layout.tsx | 53 +++++ apps/mobile/app/dashboard/(tabs)/_layout.tsx | 38 +++ apps/mobile/app/dashboard/(tabs)/index.tsx | 31 +++ apps/mobile/app/dashboard/(tabs)/lists.tsx | 67 ++++++ apps/mobile/app/dashboard/(tabs)/search.tsx | 35 +++ apps/mobile/app/dashboard/(tabs)/settings.tsx | 41 ++++ apps/mobile/app/dashboard/_layout.tsx | 38 +++ apps/mobile/app/dashboard/add-link.tsx | 57 +++++ apps/mobile/app/dashboard/add-note.tsx | 53 +++++ apps/mobile/app/dashboard/archive.tsx | 11 + apps/mobile/app/dashboard/favourites.tsx | 11 + apps/mobile/app/dashboard/lists/[slug].tsx | 31 +++ apps/mobile/app/error.tsx | 9 + apps/mobile/app/index.tsx | 20 ++ apps/mobile/app/sharing.tsx | 99 ++++++++ apps/mobile/app/signin.tsx | 101 ++++++++ apps/mobile/assets/blur.jpeg | Bin 0 -> 178818 bytes apps/mobile/assets/icon.png | Bin 0 -> 2362 bytes apps/mobile/assets/splash.png | Bin 0 -> 117993 bytes apps/mobile/babel.config.js | 9 + apps/mobile/components/Logo.tsx | 11 + apps/mobile/components/bookmarks/BookmarkCard.tsx | 243 +++++++++++++++++++ apps/mobile/components/bookmarks/BookmarkList.tsx | 61 +++++ apps/mobile/components/ui/ActionButton.tsx | 21 ++ apps/mobile/components/ui/Button.tsx | 81 +++++++ apps/mobile/components/ui/Divider.tsx | 28 +++ apps/mobile/components/ui/FullPageSpinner.tsx | 9 + apps/mobile/components/ui/Input.tsx | 28 +++ apps/mobile/components/ui/Skeleton.tsx | 38 +++ apps/mobile/components/ui/Toast.tsx | 183 ++++++++++++++ apps/mobile/eas.json | 19 ++ apps/mobile/globals.css | 80 +++++++ apps/mobile/lib/last-shared-intent.ts | 15 ++ apps/mobile/lib/providers.tsx | 54 +++++ apps/mobile/lib/session.ts | 20 ++ apps/mobile/lib/settings.ts | 29 +++ apps/mobile/lib/storage-state.ts | 51 ++++ apps/mobile/lib/trpc.ts | 4 + apps/mobile/lib/utils.ts | 6 + apps/mobile/metro.config.js | 58 +++++ apps/mobile/nativewind-env.d.ts | 1 + apps/mobile/package.json | 71 ++++++ apps/mobile/tailwind.config.ts | 73 ++++++ apps/mobile/tsconfig.json | 14 ++ apps/web/README.md | 36 +++ apps/web/app/api/auth/[...nextauth]/route.tsx | 3 + apps/web/app/api/trpc/[trpc]/route.ts | 36 +++ apps/web/app/dashboard/admin/page.tsx | 203 ++++++++++++++++ apps/web/app/dashboard/archive/page.tsx | 9 + apps/web/app/dashboard/bookmarks/layout.tsx | 23 ++ apps/web/app/dashboard/bookmarks/loading.tsx | 11 + apps/web/app/dashboard/bookmarks/page.tsx | 5 + apps/web/app/dashboard/error.tsx | 9 + apps/web/app/dashboard/favourites/page.tsx | 14 ++ apps/web/app/dashboard/layout.tsx | 24 ++ apps/web/app/dashboard/lists/[listId]/page.tsx | 44 ++++ apps/web/app/dashboard/lists/page.tsx | 14 ++ apps/web/app/dashboard/not-found.tsx | 7 + .../app/dashboard/preview/[bookmarkId]/page.tsx | 14 ++ apps/web/app/dashboard/search/page.tsx | 41 ++++ apps/web/app/dashboard/settings/page.tsx | 9 + apps/web/app/dashboard/tags/[tagName]/page.tsx | 55 +++++ apps/web/app/dashboard/tags/page.tsx | 56 +++++ apps/web/app/favicon.ico | Bin 0 -> 15406 bytes apps/web/app/globals.css | 76 ++++++ apps/web/app/layout.tsx | 51 ++++ apps/web/app/page.tsx | 12 + apps/web/app/signin/page.tsx | 25 ++ apps/web/components.json | 17 ++ .../dashboard/bookmarks/AddLinkButton.tsx | 102 ++++++++ .../dashboard/bookmarks/AddToListModal.tsx | 168 +++++++++++++ .../dashboard/bookmarks/BookmarkCardSkeleton.tsx | 30 +++ .../dashboard/bookmarks/BookmarkOptions.tsx | 185 +++++++++++++++ .../dashboard/bookmarks/BookmarkPreview.tsx | 101 ++++++++ .../dashboard/bookmarks/BookmarkedTextEditor.tsx | 109 +++++++++ .../dashboard/bookmarks/BookmarkedTextViewer.tsx | 20 ++ .../components/dashboard/bookmarks/Bookmarks.tsx | 32 +++ .../dashboard/bookmarks/BookmarksGrid.tsx | 64 +++++ .../components/dashboard/bookmarks/LinkCard.tsx | 114 +++++++++ .../web/components/dashboard/bookmarks/TagList.tsx | 39 +++ .../components/dashboard/bookmarks/TagModal.tsx | 207 ++++++++++++++++ .../components/dashboard/bookmarks/TextCard.tsx | 94 ++++++++ apps/web/components/dashboard/bookmarks/TopNav.tsx | 43 ++++ .../components/dashboard/lists/AllListsView.tsx | 66 ++++++ .../dashboard/lists/DeleteListButton.tsx | 77 ++++++ apps/web/components/dashboard/lists/ListView.tsx | 25 ++ .../components/dashboard/search/SearchInput.tsx | 25 ++ .../components/dashboard/settings/AddApiKey.tsx | 167 +++++++++++++ .../dashboard/settings/ApiKeySettings.tsx | 49 ++++ .../components/dashboard/settings/DeleteApiKey.tsx | 74 ++++++ apps/web/components/dashboard/sidebar/AllLists.tsx | 60 +++++ .../components/dashboard/sidebar/ModileSidebar.tsx | 24 ++ .../dashboard/sidebar/ModileSidebarItem.tsx | 27 +++ .../components/dashboard/sidebar/NewListModal.tsx | 170 +++++++++++++ apps/web/components/dashboard/sidebar/Sidebar.tsx | 66 ++++++ .../components/dashboard/sidebar/SidebarItem.tsx | 33 +++ .../dashboard/sidebar/SidebarProfileOptions.tsx | 35 +++ apps/web/components/signin/CredentialsForm.tsx | 222 +++++++++++++++++ apps/web/components/signin/SignInForm.tsx | 37 +++ .../web/components/signin/SignInProviderButton.tsx | 21 ++ apps/web/components/ui/action-button.tsx | 25 ++ apps/web/components/ui/back-button.tsx | 9 + apps/web/components/ui/badge.tsx | 36 +++ apps/web/components/ui/button.tsx | 56 +++++ apps/web/components/ui/card.tsx | 86 +++++++ apps/web/components/ui/dialog.tsx | 122 ++++++++++ apps/web/components/ui/dropdown-menu.tsx | 200 ++++++++++++++++ apps/web/components/ui/form.tsx | 177 ++++++++++++++ apps/web/components/ui/imageCard.tsx | 70 ++++++ apps/web/components/ui/input.tsx | 25 ++ apps/web/components/ui/label.tsx | 26 ++ apps/web/components/ui/popover.tsx | 31 +++ apps/web/components/ui/scroll-area.tsx | 48 ++++ apps/web/components/ui/select.tsx | 160 +++++++++++++ apps/web/components/ui/separator.tsx | 31 +++ apps/web/components/ui/skeleton.tsx | 15 ++ apps/web/components/ui/spinner.tsx | 20 ++ apps/web/components/ui/table.tsx | 117 +++++++++ apps/web/components/ui/tabs.tsx | 55 +++++ apps/web/components/ui/textarea.tsx | 24 ++ apps/web/components/ui/toast.tsx | 127 ++++++++++ apps/web/components/ui/toaster.tsx | 35 +++ apps/web/components/ui/use-toast.ts | 189 +++++++++++++++ apps/web/lib/bookmarkUtils.tsx | 22 ++ apps/web/lib/hooks/bookmark-search.ts | 73 ++++++ apps/web/lib/providers.tsx | 75 ++++++ apps/web/lib/trpc.tsx | 5 + apps/web/lib/utils.ts | 6 + apps/web/next.config.mjs | 53 +++++ apps/web/package.json | 89 +++++++ apps/web/postcss.config.cjs | 6 + apps/web/public/blur.avif | Bin 0 -> 52746 bytes apps/web/public/icons/logo-128.png | Bin 0 -> 2362 bytes apps/web/public/icons/logo-16.png | Bin 0 -> 287 bytes apps/web/public/icons/logo-48.png | Bin 0 -> 780 bytes apps/web/public/manifest.json | 25 ++ apps/web/server/api/client.ts | 16 ++ apps/web/server/auth.ts | 96 ++++++++ apps/web/tailwind.config.ts | 89 +++++++ apps/web/tsconfig.json | 17 ++ apps/web/vitest.config.ts | 14 ++ apps/workers/crawlerWorker.ts | 201 ++++++++++++++++ apps/workers/index.ts | 16 ++ apps/workers/openaiWorker.ts | 263 +++++++++++++++++++++ apps/workers/package.json | 56 +++++ apps/workers/searchWorker.ts | 116 +++++++++ apps/workers/tsconfig.json | 10 + 182 files changed, 8982 insertions(+) create mode 100644 apps/browser-extension/.eslintrc.cjs create mode 100644 apps/browser-extension/.gitignore create mode 100644 apps/browser-extension/index.html create mode 100644 apps/browser-extension/manifest.json create mode 100644 apps/browser-extension/package.json create mode 100644 apps/browser-extension/postcss.config.js create mode 100644 apps/browser-extension/public/logo-128.png create mode 100644 apps/browser-extension/public/logo-16.png create mode 100644 apps/browser-extension/public/logo-48.png create mode 100644 apps/browser-extension/public/logo.png create mode 100644 apps/browser-extension/src/BookmarkDeletedPage.tsx create mode 100644 apps/browser-extension/src/BookmarkSavedPage.tsx create mode 100644 apps/browser-extension/src/Layout.tsx create mode 100644 apps/browser-extension/src/Logo.tsx create mode 100644 apps/browser-extension/src/NotConfiguredPage.tsx create mode 100644 apps/browser-extension/src/OptionsPage.tsx create mode 100644 apps/browser-extension/src/SavePage.tsx create mode 100644 apps/browser-extension/src/SignInPage.tsx create mode 100644 apps/browser-extension/src/Spinner.tsx create mode 100644 apps/browser-extension/src/assets/react.svg create mode 100644 apps/browser-extension/src/index.css create mode 100644 apps/browser-extension/src/main.tsx create mode 100644 apps/browser-extension/src/utils/providers.tsx create mode 100644 apps/browser-extension/src/utils/settings.ts create mode 100644 apps/browser-extension/src/utils/trpc.ts create mode 100644 apps/browser-extension/src/vite-env.d.ts create mode 100644 apps/browser-extension/tailwind.config.js create mode 100644 apps/browser-extension/tsconfig.json create mode 100644 apps/browser-extension/tsconfig.node.json create mode 100644 apps/browser-extension/vite.config.ts create mode 100644 apps/mobile/.eslintrc.js create mode 100644 apps/mobile/.gitignore create mode 100644 apps/mobile/.npmrc create mode 100644 apps/mobile/app.json create mode 100644 apps/mobile/app/+not-found.tsx create mode 100644 apps/mobile/app/_layout.tsx create mode 100644 apps/mobile/app/dashboard/(tabs)/_layout.tsx create mode 100644 apps/mobile/app/dashboard/(tabs)/index.tsx create mode 100644 apps/mobile/app/dashboard/(tabs)/lists.tsx create mode 100644 apps/mobile/app/dashboard/(tabs)/search.tsx create mode 100644 apps/mobile/app/dashboard/(tabs)/settings.tsx create mode 100644 apps/mobile/app/dashboard/_layout.tsx create mode 100644 apps/mobile/app/dashboard/add-link.tsx create mode 100644 apps/mobile/app/dashboard/add-note.tsx create mode 100644 apps/mobile/app/dashboard/archive.tsx create mode 100644 apps/mobile/app/dashboard/favourites.tsx create mode 100644 apps/mobile/app/dashboard/lists/[slug].tsx create mode 100644 apps/mobile/app/error.tsx create mode 100644 apps/mobile/app/index.tsx create mode 100644 apps/mobile/app/sharing.tsx create mode 100644 apps/mobile/app/signin.tsx create mode 100644 apps/mobile/assets/blur.jpeg create mode 100644 apps/mobile/assets/icon.png create mode 100644 apps/mobile/assets/splash.png create mode 100644 apps/mobile/babel.config.js create mode 100644 apps/mobile/components/Logo.tsx create mode 100644 apps/mobile/components/bookmarks/BookmarkCard.tsx create mode 100644 apps/mobile/components/bookmarks/BookmarkList.tsx create mode 100644 apps/mobile/components/ui/ActionButton.tsx create mode 100644 apps/mobile/components/ui/Button.tsx create mode 100644 apps/mobile/components/ui/Divider.tsx create mode 100644 apps/mobile/components/ui/FullPageSpinner.tsx create mode 100644 apps/mobile/components/ui/Input.tsx create mode 100644 apps/mobile/components/ui/Skeleton.tsx create mode 100644 apps/mobile/components/ui/Toast.tsx create mode 100644 apps/mobile/eas.json create mode 100644 apps/mobile/globals.css create mode 100644 apps/mobile/lib/last-shared-intent.ts create mode 100644 apps/mobile/lib/providers.tsx create mode 100644 apps/mobile/lib/session.ts create mode 100644 apps/mobile/lib/settings.ts create mode 100644 apps/mobile/lib/storage-state.ts create mode 100644 apps/mobile/lib/trpc.ts create mode 100644 apps/mobile/lib/utils.ts create mode 100644 apps/mobile/metro.config.js create mode 100644 apps/mobile/nativewind-env.d.ts create mode 100644 apps/mobile/package.json create mode 100644 apps/mobile/tailwind.config.ts create mode 100644 apps/mobile/tsconfig.json create mode 100644 apps/web/README.md create mode 100644 apps/web/app/api/auth/[...nextauth]/route.tsx create mode 100644 apps/web/app/api/trpc/[trpc]/route.ts create mode 100644 apps/web/app/dashboard/admin/page.tsx create mode 100644 apps/web/app/dashboard/archive/page.tsx create mode 100644 apps/web/app/dashboard/bookmarks/layout.tsx create mode 100644 apps/web/app/dashboard/bookmarks/loading.tsx create mode 100644 apps/web/app/dashboard/bookmarks/page.tsx create mode 100644 apps/web/app/dashboard/error.tsx create mode 100644 apps/web/app/dashboard/favourites/page.tsx create mode 100644 apps/web/app/dashboard/layout.tsx create mode 100644 apps/web/app/dashboard/lists/[listId]/page.tsx create mode 100644 apps/web/app/dashboard/lists/page.tsx create mode 100644 apps/web/app/dashboard/not-found.tsx create mode 100644 apps/web/app/dashboard/preview/[bookmarkId]/page.tsx create mode 100644 apps/web/app/dashboard/search/page.tsx create mode 100644 apps/web/app/dashboard/settings/page.tsx create mode 100644 apps/web/app/dashboard/tags/[tagName]/page.tsx create mode 100644 apps/web/app/dashboard/tags/page.tsx create mode 100644 apps/web/app/favicon.ico create mode 100644 apps/web/app/globals.css create mode 100644 apps/web/app/layout.tsx create mode 100644 apps/web/app/page.tsx create mode 100644 apps/web/app/signin/page.tsx create mode 100644 apps/web/components.json create mode 100644 apps/web/components/dashboard/bookmarks/AddLinkButton.tsx create mode 100644 apps/web/components/dashboard/bookmarks/AddToListModal.tsx create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkCardSkeleton.tsx create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkedTextEditor.tsx create mode 100644 apps/web/components/dashboard/bookmarks/BookmarkedTextViewer.tsx create mode 100644 apps/web/components/dashboard/bookmarks/Bookmarks.tsx create mode 100644 apps/web/components/dashboard/bookmarks/BookmarksGrid.tsx create mode 100644 apps/web/components/dashboard/bookmarks/LinkCard.tsx create mode 100644 apps/web/components/dashboard/bookmarks/TagList.tsx create mode 100644 apps/web/components/dashboard/bookmarks/TagModal.tsx create mode 100644 apps/web/components/dashboard/bookmarks/TextCard.tsx create mode 100644 apps/web/components/dashboard/bookmarks/TopNav.tsx create mode 100644 apps/web/components/dashboard/lists/AllListsView.tsx create mode 100644 apps/web/components/dashboard/lists/DeleteListButton.tsx create mode 100644 apps/web/components/dashboard/lists/ListView.tsx create mode 100644 apps/web/components/dashboard/search/SearchInput.tsx create mode 100644 apps/web/components/dashboard/settings/AddApiKey.tsx create mode 100644 apps/web/components/dashboard/settings/ApiKeySettings.tsx create mode 100644 apps/web/components/dashboard/settings/DeleteApiKey.tsx create mode 100644 apps/web/components/dashboard/sidebar/AllLists.tsx create mode 100644 apps/web/components/dashboard/sidebar/ModileSidebar.tsx create mode 100644 apps/web/components/dashboard/sidebar/ModileSidebarItem.tsx create mode 100644 apps/web/components/dashboard/sidebar/NewListModal.tsx create mode 100644 apps/web/components/dashboard/sidebar/Sidebar.tsx create mode 100644 apps/web/components/dashboard/sidebar/SidebarItem.tsx create mode 100644 apps/web/components/dashboard/sidebar/SidebarProfileOptions.tsx create mode 100644 apps/web/components/signin/CredentialsForm.tsx create mode 100644 apps/web/components/signin/SignInForm.tsx create mode 100644 apps/web/components/signin/SignInProviderButton.tsx create mode 100644 apps/web/components/ui/action-button.tsx create mode 100644 apps/web/components/ui/back-button.tsx create mode 100644 apps/web/components/ui/badge.tsx create mode 100644 apps/web/components/ui/button.tsx create mode 100644 apps/web/components/ui/card.tsx create mode 100644 apps/web/components/ui/dialog.tsx create mode 100644 apps/web/components/ui/dropdown-menu.tsx create mode 100644 apps/web/components/ui/form.tsx create mode 100644 apps/web/components/ui/imageCard.tsx create mode 100644 apps/web/components/ui/input.tsx create mode 100644 apps/web/components/ui/label.tsx create mode 100644 apps/web/components/ui/popover.tsx create mode 100644 apps/web/components/ui/scroll-area.tsx create mode 100644 apps/web/components/ui/select.tsx create mode 100644 apps/web/components/ui/separator.tsx create mode 100644 apps/web/components/ui/skeleton.tsx create mode 100644 apps/web/components/ui/spinner.tsx create mode 100644 apps/web/components/ui/table.tsx create mode 100644 apps/web/components/ui/tabs.tsx create mode 100644 apps/web/components/ui/textarea.tsx create mode 100644 apps/web/components/ui/toast.tsx create mode 100644 apps/web/components/ui/toaster.tsx create mode 100644 apps/web/components/ui/use-toast.ts create mode 100644 apps/web/lib/bookmarkUtils.tsx create mode 100644 apps/web/lib/hooks/bookmark-search.ts create mode 100644 apps/web/lib/providers.tsx create mode 100644 apps/web/lib/trpc.tsx create mode 100644 apps/web/lib/utils.ts create mode 100644 apps/web/next.config.mjs create mode 100644 apps/web/package.json create mode 100644 apps/web/postcss.config.cjs create mode 100644 apps/web/public/blur.avif create mode 100644 apps/web/public/icons/logo-128.png create mode 100644 apps/web/public/icons/logo-16.png create mode 100644 apps/web/public/icons/logo-48.png create mode 100644 apps/web/public/manifest.json create mode 100644 apps/web/server/api/client.ts create mode 100644 apps/web/server/auth.ts create mode 100644 apps/web/tailwind.config.ts create mode 100644 apps/web/tsconfig.json create mode 100644 apps/web/vitest.config.ts create mode 100644 apps/workers/crawlerWorker.ts create mode 100644 apps/workers/index.ts create mode 100644 apps/workers/openaiWorker.ts create mode 100644 apps/workers/package.json create mode 100644 apps/workers/searchWorker.ts create mode 100644 apps/workers/tsconfig.json (limited to 'apps') diff --git a/apps/browser-extension/.eslintrc.cjs b/apps/browser-extension/.eslintrc.cjs new file mode 100644 index 00000000..450106a4 --- /dev/null +++ b/apps/browser-extension/.eslintrc.cjs @@ -0,0 +1,3 @@ +module.exports = { + ignorePatterns: ["dist/"], +}; diff --git a/apps/browser-extension/.gitignore b/apps/browser-extension/.gitignore new file mode 100644 index 00000000..a547bf36 --- /dev/null +++ b/apps/browser-extension/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/apps/browser-extension/index.html b/apps/browser-extension/index.html new file mode 100644 index 00000000..e4b78eae --- /dev/null +++ b/apps/browser-extension/index.html @@ -0,0 +1,13 @@ + + + + + + + Vite + React + TS + + +
+ + + diff --git a/apps/browser-extension/manifest.json b/apps/browser-extension/manifest.json new file mode 100644 index 00000000..d3a27e7b --- /dev/null +++ b/apps/browser-extension/manifest.json @@ -0,0 +1,19 @@ +{ + "manifest_version": 3, + "name": "Hoarder", + "description": "An extension to bookmark links to hoarder.app", + "version": "1.1", + "icons": { + "16": "public/logo-16.png", + "48": "public/logo-48.png", + "128": "public/logo-128.png" + }, + "action": { + "default_popup": "index.html" + }, + "options_ui": { + "page": "index.html#options", + "open_in_tab": false + }, + "permissions": ["storage", "tabs"] +} diff --git a/apps/browser-extension/package.json b/apps/browser-extension/package.json new file mode 100644 index 00000000..21cffb50 --- /dev/null +++ b/apps/browser-extension/package.json @@ -0,0 +1,55 @@ +{ + "name": "browser-extension", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "preview": "vite preview", + "typecheck": "tsc --noEmit" + }, + "dependencies": { + "@hoarder/trpc": "0.1.0", + "@tanstack/react-query": "^5.24.8", + "@trpc/client": "11.0.0-next-beta.308", + "@trpc/next": "11.0.0-next-beta.308", + "@trpc/react-query": "11.0.0-next-beta.308", + "@trpc/server": "11.0.0-next-beta.308", + "lucide-react": "^0.330.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "react-router-dom": "^6.22.0", + "use-chrome-storage": "^1.2.2", + "superjson": "^2.2.1", + "zod": "^3.22.4" + }, + "devDependencies": { + "@hoarder/eslint-config": "workspace:^0.2.0", + "@hoarder/prettier-config": "workspace:^0.1.0", + "@hoarder/tailwind-config": "workspace:^0.1.0", + "@hoarder/tsconfig": "workspace:^0.1.0", + "@crxjs/vite-plugin": "^1.0.14", + "@types/react": "^18.2.55", + "@types/react-dom": "^18.2.19", + "@types/chrome": "^0.0.260", + "@vitejs/plugin-react-swc": "^3.5.0", + "autoprefixer": "^10.4.17", + "eslint": "^8.57.0", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.4.5", + "postcss": "^8.4.35", + "tailwindcss": "^3.4.1", + "typescript": "^5.3.3", + "vite": "^5.1.0" + }, + "eslintConfig": { + "root": true, + "extends": [ + "@hoarder/eslint-config/base", + "@hoarder/eslint-config/react" + ] + }, + "prettier": "@hoarder/prettier-config" +} diff --git a/apps/browser-extension/postcss.config.js b/apps/browser-extension/postcss.config.js new file mode 100644 index 00000000..2aa7205d --- /dev/null +++ b/apps/browser-extension/postcss.config.js @@ -0,0 +1,6 @@ +export default { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +}; diff --git a/apps/browser-extension/public/logo-128.png b/apps/browser-extension/public/logo-128.png new file mode 100644 index 00000000..71ead90c Binary files /dev/null and b/apps/browser-extension/public/logo-128.png differ diff --git a/apps/browser-extension/public/logo-16.png b/apps/browser-extension/public/logo-16.png new file mode 100644 index 00000000..dd864d44 Binary files /dev/null and b/apps/browser-extension/public/logo-16.png differ diff --git a/apps/browser-extension/public/logo-48.png b/apps/browser-extension/public/logo-48.png new file mode 100644 index 00000000..7ba1cd49 Binary files /dev/null and b/apps/browser-extension/public/logo-48.png differ diff --git a/apps/browser-extension/public/logo.png b/apps/browser-extension/public/logo.png new file mode 100644 index 00000000..ebe0a6a3 Binary files /dev/null and b/apps/browser-extension/public/logo.png differ diff --git a/apps/browser-extension/src/BookmarkDeletedPage.tsx b/apps/browser-extension/src/BookmarkDeletedPage.tsx new file mode 100644 index 00000000..23e1d9da --- /dev/null +++ b/apps/browser-extension/src/BookmarkDeletedPage.tsx @@ -0,0 +1,3 @@ +export default function BookmarkDeletedPage() { + return

Bookmark Deleted!

; +} diff --git a/apps/browser-extension/src/BookmarkSavedPage.tsx b/apps/browser-extension/src/BookmarkSavedPage.tsx new file mode 100644 index 00000000..f25a83ba --- /dev/null +++ b/apps/browser-extension/src/BookmarkSavedPage.tsx @@ -0,0 +1,62 @@ +import { Link, useNavigate, useParams } from "react-router-dom"; +import { api } from "./utils/trpc"; +import usePluginSettings from "./utils/settings"; +import { ArrowUpRightFromSquare, Trash } from "lucide-react"; +import Spinner from "./Spinner"; +import { useState } from "react"; + +export default function BookmarkSavedPage() { + const { bookmarkId } = useParams(); + const navigate = useNavigate(); + const [error, setError] = useState(""); + + const { mutate: deleteBookmark, isPending } = + api.bookmarks.deleteBookmark.useMutation({ + onSuccess: () => { + navigate("/bookmarkdeleted"); + }, + onError: (e) => { + setError(e.message); + }, + }); + + const { settings } = usePluginSettings(); + + if (!bookmarkId) { + return
NOT FOUND
; + } + + return ( +
+ {error &&

{error}

} +
+

Bookmarked!

+
+ + +

Open

+ + +
+
+
+ ); +} diff --git a/apps/browser-extension/src/Layout.tsx b/apps/browser-extension/src/Layout.tsx new file mode 100644 index 00000000..f8279a18 --- /dev/null +++ b/apps/browser-extension/src/Layout.tsx @@ -0,0 +1,51 @@ +import { Outlet } from "react-router-dom"; +import { Home, RefreshCw, Settings, X } from "lucide-react"; +import { useNavigate } from "react-router-dom"; +import usePluginSettings from "./utils/settings"; + +export default function Layout() { + const navigate = useNavigate(); + const { settings, isPending: isInit } = usePluginSettings(); + if (!isInit) { + return
Loading ...
; + } + + if (!settings.apiKey || !settings.address) { + navigate("/notconfigured"); + return; + } + + return ( +
+
+ +
+
+
+
+ + + Bookmarks + +
+
+ {process.env.NODE_ENV == "development" && ( + + )} + + +
+
+
+ ); +} diff --git a/apps/browser-extension/src/Logo.tsx b/apps/browser-extension/src/Logo.tsx new file mode 100644 index 00000000..6b29e68c --- /dev/null +++ b/apps/browser-extension/src/Logo.tsx @@ -0,0 +1,10 @@ +import { PackageOpen } from "lucide-react"; + +export default function Logo() { + return ( + + +

Hoarder

+
+ ); +} diff --git a/apps/browser-extension/src/NotConfiguredPage.tsx b/apps/browser-extension/src/NotConfiguredPage.tsx new file mode 100644 index 00000000..fc5c8f47 --- /dev/null +++ b/apps/browser-extension/src/NotConfiguredPage.tsx @@ -0,0 +1,47 @@ +import { useEffect, useState } from "react"; +import { useNavigate } from "react-router-dom"; +import usePluginSettings from "./utils/settings"; +import Logo from "./Logo"; + +export default function NotConfiguredPage() { + const navigate = useNavigate(); + + const { settings, setSettings } = usePluginSettings(); + + const [error, setError] = useState(""); + const [serverAddress, setServerAddress] = useState(settings.address); + useEffect(() => { + setServerAddress(settings.address); + }, [settings.address]); + + const onSave = () => { + if (serverAddress == "") { + setError("Server address is required"); + return; + } + setSettings((s) => ({ ...s, address: serverAddress })); + navigate("/signin"); + }; + + return ( +
+ + + To use the plugin, you need to configure it first. + +

{error}

+
+ + setServerAddress(e.target.value)} + /> +
+ +
+ ); +} diff --git a/apps/browser-extension/src/OptionsPage.tsx b/apps/browser-extension/src/OptionsPage.tsx new file mode 100644 index 00000000..6407b3cc --- /dev/null +++ b/apps/browser-extension/src/OptionsPage.tsx @@ -0,0 +1,60 @@ +import React, { useEffect } from "react"; +import usePluginSettings from "./utils/settings"; +import { api } from "./utils/trpc"; +import Spinner from "./Spinner"; +import { useNavigate } from "react-router-dom"; +import Logo from "./Logo"; + +export default function OptionsPage() { + const navigate = useNavigate(); + const { settings, setSettings } = usePluginSettings(); + + const { data: whoami, error: whoAmIError } = api.users.whoami.useQuery( + undefined, + { + enabled: settings.address != "", + }, + ); + + const invalidateWhoami = api.useUtils().users.whoami.refetch; + + useEffect(() => { + invalidateWhoami(); + }, [settings, invalidateWhoami]); + + let loggedInMessage: React.ReactNode; + if (whoAmIError) { + if (whoAmIError.data?.code == "UNAUTHORIZED") { + loggedInMessage = Not logged in; + } else { + loggedInMessage = ( + Something went wrong: {whoAmIError.message} + ); + } + } else if (whoami) { + loggedInMessage = {whoami.email}; + } else { + loggedInMessage = ; + } + + const onLogout = () => { + setSettings((s) => ({ ...s, apiKey: "" })); + invalidateWhoami(); + navigate("/notconfigured"); + }; + + return ( +
+ + Settings +
+
+ Logged in as: + {loggedInMessage} +
+ +
+ ); +} diff --git a/apps/browser-extension/src/SavePage.tsx b/apps/browser-extension/src/SavePage.tsx new file mode 100644 index 00000000..638af149 --- /dev/null +++ b/apps/browser-extension/src/SavePage.tsx @@ -0,0 +1,60 @@ +import { useEffect, useState } from "react"; +import Spinner from "./Spinner"; +import { api } from "./utils/trpc"; +import { Navigate } from "react-router-dom"; + +export default function SavePage() { + const [error, setError] = useState(undefined); + + const { + data, + mutate: createBookmark, + status, + } = api.bookmarks.createBookmark.useMutation({ + onError: (e) => { + setError("Something went wrong: " + e.message); + }, + }); + + useEffect(() => { + async function runSave() { + let currentUrl; + const [currentTab] = await chrome.tabs.query({ + active: true, + lastFocusedWindow: true, + }); + if (currentTab?.url) { + currentUrl = currentTab.url; + } else { + setError("Couldn't find the URL of the current tab"); + return; + } + + createBookmark({ + type: "link", + url: currentUrl, + }); + } + runSave(); + }, [createBookmark]); + + switch (status) { + case "error": { + return
{error}
; + } + case "success": { + return ; + } + case "pending": { + return ( +
+ Saving Bookmark + +
+ ); + } + case "idle": { + return
; + } + } +} diff --git a/apps/browser-extension/src/SignInPage.tsx b/apps/browser-extension/src/SignInPage.tsx new file mode 100644 index 00000000..6db7c348 --- /dev/null +++ b/apps/browser-extension/src/SignInPage.tsx @@ -0,0 +1,89 @@ +import { useState } from "react"; +import { api } from "./utils/trpc"; +import usePluginSettings from "./utils/settings"; +import { useNavigate } from "react-router-dom"; +import Logo from "./Logo"; + +export default function SignInPage() { + const navigate = useNavigate(); + const { setSettings } = usePluginSettings(); + + const { + mutate: login, + error, + isPending, + } = api.apiKeys.exchange.useMutation({ + onSuccess: (resp) => { + setSettings((s) => ({ ...s, apiKey: resp.key })); + navigate("/options"); + }, + onError: () => {}, + }); + + const [formData, setFormData] = useState<{ + email: string; + password: string; + }>({ + email: "", + password: "", + }); + + const onSubmit = (e: React.FormEvent) => { + e.preventDefault(); + const randStr = (Math.random() + 1).toString(36).substring(5); + login({ ...formData, keyName: `Browser extension: (${randStr})` }); + }; + + let errorMessage = ""; + if (error) { + if (error.data?.code == "UNAUTHORIZED") { + errorMessage = "Wrong username or password"; + } else { + errorMessage = error.message; + } + } + + return ( +
+ +

Login

+

{errorMessage}

+
+
+ + + setFormData((f) => ({ ...f, email: e.target.value })) + } + type="text" + name="email" + className="h-8 flex-1 rounded-lg border border-gray-300 p-2" + /> +
+
+ + + setFormData((f) => ({ + ...f, + password: e.target.value, + })) + } + type="password" + name="password" + className="h-8 flex-1 rounded-lg border border-gray-300 p-2" + /> +
+ +
+
+ ); +} diff --git a/apps/browser-extension/src/Spinner.tsx b/apps/browser-extension/src/Spinner.tsx new file mode 100644 index 00000000..9fd8839b --- /dev/null +++ b/apps/browser-extension/src/Spinner.tsx @@ -0,0 +1,18 @@ +export default function Spinner() { + return ( + + + + ); +} diff --git a/apps/browser-extension/src/assets/react.svg b/apps/browser-extension/src/assets/react.svg new file mode 100644 index 00000000..6c87de9b --- /dev/null +++ b/apps/browser-extension/src/assets/react.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/apps/browser-extension/src/index.css b/apps/browser-extension/src/index.css new file mode 100644 index 00000000..e7d4bb2f --- /dev/null +++ b/apps/browser-extension/src/index.css @@ -0,0 +1,72 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +:root { + font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; + line-height: 1.5; + font-weight: 400; + + color-scheme: light dark; + color: rgba(255, 255, 255, 0.87); + background-color: #242424; + + font-synthesis: none; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} + +a { + font-weight: 500; + color: #646cff; + text-decoration: inherit; +} +a:hover { + color: #535bf2; +} + +body { + margin: 0; + display: flex; + place-items: center; + min-width: 320px; + min-height: 100vh; +} + +h1 { + font-size: 3.2em; + line-height: 1.1; +} + +button { + border-radius: 8px; + border: 1px solid transparent; + padding: 0.6em 1.2em; + font-size: 1em; + font-weight: 500; + font-family: inherit; + background-color: #1a1a1a; + cursor: pointer; + transition: border-color 0.25s; +} +button:hover { + border-color: #646cff; +} +button:focus, +button:focus-visible { + outline: 4px auto -webkit-focus-ring-color; +} + +@media (prefers-color-scheme: light) { + :root { + color: #213547; + background-color: #ffffff; + } + a:hover { + color: #747bff; + } + button { + background-color: #f9f9f9; + } +} diff --git a/apps/browser-extension/src/main.tsx b/apps/browser-extension/src/main.tsx new file mode 100644 index 00000000..085a5a69 --- /dev/null +++ b/apps/browser-extension/src/main.tsx @@ -0,0 +1,40 @@ +import ReactDOM from "react-dom/client"; +import "./index.css"; +import OptionsPage from "./OptionsPage.tsx"; +import NotConfiguredPage from "./NotConfiguredPage.tsx"; +import { Providers } from "./utils/providers.tsx"; +import BookmarkSavedPage from "./BookmarkSavedPage.tsx"; +import { HashRouter, Routes, Route } from "react-router-dom"; +import Layout from "./Layout.tsx"; +import SavePage from "./SavePage.tsx"; +import BookmarkDeletedPage from "./BookmarkDeletedPage.tsx"; +import SignInPage from "./SignInPage.tsx"; + +function App() { + return ( +
+ + + + }> + } /> + } + /> + } + /> + + } /> + } /> + } /> + + + +
+ ); +} + +ReactDOM.createRoot(document.getElementById("root")!).render(); diff --git a/apps/browser-extension/src/utils/providers.tsx b/apps/browser-extension/src/utils/providers.tsx new file mode 100644 index 00000000..d20f2512 --- /dev/null +++ b/apps/browser-extension/src/utils/providers.tsx @@ -0,0 +1,46 @@ +import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; +import { httpBatchLink } from "@trpc/client"; +import { useEffect, useState } from "react"; +import { api } from "./trpc"; +import usePluginSettings, { getPluginSettings } from "./settings"; +import superjson from "superjson"; + +function getTRPCClient(address: string) { + return api.createClient({ + links: [ + httpBatchLink({ + url: `${address}/api/trpc`, + async headers() { + const settings = await getPluginSettings(); + return { + Authorization: `Bearer ${settings.apiKey}`, + }; + }, + transformer: superjson, + }), + ], + }); +} + +export function Providers({ children }: { children: React.ReactNode }) { + const { settings } = usePluginSettings(); + const [queryClient] = useState(() => new QueryClient()); + + const [trpcClient, setTrpcClient] = useState< + ReturnType + >(getTRPCClient(settings.address)); + + useEffect(() => { + setTrpcClient(getTRPCClient(settings.address)); + }, [settings.address]); + + return ( + + {children} + + ); +} diff --git a/apps/browser-extension/src/utils/settings.ts b/apps/browser-extension/src/utils/settings.ts new file mode 100644 index 00000000..37f474c0 --- /dev/null +++ b/apps/browser-extension/src/utils/settings.ts @@ -0,0 +1,22 @@ +import { useChromeStorageSync } from "use-chrome-storage"; + +export type Settings = { + apiKey: string; + address: string; +}; + +export default function usePluginSettings() { + const [settings, setSettings, _1, _2, isInit] = useChromeStorageSync( + "settings", + { + apiKey: "", + address: "", + } as Settings, + ); + + return { settings, setSettings, isPending: isInit }; +} + +export async function getPluginSettings() { + return (await chrome.storage.sync.get("settings")).settings as Settings; +} diff --git a/apps/browser-extension/src/utils/trpc.ts b/apps/browser-extension/src/utils/trpc.ts new file mode 100644 index 00000000..da21a55a --- /dev/null +++ b/apps/browser-extension/src/utils/trpc.ts @@ -0,0 +1,4 @@ +import { createTRPCReact } from "@trpc/react-query"; +import type { AppRouter } from "@hoarder/trpc/routers/_app"; + +export const api = createTRPCReact(); diff --git a/apps/browser-extension/src/vite-env.d.ts b/apps/browser-extension/src/vite-env.d.ts new file mode 100644 index 00000000..11f02fe2 --- /dev/null +++ b/apps/browser-extension/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/apps/browser-extension/tailwind.config.js b/apps/browser-extension/tailwind.config.js new file mode 100644 index 00000000..1c0c7c87 --- /dev/null +++ b/apps/browser-extension/tailwind.config.js @@ -0,0 +1,10 @@ +/** @type {import('tailwindcss').Config} */ +const tailwindConfig = { + content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], + theme: { + extend: {}, + }, + plugins: [], +}; + +export default tailwindConfig; diff --git a/apps/browser-extension/tsconfig.json b/apps/browser-extension/tsconfig.json new file mode 100644 index 00000000..a7fc6fbf --- /dev/null +++ b/apps/browser-extension/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "module": "ESNext", + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react-jsx", + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"], + "references": [{ "path": "./tsconfig.node.json" }] +} diff --git a/apps/browser-extension/tsconfig.node.json b/apps/browser-extension/tsconfig.node.json new file mode 100644 index 00000000..97ede7ee --- /dev/null +++ b/apps/browser-extension/tsconfig.node.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "composite": true, + "skipLibCheck": true, + "module": "ESNext", + "moduleResolution": "bundler", + "allowSyntheticDefaultImports": true, + "strict": true + }, + "include": ["vite.config.ts"] +} diff --git a/apps/browser-extension/vite.config.ts b/apps/browser-extension/vite.config.ts new file mode 100644 index 00000000..29c6bc6e --- /dev/null +++ b/apps/browser-extension/vite.config.ts @@ -0,0 +1,9 @@ +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react-swc"; +import { crx } from "@crxjs/vite-plugin"; +import manifest from "./manifest.json"; + +// https://vitejs.dev/config/ +export default defineConfig({ + plugins: [react(), crx({ manifest })], +}); diff --git a/apps/mobile/.eslintrc.js b/apps/mobile/.eslintrc.js new file mode 100644 index 00000000..53beac49 --- /dev/null +++ b/apps/mobile/.eslintrc.js @@ -0,0 +1,4 @@ +module.exports = { + root: true, + extends: ["universe/native"], +}; diff --git a/apps/mobile/.gitignore b/apps/mobile/.gitignore new file mode 100644 index 00000000..2920e5a8 --- /dev/null +++ b/apps/mobile/.gitignore @@ -0,0 +1,39 @@ +# Learn more https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files + +# dependencies +node_modules/ + +# Expo +.expo/ +dist/ +web-build/ + +# Native +*.orig.* +*.jks +*.p8 +*.p12 +*.key +*.mobileprovision + +# Metro +.metro-health-check* + +# debug +npm-debug.* +yarn-debug.* +yarn-error.* + +# macOS +.DS_Store +*.pem + +# local env files +.env*.local + +# typescript +*.tsbuildinfo + +#build files +ios/ +android/ diff --git a/apps/mobile/.npmrc b/apps/mobile/.npmrc new file mode 100644 index 00000000..d67f3748 --- /dev/null +++ b/apps/mobile/.npmrc @@ -0,0 +1 @@ +node-linker=hoisted diff --git a/apps/mobile/app.json b/apps/mobile/app.json new file mode 100644 index 00000000..e16baa37 --- /dev/null +++ b/apps/mobile/app.json @@ -0,0 +1,57 @@ +{ + "expo": { + "name": "Hoarder App", + "slug": "hoarder", + "scheme": "hoarder", + "version": "1.2.0", + "orientation": "portrait", + "icon": "./assets/icon.png", + "userInterfaceStyle": "light", + "splash": { + "image": "./assets/splash.png", + "resizeMode": "contain", + "backgroundColor": "#ffffff" + }, + "assetBundlePatterns": [ + "**/*" + ], + "ios": { + "supportsTablet": true, + "bundleIdentifier": "app.hoarder.hoardermobile", + "config": { + "usesNonExemptEncryption": false + } + }, + "android": { + "adaptiveIcon": { + "foregroundImage": "./assets/icon.png", + "backgroundColor": "#ffffff" + }, + "package": "app.hoarder.hoardermobile" + }, + "plugins": [ + "expo-router", + [ + "expo-share-intent", + { + "iosActivationRules": { + "NSExtensionActivationSupportsWebURLWithMaxCount": 1, + "NSExtensionActivationSupportsWebPageWithMaxCount": 0, + "NSExtensionActivationSupportsImageWithMaxCount": 0, + "NSExtensionActivationSupportsMovieWithMaxCount": 0, + "NSExtensionActivationSupportsText": true + } + } + ], + "expo-secure-store" + ], + "extra": { + "router": { + "origin": false + }, + "eas": { + "projectId": "d6d14643-ad43-4cd3-902a-92c5944d5e45" + } + } + } +} diff --git a/apps/mobile/app/+not-found.tsx b/apps/mobile/app/+not-found.tsx new file mode 100644 index 00000000..466505b6 --- /dev/null +++ b/apps/mobile/app/+not-found.tsx @@ -0,0 +1,6 @@ +import { View } from "react-native"; + +// This is kinda important given that the sharing modal always resolve to an unknown route +export default function NotFound() { + return ; +} diff --git a/apps/mobile/app/_layout.tsx b/apps/mobile/app/_layout.tsx new file mode 100644 index 00000000..6304ced5 --- /dev/null +++ b/apps/mobile/app/_layout.tsx @@ -0,0 +1,53 @@ +import "@/globals.css"; +import "expo-dev-client"; + +import { useRouter } from "expo-router"; +import { Stack } from "expo-router/stack"; +import { useShareIntent } from "expo-share-intent"; +import { StatusBar } from "expo-status-bar"; +import { useEffect } from "react"; +import { View } from "react-native"; + +import { useLastSharedIntent } from "@/lib/last-shared-intent"; +import { Providers } from "@/lib/providers"; + +export default function RootLayout() { + const router = useRouter(); + const { hasShareIntent, shareIntent, resetShareIntent } = useShareIntent(); + + const lastSharedIntent = useLastSharedIntent(); + + useEffect(() => { + const intentJson = JSON.stringify(shareIntent); + if (hasShareIntent && !lastSharedIntent.isPreviouslyShared(intentJson)) { + // TODO: Remove once https://github.com/achorein/expo-share-intent/issues/14 is fixed + lastSharedIntent.setIntent(intentJson); + router.replace({ + pathname: "sharing", + params: { shareIntent: intentJson }, + }); + resetShareIntent(); + } + }, [hasShareIntent]); + + return ( + + + + + + + + + + ); +} diff --git a/apps/mobile/app/dashboard/(tabs)/_layout.tsx b/apps/mobile/app/dashboard/(tabs)/_layout.tsx new file mode 100644 index 00000000..5b2d810a --- /dev/null +++ b/apps/mobile/app/dashboard/(tabs)/_layout.tsx @@ -0,0 +1,38 @@ +import { Tabs } from "expo-router"; +import { ClipboardList, Home, Search, Settings } from "lucide-react-native"; +import React from "react"; + +export default function TabLayout() { + return ( + + , + }} + /> + , + }} + /> + , + }} + /> + , + }} + /> + + ); +} diff --git a/apps/mobile/app/dashboard/(tabs)/index.tsx b/apps/mobile/app/dashboard/(tabs)/index.tsx new file mode 100644 index 00000000..b2349525 --- /dev/null +++ b/apps/mobile/app/dashboard/(tabs)/index.tsx @@ -0,0 +1,31 @@ +import { Link, Stack } from "expo-router"; +import { SquarePen, Link as LinkIcon } from "lucide-react-native"; +import { View } from "react-native"; + +import BookmarkList from "@/components/bookmarks/BookmarkList"; + +function HeaderRight() { + return ( + + + + + + + + + ); +} + +export default function Home() { + return ( + <> + , + }} + /> + + + ); +} diff --git a/apps/mobile/app/dashboard/(tabs)/lists.tsx b/apps/mobile/app/dashboard/(tabs)/lists.tsx new file mode 100644 index 00000000..b534ddda --- /dev/null +++ b/apps/mobile/app/dashboard/(tabs)/lists.tsx @@ -0,0 +1,67 @@ +import { Link } from "expo-router"; +import { useEffect, useState } from "react"; +import { FlatList, View } from "react-native"; + +import { api } from "@/lib/trpc"; + +export default function Lists() { + const [refreshing, setRefreshing] = useState(false); + const { data: lists, isPending } = api.lists.list.useQuery(); + const apiUtils = api.useUtils(); + + useEffect(() => { + setRefreshing(isPending); + }, [isPending]); + + if (!lists) { + // Add spinner + return ; + } + + const onRefresh = () => { + apiUtils.lists.list.invalidate(); + }; + + const links = [ + { + id: "fav", + logo: "⭐️", + name: "Favourites", + href: "/dashboard/favourites", + }, + { + id: "arch", + logo: "🗄️", + name: "Archive", + href: "/dashboard/archive", + }, + ]; + + links.push( + ...lists.lists.map((l) => ({ + id: l.id, + logo: l.icon, + name: l.name, + href: `/dashboard/lists/${l.id}`, + })), + ); + + return ( + ( + + + {l.item.logo} {l.item.name} + + + )} + data={links} + refreshing={refreshing} + onRefresh={onRefresh} + /> + ); +} diff --git a/apps/mobile/app/dashboard/(tabs)/search.tsx b/apps/mobile/app/dashboard/(tabs)/search.tsx new file mode 100644 index 00000000..980cab36 --- /dev/null +++ b/apps/mobile/app/dashboard/(tabs)/search.tsx @@ -0,0 +1,35 @@ +import { keepPreviousData } from "@tanstack/react-query"; +import { useState } from "react"; +import { View } from "react-native"; +import { useDebounce } from "use-debounce"; + +import BookmarkList from "@/components/bookmarks/BookmarkList"; +import { Divider } from "@/components/ui/Divider"; +import { Input } from "@/components/ui/Input"; +import { api } from "@/lib/trpc"; + +export default function Search() { + const [search, setSearch] = useState(""); + + const [query] = useDebounce(search, 200); + + const { data } = api.bookmarks.searchBookmarks.useQuery( + { text: query }, + { placeholderData: keepPreviousData }, + ); + + return ( + + + + {data && b.id)} />} + + ); +} diff --git a/apps/mobile/app/dashboard/(tabs)/settings.tsx b/apps/mobile/app/dashboard/(tabs)/settings.tsx new file mode 100644 index 00000000..9f86d5ec --- /dev/null +++ b/apps/mobile/app/dashboard/(tabs)/settings.tsx @@ -0,0 +1,41 @@ +import { useRouter } from "expo-router"; +import { useEffect } from "react"; +import { Text, View } from "react-native"; + +import Logo from "@/components/Logo"; +import { Button } from "@/components/ui/Button"; +import { useSession } from "@/lib/session"; +import { api } from "@/lib/trpc"; + +export default function Dashboard() { + const router = useRouter(); + + const { isLoggedIn, logout } = useSession(); + + useEffect(() => { + if (isLoggedIn !== undefined && !isLoggedIn) { + router.replace("signin"); + } + }, [isLoggedIn]); + + const { data, error, isLoading } = api.users.whoami.useQuery(); + + useEffect(() => { + if (error?.data?.code === "UNAUTHORIZED") { + logout(); + } + }, [error]); + + return ( + + + + + {isLoading ? "Loading ..." : data?.email} + + + + + + + Add + + + + + + + ); +} diff --git a/apps/web/components/dashboard/bookmarks/AddToListModal.tsx b/apps/web/components/dashboard/bookmarks/AddToListModal.tsx new file mode 100644 index 00000000..c9fd5da0 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/AddToListModal.tsx @@ -0,0 +1,168 @@ +import { ActionButton } from "@/components/ui/action-button"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, + FormMessage, +} from "@/components/ui/form"; + +import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { useState } from "react"; + +import { + Select, + SelectContent, + SelectGroup, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import LoadingSpinner from "@/components/ui/spinner"; +import { z } from "zod"; +import { useForm } from "react-hook-form"; +import { zodResolver } from "@hookform/resolvers/zod"; + +export default function AddToListModal({ + bookmarkId, + open, + setOpen, +}: { + bookmarkId: string; + open: boolean; + setOpen: (open: boolean) => void; +}) { + const formSchema = z.object({ + listId: z.string({ + required_error: "Please select a list", + }), + }); + const form = useForm>({ + resolver: zodResolver(formSchema), + }); + + const { data: lists, isPending: isFetchingListsPending } = + api.lists.list.useQuery(); + + const listInvalidationFunction = api.useUtils().lists.get.invalidate; + const bookmarksInvalidationFunction = + api.useUtils().bookmarks.getBookmarks.invalidate; + + const { mutate: addToList, isPending: isAddingToListPending } = + api.lists.addToList.useMutation({ + onSuccess: (_resp, req) => { + toast({ + description: "List has been updated!", + }); + listInvalidationFunction({ listId: req.listId }); + bookmarksInvalidationFunction(); + }, + onError: (e) => { + if (e.data?.code == "BAD_REQUEST") { + toast({ + variant: "destructive", + description: e.message, + }); + } else { + toast({ + variant: "destructive", + title: "Something went wrong", + }); + } + }, + }); + + const isPending = isFetchingListsPending || isAddingToListPending; + + return ( + + +
+ { + addToList({ + bookmarkId: bookmarkId, + listId: value.listId, + }); + })} + > + + Add to List + + +
+ {lists ? ( + { + return ( + + + + + + + ); + }} + /> + ) : ( + + )} +
+ + + + + + Add + + +
+ +
+
+ ); +} + +export function useAddToListModal(bookmarkId: string) { + const [open, setOpen] = useState(false); + + return { + open, + setOpen, + content: ( + + ), + }; +} diff --git a/apps/web/components/dashboard/bookmarks/BookmarkCardSkeleton.tsx b/apps/web/components/dashboard/bookmarks/BookmarkCardSkeleton.tsx new file mode 100644 index 00000000..1f5fa433 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/BookmarkCardSkeleton.tsx @@ -0,0 +1,30 @@ +import { + ImageCard, + ImageCardBody, + ImageCardContent, + ImageCardFooter, + ImageCardTitle, + ImageCardBanner, +} from "@/components/ui/imageCard"; +import { Skeleton } from "@/components/ui/skeleton"; + +export default function BookmarkCardSkeleton() { + return ( + + + + + + + + + + + + + ); +} diff --git a/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx b/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx new file mode 100644 index 00000000..4f08ebee --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/BookmarkOptions.tsx @@ -0,0 +1,185 @@ +"use client"; + +import { useToast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { ZBookmark, ZBookmarkedLink } from "@hoarder/trpc/types/bookmarks"; +import { Button } from "@/components/ui/button"; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from "@/components/ui/dropdown-menu"; +import { + Archive, + Link, + List, + MoreHorizontal, + Pencil, + RotateCw, + Star, + Tags, + Trash2, +} from "lucide-react"; +import { useTagModel } from "./TagModal"; +import { useState } from "react"; +import { BookmarkedTextEditor } from "./BookmarkedTextEditor"; +import { useAddToListModal } from "./AddToListModal"; + +export default function BookmarkOptions({ bookmark }: { bookmark: ZBookmark }) { + const { toast } = useToast(); + const linkId = bookmark.id; + + const { setOpen: setTagModalIsOpen, content: tagModal } = + useTagModel(bookmark); + const { setOpen: setAddToListModalOpen, content: addToListModal } = + useAddToListModal(bookmark.id); + + const [isTextEditorOpen, setTextEditorOpen] = useState(false); + + const invalidateAllBookmarksCache = + api.useUtils().bookmarks.getBookmarks.invalidate; + + const invalidateBookmarkCache = + api.useUtils().bookmarks.getBookmark.invalidate; + + const onError = () => { + toast({ + variant: "destructive", + title: "Something went wrong", + description: "There was a problem with your request.", + }); + }; + const deleteBookmarkMutator = api.bookmarks.deleteBookmark.useMutation({ + onSuccess: () => { + toast({ + description: "The bookmark has been deleted!", + }); + }, + onError, + onSettled: () => { + invalidateAllBookmarksCache(); + }, + }); + + const updateBookmarkMutator = api.bookmarks.updateBookmark.useMutation({ + onSuccess: () => { + toast({ + description: "The bookmark has been updated!", + }); + }, + onError, + onSettled: () => { + invalidateBookmarkCache({ bookmarkId: bookmark.id }); + invalidateAllBookmarksCache(); + }, + }); + + const crawlBookmarkMutator = api.bookmarks.recrawlBookmark.useMutation({ + onSuccess: () => { + toast({ + description: "Re-fetch has been enqueued!", + }); + }, + onError, + onSettled: () => { + invalidateBookmarkCache({ bookmarkId: bookmark.id }); + }, + }); + + return ( + <> + {tagModal} + {addToListModal} + + + + + + + {bookmark.content.type === "text" && ( + setTextEditorOpen(true)}> + + Edit + + )} + + updateBookmarkMutator.mutate({ + bookmarkId: linkId, + favourited: !bookmark.favourited, + }) + } + > + + {bookmark.favourited ? "Un-favourite" : "Favourite"} + + + updateBookmarkMutator.mutate({ + bookmarkId: linkId, + archived: !bookmark.archived, + }) + } + > + + {bookmark.archived ? "Un-archive" : "Archive"} + + {bookmark.content.type === "link" && ( + { + navigator.clipboard.writeText( + (bookmark.content as ZBookmarkedLink).url, + ); + toast({ + description: "Link was added to your clipboard!", + }); + }} + > + + Copy Link + + )} + setTagModalIsOpen(true)}> + + Edit Tags + + + setAddToListModalOpen(true)}> + + Add to List + + + {bookmark.content.type === "link" && ( + + crawlBookmarkMutator.mutate({ bookmarkId: bookmark.id }) + } + > + + Refresh + + )} + + deleteBookmarkMutator.mutate({ bookmarkId: bookmark.id }) + } + > + + Delete + + + + + ); +} diff --git a/apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx b/apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx new file mode 100644 index 00000000..2a8ae1b1 --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/BookmarkPreview.tsx @@ -0,0 +1,101 @@ +"use client"; + +import { BackButton } from "@/components/ui/back-button"; +import { Skeleton } from "@/components/ui/skeleton"; +import { isBookmarkStillCrawling } from "@/lib/bookmarkUtils"; +import { api } from "@/lib/trpc"; +import { ZBookmark } from "@hoarder/trpc/types/bookmarks"; +import { ArrowLeftCircle, CalendarDays, ExternalLink } from "lucide-react"; +import Link from "next/link"; +import Markdown from "react-markdown"; + +export default function BookmarkPreview({ + initialData, +}: { + initialData: ZBookmark; +}) { + const { data: bookmark } = api.bookmarks.getBookmark.useQuery( + { + bookmarkId: initialData.id, + }, + { + initialData, + refetchInterval: (query) => { + const data = query.state.data; + if (!data) { + return false; + } + // If the link is not crawled or not tagged + if (isBookmarkStillCrawling(data)) { + return 1000; + } + return false; + }, + }, + ); + + const linkHeader = bookmark.content.type == "link" && ( +
+

+ {bookmark.content.title || bookmark.content.url} +

+ + View Original + + +
+ ); + + let content; + switch (bookmark.content.type) { + case "link": { + if (!bookmark.content.htmlContent) { + content = ( +
Failed to fetch link content ...
+ ); + } else { + content = ( +
+ ); + } + break; + } + case "text": { + content = {bookmark.content.text}; + break; + } + } + + return ( +
+
+ + + +
+ + {bookmark.createdAt.toLocaleString()} + +
+
+
+ {linkHeader} +
+ {isBookmarkStillCrawling(bookmark) ? ( +
+ + + +
+ ) : ( + content + )} +
+
+ ); +} diff --git a/apps/web/components/dashboard/bookmarks/BookmarkedTextEditor.tsx b/apps/web/components/dashboard/bookmarks/BookmarkedTextEditor.tsx new file mode 100644 index 00000000..a5b58f1a --- /dev/null +++ b/apps/web/components/dashboard/bookmarks/BookmarkedTextEditor.tsx @@ -0,0 +1,109 @@ +import { ZBookmark } from "@hoarder/trpc/types/bookmarks"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { ActionButton } from "@/components/ui/action-button"; +import { Button } from "@/components/ui/button"; +import { Textarea } from "@/components/ui/textarea"; +import { api } from "@/lib/trpc"; +import { useState } from "react"; +import { toast } from "@/components/ui/use-toast"; + +export function BookmarkedTextEditor({ + bookmark, + open, + setOpen, +}: { + bookmark?: ZBookmark; + open: boolean; + setOpen: (open: boolean) => void; +}) { + const isNewBookmark = bookmark === undefined; + const [noteText, setNoteText] = useState( + bookmark && bookmark.content.type == "text" ? bookmark.content.text : "", + ); + + const invalidateAllBookmarksCache = + api.useUtils().bookmarks.getBookmarks.invalidate; + const invalidateOneBookmarksCache = + api.useUtils().bookmarks.getBookmark.invalidate; + + const { mutate: createBookmarkMutator, isPending: isCreationPending } = + api.bookmarks.createBookmark.useMutation({ + onSuccess: () => { + invalidateAllBookmarksCache(); + toast({ + description: "Note created!", + }); + setOpen(false); + setNoteText(""); + }, + onError: () => { + toast({ description: "Something went wrong", variant: "destructive" }); + }, + }); + const { mutate: updateBookmarkMutator, isPending: isUpdatePending } = + api.bookmarks.updateBookmarkText.useMutation({ + onSuccess: () => { + invalidateOneBookmarksCache({ + bookmarkId: bookmark!.id, + }); + toast({ + description: "Note updated!", + }); + setOpen(false); + }, + onError: () => { + toast({ description: "Something went wrong", variant: "destructive" }); + }, + }); + const isPending = isCreationPending || isUpdatePending; + + const onSave = () => { + if (isNewBookmark) { + createBookmarkMutator({ + type: "text", + text: noteText, + }); + } else { + updateBookmarkMutator({ + bookmarkId: bookmark.id, + text: noteText, + }); + } + }; + + return ( + + + + {isNewBookmark ? "New Note" : "Edit Note"} + + Write your note with markdown support + + +