From 96a874266961e36b97ae0681e2a916f1fff11fe3 Mon Sep 17 00:00:00 2001 From: Ali Osman Date: Wed, 19 Jul 2023 08:58:41 +0300 Subject: [PATCH 1/4] feat: add extension theme mode, refactor src directory --- apps/extension/package.json | 3 +- apps/extension/{ => src}/background/index.ts | 0 .../{ => src}/background/messages/getToken.ts | 0 .../background/messages/openSettings.ts | 0 .../{ => src}/contents/translate.tsx | 13 +- .../popup/components/DictionarySelector.tsx | 0 .../popup/components/LanguageSelector.tsx | 0 .../features/popup/components/Popup.tsx | 0 .../{ => src}/features/popup/context/popup.ts | 0 .../components/DictionarySelector.tsx | 47 ++++- .../translate/components/FlaotingButton.tsx | 0 .../translate/components/LanguageSelector.tsx | 0 .../translate/components/TranslatePopup.tsx | 14 +- .../features/translate/context/popover.ts | 21 ++- apps/extension/{ => src}/libs/trpc.ts | 0 .../options/apparence/apparance-form.tsx | 4 +- .../{ => src}/options/apparence/layout.tsx | 0 .../options/components/sidebar-nav.tsx | 0 .../{ => src}/options/context/options.ts | 0 apps/extension/{ => src}/options/index.tsx | 14 +- .../options/providers/trpc-provider.tsx | 0 .../{ => src}/options/settings/layout.tsx | 0 .../options/settings/settings-form.tsx | 0 apps/extension/{ => src}/popup.tsx | 0 apps/extension/src/providers/index.tsx | 19 ++ apps/extension/{ => src}/styles/globals.css | 0 apps/extension/{ => src}/utils/constants.ts | 0 apps/extension/{ => src}/utils/index.ts | 0 apps/extension/{ => src}/utils/schemas.ts | 0 .../src/components/Published/Published.tsx | 1 - apps/next/src/components/Published/Rating.tsx | 2 - apps/next/src/components/Published/index.tsx | 2 - .../components/Published/published.constan.ts | 162 +++++++++--------- packages/api/src/router/word.ts | 40 ++--- 34 files changed, 196 insertions(+), 146 deletions(-) rename apps/extension/{ => src}/background/index.ts (100%) rename apps/extension/{ => src}/background/messages/getToken.ts (100%) rename apps/extension/{ => src}/background/messages/openSettings.ts (100%) rename apps/extension/{ => src}/contents/translate.tsx (80%) rename apps/extension/{ => src}/features/popup/components/DictionarySelector.tsx (100%) rename apps/extension/{ => src}/features/popup/components/LanguageSelector.tsx (100%) rename apps/extension/{ => src}/features/popup/components/Popup.tsx (100%) rename apps/extension/{ => src}/features/popup/context/popup.ts (100%) rename apps/extension/{ => src}/features/translate/components/DictionarySelector.tsx (54%) rename apps/extension/{ => src}/features/translate/components/FlaotingButton.tsx (100%) rename apps/extension/{ => src}/features/translate/components/LanguageSelector.tsx (100%) rename apps/extension/{ => src}/features/translate/components/TranslatePopup.tsx (92%) rename apps/extension/{ => src}/features/translate/context/popover.ts (84%) rename apps/extension/{ => src}/libs/trpc.ts (100%) rename apps/extension/{ => src}/options/apparence/apparance-form.tsx (99%) rename apps/extension/{ => src}/options/apparence/layout.tsx (100%) rename apps/extension/{ => src}/options/components/sidebar-nav.tsx (100%) rename apps/extension/{ => src}/options/context/options.ts (100%) rename apps/extension/{ => src}/options/index.tsx (84%) rename apps/extension/{ => src}/options/providers/trpc-provider.tsx (100%) rename apps/extension/{ => src}/options/settings/layout.tsx (100%) rename apps/extension/{ => src}/options/settings/settings-form.tsx (100%) rename apps/extension/{ => src}/popup.tsx (100%) create mode 100644 apps/extension/src/providers/index.tsx rename apps/extension/{ => src}/styles/globals.css (100%) rename apps/extension/{ => src}/utils/constants.ts (100%) rename apps/extension/{ => src}/utils/index.ts (100%) rename apps/extension/{ => src}/utils/schemas.ts (100%) diff --git a/apps/extension/package.json b/apps/extension/package.json index 1ccd8c8b..dd518954 100644 --- a/apps/extension/package.json +++ b/apps/extension/package.json @@ -22,6 +22,7 @@ "cors": "^2.8.5", "framer-motion": "^10.12.18", "lucide-react": "^0.257.0", + "next-themes": "^0.2.1", "plasmo": "0.80.0", "react": "18.2.0", "react-country-flag": "^3.1.0", @@ -52,4 +53,4 @@ "http://localhost:3000/" ] } -} \ No newline at end of file +} diff --git a/apps/extension/background/index.ts b/apps/extension/src/background/index.ts similarity index 100% rename from apps/extension/background/index.ts rename to apps/extension/src/background/index.ts diff --git a/apps/extension/background/messages/getToken.ts b/apps/extension/src/background/messages/getToken.ts similarity index 100% rename from apps/extension/background/messages/getToken.ts rename to apps/extension/src/background/messages/getToken.ts diff --git a/apps/extension/background/messages/openSettings.ts b/apps/extension/src/background/messages/openSettings.ts similarity index 100% rename from apps/extension/background/messages/openSettings.ts rename to apps/extension/src/background/messages/openSettings.ts diff --git a/apps/extension/contents/translate.tsx b/apps/extension/src/contents/translate.tsx similarity index 80% rename from apps/extension/contents/translate.tsx rename to apps/extension/src/contents/translate.tsx index a63be6f5..05442c22 100644 --- a/apps/extension/contents/translate.tsx +++ b/apps/extension/src/contents/translate.tsx @@ -1,16 +1,14 @@ import FloatingButton from "~features/translate/components/FlaotingButton" import { PopoverContext, useContextPopover, usePopover } from "~features/translate/context/popover" -import { TRPCProvider } from "~options/providers/trpc-provider" import "@wordigo/ui/styles/globals.css" -import { Portal } from "@radix-ui/react-portal" import styleText from "data-text:@wordigo/ui/styles/globals.css" import type { PlasmoCSConfig } from "plasmo" import { Fragment } from "react" -import { Toaster } from "~../../packages/ui" import TranslatePopup from "~features/translate/components/TranslatePopup" +import Provider from "~providers" export const config: PlasmoCSConfig = { matches: [""], @@ -40,14 +38,11 @@ Translate.Layout = () => { const popover = usePopover({}) return ( - - + - - - + - + ) } diff --git a/apps/extension/features/popup/components/DictionarySelector.tsx b/apps/extension/src/features/popup/components/DictionarySelector.tsx similarity index 100% rename from apps/extension/features/popup/components/DictionarySelector.tsx rename to apps/extension/src/features/popup/components/DictionarySelector.tsx diff --git a/apps/extension/features/popup/components/LanguageSelector.tsx b/apps/extension/src/features/popup/components/LanguageSelector.tsx similarity index 100% rename from apps/extension/features/popup/components/LanguageSelector.tsx rename to apps/extension/src/features/popup/components/LanguageSelector.tsx diff --git a/apps/extension/features/popup/components/Popup.tsx b/apps/extension/src/features/popup/components/Popup.tsx similarity index 100% rename from apps/extension/features/popup/components/Popup.tsx rename to apps/extension/src/features/popup/components/Popup.tsx diff --git a/apps/extension/features/popup/context/popup.ts b/apps/extension/src/features/popup/context/popup.ts similarity index 100% rename from apps/extension/features/popup/context/popup.ts rename to apps/extension/src/features/popup/context/popup.ts diff --git a/apps/extension/features/translate/components/DictionarySelector.tsx b/apps/extension/src/features/translate/components/DictionarySelector.tsx similarity index 54% rename from apps/extension/features/translate/components/DictionarySelector.tsx rename to apps/extension/src/features/translate/components/DictionarySelector.tsx index 70a65bf1..657c072b 100644 --- a/apps/extension/features/translate/components/DictionarySelector.tsx +++ b/apps/extension/src/features/translate/components/DictionarySelector.tsx @@ -8,15 +8,19 @@ import { ToastAction, useToast } from "@wordigo/ui" -import { ChevronDown } from "lucide-react" -import { useState } from "react" +import { ChevronDown, RotateCw } from "lucide-react" +import { Fragment, useEffect, useState } from "react" import { sendToBackground } from "@plasmohq/messaging" import trpc from "~libs/trpc" -const DictionarySelector = () => { +import { useContextPopover } from "../context/popover" + +const DictionarySelector = ({ sourceLangauge, translatedText }: { sourceLangauge: string; translatedText: string }) => { + const { targetLanguage, selectedText } = useContextPopover() const { mutate, data, isLoading } = trpc.dictionary.getUserDictionariesMutation.useMutation() + const { mutate: addMutate, isLoading: addIsLoading, status } = trpc.word.addWord.useMutation() const [showMenu, setShowMenu] = useState(false) const { toast } = useToast() @@ -40,7 +44,20 @@ const DictionarySelector = () => { } } - const handleAddLibrary = () => {} + useEffect(() => { + if (status === "success") { + toast({ + title: "Successful", + description: "Word insertion successful.", + action: View Dictionary + }) + } + }, [status]) + + const handleAddLibrary = (dictionaryId: string) => { + setShowMenu(false) + addMutate({ dictionaryId, nativeLanguage: sourceLangauge, targetLanguage, text: selectedText, translatedText }) + } return ( @@ -48,16 +65,30 @@ const DictionarySelector = () => { {isLoading ? ( ) : ( - data?.dictionaries?.map((item) => {item.title}) + data?.data?.map((item) => ( + handleAddLibrary(item.id)} key={item.id}> + {item.title} + + )) )} diff --git a/apps/extension/features/translate/components/FlaotingButton.tsx b/apps/extension/src/features/translate/components/FlaotingButton.tsx similarity index 100% rename from apps/extension/features/translate/components/FlaotingButton.tsx rename to apps/extension/src/features/translate/components/FlaotingButton.tsx diff --git a/apps/extension/features/translate/components/LanguageSelector.tsx b/apps/extension/src/features/translate/components/LanguageSelector.tsx similarity index 100% rename from apps/extension/features/translate/components/LanguageSelector.tsx rename to apps/extension/src/features/translate/components/LanguageSelector.tsx diff --git a/apps/extension/features/translate/components/TranslatePopup.tsx b/apps/extension/src/features/translate/components/TranslatePopup.tsx similarity index 92% rename from apps/extension/features/translate/components/TranslatePopup.tsx rename to apps/extension/src/features/translate/components/TranslatePopup.tsx index d3a4c256..fd919c51 100644 --- a/apps/extension/features/translate/components/TranslatePopup.tsx +++ b/apps/extension/src/features/translate/components/TranslatePopup.tsx @@ -13,7 +13,6 @@ import { } from "@wordigo/ui" import { motion } from "framer-motion" import { ArrowRightLeft, Copy, Settings, Volume2 } from "lucide-react" -import type { MouseEvent } from "react" import { useEffect, useMemo } from "react" import ReactCountryFlag from "react-country-flag" @@ -53,10 +52,6 @@ const TranslatePopup = () => { opeendSettings && setPopup(false) } - const handleAddLibrary = (event: MouseEvent) => { - event.preventDefault() - } - const textToSpeech = () => { const speech = new SpeechSynthesisUtterance(data.translatedText as string) // Initialize the speech synthesis @@ -68,11 +63,6 @@ const TranslatePopup = () => { window.speechSynthesis.speak(speech) } - const closeTranslationPopup = () => { - setPopup(false) - reset() - } - const copyTranslatedText = () => { void navigator.clipboard.writeText(data.translatedText as string) toast.toast({ @@ -147,11 +137,11 @@ const TranslatePopup = () => { - - + diff --git a/apps/extension/features/translate/context/popover.ts b/apps/extension/src/features/translate/context/popover.ts similarity index 84% rename from apps/extension/features/translate/context/popover.ts rename to apps/extension/src/features/translate/context/popover.ts index 46ec6d0a..412779d2 100644 --- a/apps/extension/features/translate/context/popover.ts +++ b/apps/extension/src/features/translate/context/popover.ts @@ -7,8 +7,10 @@ import { useStorage } from "@plasmohq/storage/hook" export interface IPopoverOptions { isFloating: boolean isPopup: boolean + sourceLanguage: string setFloating: Dispatch> setPopup: Dispatch> + setSourceLanguage: Dispatch> selectedText?: string targetLanguage: string cordinate: { @@ -22,6 +24,7 @@ export const usePopover = ({}) => { const [isFloating, setFloating] = useState(false) const [isPopup, setPopup] = useState(false) const [selectedText, setSelectedText] = useState() + const [sourceLanguage, setSourceLanguage] = useState() const [cordinate, setCordinate] = useState({ x: 0, y: 0 }) const [targetLanguage] = useStorage({ @@ -80,9 +83,23 @@ export const usePopover = ({}) => { targetLanguage, setPopup, cordinate, - setCordinate + setCordinate, + sourceLanguage, + setSourceLanguage }), - [selectedText, setSelectedText, isFloating, setFloating, isPopup, setPopup, targetLanguage, cordinate, setCordinate] + [ + selectedText, + setSelectedText, + isFloating, + setFloating, + isPopup, + setPopup, + targetLanguage, + sourceLanguage, + cordinate, + setCordinate, + setSourceLanguage + ] ) } diff --git a/apps/extension/libs/trpc.ts b/apps/extension/src/libs/trpc.ts similarity index 100% rename from apps/extension/libs/trpc.ts rename to apps/extension/src/libs/trpc.ts diff --git a/apps/extension/options/apparence/apparance-form.tsx b/apps/extension/src/options/apparence/apparance-form.tsx similarity index 99% rename from apps/extension/options/apparence/apparance-form.tsx rename to apps/extension/src/options/apparence/apparance-form.tsx index d73456b4..fcebeb5b 100644 --- a/apps/extension/options/apparence/apparance-form.tsx +++ b/apps/extension/src/options/apparence/apparance-form.tsx @@ -43,6 +43,8 @@ const ApparanceForm = () => { }) function onSubmit(data: AppearanceFormValues) { + console.log(data.theme) + theme.setTheme(data.theme) // toast({ @@ -56,7 +58,7 @@ const ApparanceForm = () => { } return ( -
+ { const options = useOptions({}) return ( - - + +

Settings

@@ -49,9 +50,8 @@ Dashboard.Layout = () => {
- -
-
+ + ) } diff --git a/apps/extension/options/providers/trpc-provider.tsx b/apps/extension/src/options/providers/trpc-provider.tsx similarity index 100% rename from apps/extension/options/providers/trpc-provider.tsx rename to apps/extension/src/options/providers/trpc-provider.tsx diff --git a/apps/extension/options/settings/layout.tsx b/apps/extension/src/options/settings/layout.tsx similarity index 100% rename from apps/extension/options/settings/layout.tsx rename to apps/extension/src/options/settings/layout.tsx diff --git a/apps/extension/options/settings/settings-form.tsx b/apps/extension/src/options/settings/settings-form.tsx similarity index 100% rename from apps/extension/options/settings/settings-form.tsx rename to apps/extension/src/options/settings/settings-form.tsx diff --git a/apps/extension/popup.tsx b/apps/extension/src/popup.tsx similarity index 100% rename from apps/extension/popup.tsx rename to apps/extension/src/popup.tsx diff --git a/apps/extension/src/providers/index.tsx b/apps/extension/src/providers/index.tsx new file mode 100644 index 00000000..c99f3159 --- /dev/null +++ b/apps/extension/src/providers/index.tsx @@ -0,0 +1,19 @@ +import { Portal } from "@radix-ui/react-portal" +import { ThemeProvider } from "next-themes" +import type { PropsWithChildren } from "react" + +import { Toaster } from "~../../packages/ui" +import { TRPCProvider } from "~options/providers/trpc-provider" + +const Provider = ({ children }: PropsWithChildren) => { + return ( + + + {children} + + + + ) +} + +export default Provider diff --git a/apps/extension/styles/globals.css b/apps/extension/src/styles/globals.css similarity index 100% rename from apps/extension/styles/globals.css rename to apps/extension/src/styles/globals.css diff --git a/apps/extension/utils/constants.ts b/apps/extension/src/utils/constants.ts similarity index 100% rename from apps/extension/utils/constants.ts rename to apps/extension/src/utils/constants.ts diff --git a/apps/extension/utils/index.ts b/apps/extension/src/utils/index.ts similarity index 100% rename from apps/extension/utils/index.ts rename to apps/extension/src/utils/index.ts diff --git a/apps/extension/utils/schemas.ts b/apps/extension/src/utils/schemas.ts similarity index 100% rename from apps/extension/utils/schemas.ts rename to apps/extension/src/utils/schemas.ts diff --git a/apps/next/src/components/Published/Published.tsx b/apps/next/src/components/Published/Published.tsx index c4c6ea08..54d41a64 100644 --- a/apps/next/src/components/Published/Published.tsx +++ b/apps/next/src/components/Published/Published.tsx @@ -1,4 +1,3 @@ -import React from "react"; import Image from "next/image"; import Rating from "./Rating"; diff --git a/apps/next/src/components/Published/Rating.tsx b/apps/next/src/components/Published/Rating.tsx index d95fc51b..9d695a0a 100644 --- a/apps/next/src/components/Published/Rating.tsx +++ b/apps/next/src/components/Published/Rating.tsx @@ -1,5 +1,3 @@ -import React from "react"; - export default function Rating({ rating }: { rating: string | null }) { return (
diff --git a/apps/next/src/components/Published/index.tsx b/apps/next/src/components/Published/index.tsx index 5dbdf39f..b1255b65 100644 --- a/apps/next/src/components/Published/index.tsx +++ b/apps/next/src/components/Published/index.tsx @@ -1,5 +1,3 @@ -import React from "react"; - import Published from "./Published"; import PublishedConstan, { type IPublished } from "./published.constan"; diff --git a/apps/next/src/components/Published/published.constan.ts b/apps/next/src/components/Published/published.constan.ts index c8329d28..b85a977a 100644 --- a/apps/next/src/components/Published/published.constan.ts +++ b/apps/next/src/components/Published/published.constan.ts @@ -1,95 +1,95 @@ export interface IPublished { - title: string, - src: string | null, - description: string, - user: IUser, - rating: string | null, - words_length: string, + title: string; + src: string | null; + description: string; + user: IUser; + rating: string | null; + words_length: string; } interface IUser { - name: string, - profil_avatar: string | null, + name: string; + profil_avatar: string | null; } const published: IPublished[] = [ - { - description: "Des1", - rating: "5", - src: "", - title: "Title1", - user: { - name: "Ipsum", - profil_avatar: "" - }, - words_length: "" + { + description: "Des1", + rating: "5", + src: "", + title: "Title1", + user: { + name: "Ipsum", + profil_avatar: "", }, - { - description: "Des2", - rating: "5", - src: "", - title: "Title2", - user: { - name: "Ipsum", - profil_avatar: "" - }, - words_length: "" + words_length: "", + }, + { + description: "Des2", + rating: "5", + src: "", + title: "Title2", + user: { + name: "Ipsum", + profil_avatar: "", }, - { - description: "Des2", - rating: "5", - src: "", - title: "Title2", - user: { - name: "Ipsum", - profil_avatar: "" - }, - words_length: "" + words_length: "", + }, + { + description: "Des2", + rating: "5", + src: "", + title: "Title2", + user: { + name: "Ipsum", + profil_avatar: "", }, - { - description: "Des2", - rating: "5", - src: "", - title: "Title2", - user: { - name: "Ipsum", - profil_avatar: "" - }, - words_length: "" + words_length: "", + }, + { + description: "Des2", + rating: "5", + src: "", + title: "Title2", + user: { + name: "Ipsum", + profil_avatar: "", }, - { - description: "Des2", - rating: "5", - src: "", - title: "Title2", - user: { - name: "Ipsum", - profil_avatar: "" - }, - words_length: "" + words_length: "", + }, + { + description: "Des2", + rating: "5", + src: "", + title: "Title2", + user: { + name: "Ipsum", + profil_avatar: "", }, - { - description: "Des3", - rating: "5", - src: "", - title: "Title3", - user: { - name: "Ipsum", - profil_avatar: "" - }, - words_length: "" + words_length: "", + }, + { + description: "Des3", + rating: "5", + src: "", + title: "Title3", + user: { + name: "Ipsum", + profil_avatar: "", }, - { - description: "Des4", - rating: "5", - src: "", - title: "Title4", - user: { - name: "Ipsum", - profil_avatar: "" - }, - words_length: "" - } -] + words_length: "", + }, + { + description: "Des4", + rating: "5", + src: "", + title: "Title4", + user: { + name: "Ipsum", + profil_avatar: "", + }, + words_length: "", + }, +]; -export default published \ No newline at end of file +export default published; diff --git a/packages/api/src/router/word.ts b/packages/api/src/router/word.ts index 86276e05..efc343de 100644 --- a/packages/api/src/router/word.ts +++ b/packages/api/src/router/word.ts @@ -1,11 +1,11 @@ -import { z } from "zod" +import { z } from "zod"; -import { prisma } from "@wordigo/db" +import { prisma } from "@wordigo/db"; -import { DictionaryInitialTitle, LearningStatuses } from "../../../common/constants/index" -import messages from "../../../common/constants/messages" -import { errorResult, successResult } from "../../../common/constants/results" -import { createTRPCRouter, protectedProcedure } from "../trpc" +import { DictionaryInitialTitle, LearningStatuses } from "../../../common/constants/index"; +import messages from "../../../common/constants/messages"; +import { errorResult, successResult } from "../../../common/constants/results"; +import { createTRPCRouter, protectedProcedure } from "../trpc"; export const wordRouter = createTRPCRouter({ addWord: protectedProcedure @@ -19,8 +19,8 @@ export const wordRouter = createTRPCRouter({ }), ) .mutation(async ({ ctx, input }) => { - const { text, translatedText, nativeLanguage, targetLanguage, dictionaryId } = input - const userId = ctx.user.id + const { text, translatedText, nativeLanguage, targetLanguage, dictionaryId } = input; + const userId = ctx.user.id; if ((dictionaryId?.length as number) > 0) { const dicFromDb = await prisma.dictionaries.findFirst({ @@ -28,10 +28,10 @@ export const wordRouter = createTRPCRouter({ id: dictionaryId as string, authorId: userId, }, - }) + }); if (!dicFromDb) { - return errorResult(false, messages.dictionary_not_found) + return errorResult(false, messages.dictionary_not_found); } } @@ -42,9 +42,9 @@ export const wordRouter = createTRPCRouter({ nativeLanguage, targetLanguage, }, - }) + }); - let word + let word; if (!wordFromDb) word = await prisma.words.create({ data: { @@ -53,8 +53,8 @@ export const wordRouter = createTRPCRouter({ nativeLanguage, targetLanguage, }, - }) - else word = wordFromDb + }); + else word = wordFromDb; const userWord = await prisma.userWords.create({ data: { @@ -62,20 +62,20 @@ export const wordRouter = createTRPCRouter({ learningStatus: LearningStatuses["Not Learned"], authorId: userId, }, - }) + }); const initialDictionary = await prisma.dictionaries.findFirst({ where: { title: DictionaryInitialTitle, }, - }) + }); await prisma.dictAndUserWords.create({ data: { userWordId: userWord.id, dictionaryId: initialDictionary?.id as string, }, - }) + }); if (dictionaryId) { await prisma.dictAndUserWords.create({ @@ -83,10 +83,10 @@ export const wordRouter = createTRPCRouter({ userWordId: userWord.id, dictionaryId, }, - }) + }); } - return successResult(true, messages.success) + return successResult(true, messages.success); }), //Whole list can be seen just by admins @@ -104,4 +104,4 @@ export const wordRouter = createTRPCRouter({ // } // }), -}) +}); From 0a5c92c52057b31c82f08569cd9f997752a738f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sefa=20kap=C4=B1s=C4=B1z?= Date: Thu, 20 Jul 2023 07:37:24 +0300 Subject: [PATCH 2/4] feat: user udpate added --- packages/api/src/root.ts | 4 +- packages/api/src/router/dictionary.ts | 7 +++ packages/api/src/router/user.ts | 66 +++++++++++++++++++++++++++ packages/common/constants/messages.ts | 4 +- 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 packages/api/src/router/user.ts diff --git a/packages/api/src/root.ts b/packages/api/src/root.ts index fffb14e5..6930ca47 100644 --- a/packages/api/src/root.ts +++ b/packages/api/src/root.ts @@ -3,6 +3,7 @@ import { dictionaryRouter } from "./router/dictionary" import { dictionaryWordRouter } from "./router/dictionaryWord" import { subscribeRouter } from './router/subscribe' import { translationRouter } from "./router/translation" +import { userRouter } from './router/user' import { userWordRouter } from "./router/userWord" import { wordRouter } from "./router/word" import { createTRPCRouter } from "./trpc" @@ -14,7 +15,8 @@ export const appRouter = createTRPCRouter({ dictionaryWord: dictionaryWordRouter, word: wordRouter, userWord: userWordRouter, - subscribe: subscribeRouter + subscribe: subscribeRouter, + user: userRouter }) // export type definition of API diff --git a/packages/api/src/router/dictionary.ts b/packages/api/src/router/dictionary.ts index 3225d52b..ba63b53c 100644 --- a/packages/api/src/router/dictionary.ts +++ b/packages/api/src/router/dictionary.ts @@ -15,6 +15,13 @@ export const dictionaryRouter = createTRPCRouter({ return successResult(dictionaries, messages.success) }), + //getUserDictionaryList + getUserPublicDictionaries: protectedProcedure.query(async () => { + const dictionaries = await prisma.dictionaries.findMany({ where: { published: true } }) + + return successResult(dictionaries, messages.success) + }), + //getUserDictionary Mutation getUserDictionariesMutation: protectedProcedure.mutation(async ({ ctx }) => { const { id } = ctx.user diff --git a/packages/api/src/router/user.ts b/packages/api/src/router/user.ts new file mode 100644 index 00000000..605cc6f4 --- /dev/null +++ b/packages/api/src/router/user.ts @@ -0,0 +1,66 @@ + +import { prisma } from "@wordigo/db" + +import { z } from 'zod' +import messages from '../../../common/constants/messages' +import { errorResult, successResult } from '../../../common/constants/results' +import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc" + +export const userRouter = createTRPCRouter({ + publicDicsUsers: publicProcedure + .query(async () => { + const publicDictionaries = await prisma.dictionaries + .findMany({ where: { published: true }, include: { author: true } }) + + const users = publicDictionaries + + }), + + delete: protectedProcedure + .input(z.object({ + userId: z.string() + })) + .mutation(async ({ ctx, input }) => { + const { userId } = input + + const userFromDb = await prisma.profiles.findFirst({ where: { id: userId } }) + if (!userFromDb) { + return errorResult(null, messages.user_not_found) + } + + await prisma.profiles.delete({ where: { id: userId } }) + + }), + + update: protectedProcedure + .input(z.object({ + username: z.string().nullable(), + name: z.string().nullable(), + avatar_url: z.string().nullable(), + nativeLanguage: z.string().nullable(), + targetLanguage: z.string().nullable() + })) + .mutation(async ({ ctx, input }) => { + const { username, name, avatar_url, nativeLanguage, targetLanguage } = input + const { user } = ctx + + const profile = await prisma.profiles.findFirst({ where: { id: user.id } }) + if (!profile) + return errorResult(false, messages.user_not_found) + + await prisma.profiles.update({ + where: { id: profile.id }, + data: { + username: username === null || '' ? profile.username : username, + name: name === null || '' ? profile.name : name, + avatar_url: avatar_url === null || '' ? profile.avatar_url : avatar_url, + nativeLanguage: nativeLanguage === null || '' ? profile.nativeLanguage : nativeLanguage, + targetLanguage: targetLanguage === null || '' ? profile.targetLanguage : targetLanguage + } + }) + + return successResult(true, messages.success) + + }) + +}) \ No newline at end of file diff --git a/packages/common/constants/messages.ts b/packages/common/constants/messages.ts index 59c88cb2..a1779687 100644 --- a/packages/common/constants/messages.ts +++ b/packages/common/constants/messages.ts @@ -6,5 +6,7 @@ export default { userWord_not_found: "UserWord Couldn't Found!", - word_not_found: "Word Couldn't Found!" + word_not_found: "Word Couldn't Found!", + + user_not_found: "User Couldn't Found!" } \ No newline at end of file From 7d533716c26f9666c43be1ff997b3ed86d883553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?sefa=20kap=C4=B1s=C4=B1z?= Date: Thu, 20 Jul 2023 08:22:00 +0300 Subject: [PATCH 3/4] feat: language check added --- packages/api/src/router/user.ts | 17 +++++++++ packages/api/src/router/word.ts | 50 ++++++++++++++++----------- packages/common/constants/messages.ts | 4 ++- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/packages/api/src/router/user.ts b/packages/api/src/router/user.ts index 605cc6f4..28d6994f 100644 --- a/packages/api/src/router/user.ts +++ b/packages/api/src/router/user.ts @@ -2,6 +2,7 @@ import { prisma } from "@wordigo/db" import { z } from 'zod' +import { AllCountryLanguages } from '../../../common' import messages from '../../../common/constants/messages' import { errorResult, successResult } from '../../../common/constants/results' import { createTRPCRouter, protectedProcedure, publicProcedure } from "../trpc" @@ -48,6 +49,22 @@ export const userRouter = createTRPCRouter({ if (!profile) return errorResult(false, messages.user_not_found) + if (nativeLanguage !== null && nativeLanguage !== '') { + const doNativeLangExist = AllCountryLanguages.filter(lang => { + return lang.code.toLowerCase() === nativeLanguage?.trim().toLowerCase() + }) + + if (doNativeLangExist.length === 0) + return errorResult(false, messages.language_not_found) + } else if (targetLanguage !== null && targetLanguage !== '') { + const doTargetLangExist = AllCountryLanguages.filter(lang => { + return lang.code.toLowerCase() === targetLanguage?.trim().toLowerCase() + }) + + if (doTargetLangExist.length === 0) + return errorResult(false, messages.language_not_found) + } + await prisma.profiles.update({ where: { id: profile.id }, data: { diff --git a/packages/api/src/router/word.ts b/packages/api/src/router/word.ts index efc343de..627f4c64 100644 --- a/packages/api/src/router/word.ts +++ b/packages/api/src/router/word.ts @@ -1,11 +1,12 @@ -import { z } from "zod"; +import { z } from "zod" -import { prisma } from "@wordigo/db"; +import { prisma } from "@wordigo/db" -import { DictionaryInitialTitle, LearningStatuses } from "../../../common/constants/index"; -import messages from "../../../common/constants/messages"; -import { errorResult, successResult } from "../../../common/constants/results"; -import { createTRPCRouter, protectedProcedure } from "../trpc"; +import { DictionaryInitialTitle, LearningStatuses } from "../../../common/constants/index" +import messages from "../../../common/constants/messages" +import { errorResult, successResult } from "../../../common/constants/results" +import { AllCountryLanguages } from '../../../common/index' +import { createTRPCRouter, protectedProcedure } from "../trpc" export const wordRouter = createTRPCRouter({ addWord: protectedProcedure @@ -19,8 +20,8 @@ export const wordRouter = createTRPCRouter({ }), ) .mutation(async ({ ctx, input }) => { - const { text, translatedText, nativeLanguage, targetLanguage, dictionaryId } = input; - const userId = ctx.user.id; + const { text, translatedText, nativeLanguage, targetLanguage, dictionaryId } = input + const userId = ctx.user.id if ((dictionaryId?.length as number) > 0) { const dicFromDb = await prisma.dictionaries.findFirst({ @@ -28,13 +29,22 @@ export const wordRouter = createTRPCRouter({ id: dictionaryId as string, authorId: userId, }, - }); + }) if (!dicFromDb) { - return errorResult(false, messages.dictionary_not_found); + return errorResult(false, messages.dictionary_not_found) } } + const doLangsExist = AllCountryLanguages.filter(lang => { + return lang.code.toLowerCase() === nativeLanguage.trim().toLowerCase() || + lang.code.toLowerCase() === targetLanguage.trim().toLowerCase() + }) + + if (doLangsExist.length !== 2) { + return errorResult(false, messages.language_not_found) + } + const wordFromDb = await prisma.words.findFirst({ where: { text: text.trim().toLowerCase(), @@ -42,9 +52,9 @@ export const wordRouter = createTRPCRouter({ nativeLanguage, targetLanguage, }, - }); + }) - let word; + let word if (!wordFromDb) word = await prisma.words.create({ data: { @@ -53,8 +63,8 @@ export const wordRouter = createTRPCRouter({ nativeLanguage, targetLanguage, }, - }); - else word = wordFromDb; + }) + else word = wordFromDb const userWord = await prisma.userWords.create({ data: { @@ -62,20 +72,20 @@ export const wordRouter = createTRPCRouter({ learningStatus: LearningStatuses["Not Learned"], authorId: userId, }, - }); + }) const initialDictionary = await prisma.dictionaries.findFirst({ where: { title: DictionaryInitialTitle, }, - }); + }) await prisma.dictAndUserWords.create({ data: { userWordId: userWord.id, dictionaryId: initialDictionary?.id as string, }, - }); + }) if (dictionaryId) { await prisma.dictAndUserWords.create({ @@ -83,10 +93,10 @@ export const wordRouter = createTRPCRouter({ userWordId: userWord.id, dictionaryId, }, - }); + }) } - return successResult(true, messages.success); + return successResult(true, messages.success) }), //Whole list can be seen just by admins @@ -104,4 +114,4 @@ export const wordRouter = createTRPCRouter({ // } // }), -}); +}) diff --git a/packages/common/constants/messages.ts b/packages/common/constants/messages.ts index a1779687..995206c1 100644 --- a/packages/common/constants/messages.ts +++ b/packages/common/constants/messages.ts @@ -8,5 +8,7 @@ export default { word_not_found: "Word Couldn't Found!", - user_not_found: "User Couldn't Found!" + user_not_found: "User Couldn't Found!", + + language_not_found: "Language Couldn't Found!" } \ No newline at end of file From fcd7e6f863d94048e28139aa3a82a3e2a7a1ae36 Mon Sep 17 00:00:00 2001 From: Ali Osman Date: Thu, 20 Jul 2023 21:37:56 +0300 Subject: [PATCH 4/4] feat: update extensionn --- apps/extension/package.json | 1 - apps/extension/src/contents/translate.tsx | 4 +- .../components/DictionarySelector.tsx | 6 +- .../translate/components/FlaotingButton.tsx | 3 +- .../translate/components/LanguageSelector.tsx | 3 +- .../translate/components/TranslatePopup.tsx | 21 ++++-- .../src/features/translate/context/popover.ts | 2 + apps/extension/src/libs/trpc.ts | 4 +- .../src/options/apparence/apparance-form.tsx | 39 +++++++--- .../src/options/apparence/layout.tsx | 2 +- .../extension/src/options/settings/layout.tsx | 2 +- apps/extension/src/popup.tsx | 14 ++-- apps/extension/src/providers/index.tsx | 19 +++-- .../{options => }/providers/trpc-provider.tsx | 0 apps/extension/src/styles/globals.css | 72 ++++++++++++++++++- apps/extension/tailwind.config.js | 6 +- apps/extension/tsconfig.json | 16 +++-- packages/config/tailwind/index.ts | 1 + 18 files changed, 161 insertions(+), 54 deletions(-) rename apps/extension/src/{options => }/providers/trpc-provider.tsx (100%) diff --git a/apps/extension/package.json b/apps/extension/package.json index dd518954..90bdf7c9 100644 --- a/apps/extension/package.json +++ b/apps/extension/package.json @@ -22,7 +22,6 @@ "cors": "^2.8.5", "framer-motion": "^10.12.18", "lucide-react": "^0.257.0", - "next-themes": "^0.2.1", "plasmo": "0.80.0", "react": "18.2.0", "react-country-flag": "^3.1.0", diff --git a/apps/extension/src/contents/translate.tsx b/apps/extension/src/contents/translate.tsx index 05442c22..a9b33832 100644 --- a/apps/extension/src/contents/translate.tsx +++ b/apps/extension/src/contents/translate.tsx @@ -1,9 +1,9 @@ import FloatingButton from "~features/translate/components/FlaotingButton" import { PopoverContext, useContextPopover, usePopover } from "~features/translate/context/popover" -import "@wordigo/ui/styles/globals.css" +import "~/styles/globals.css" -import styleText from "data-text:@wordigo/ui/styles/globals.css" +import styleText from "data-text:~/styles/globals.css" import type { PlasmoCSConfig } from "plasmo" import { Fragment } from "react" diff --git a/apps/extension/src/features/translate/components/DictionarySelector.tsx b/apps/extension/src/features/translate/components/DictionarySelector.tsx index 657c072b..5daa3b18 100644 --- a/apps/extension/src/features/translate/components/DictionarySelector.tsx +++ b/apps/extension/src/features/translate/components/DictionarySelector.tsx @@ -32,7 +32,7 @@ const DictionarySelector = ({ sourceLangauge, translatedText }: { sourceLangauge name: "getToken" }) if (token) { - setShowMenu(!showMenu) + setShowMenu(true) mutate() } else { toast({ @@ -60,7 +60,7 @@ const DictionarySelector = ({ sourceLangauge, translatedText }: { sourceLangauge } return ( - +
+ diff --git a/apps/extension/src/features/translate/context/popover.ts b/apps/extension/src/features/translate/context/popover.ts index 412779d2..3393fc6b 100644 --- a/apps/extension/src/features/translate/context/popover.ts +++ b/apps/extension/src/features/translate/context/popover.ts @@ -11,6 +11,8 @@ export interface IPopoverOptions { setFloating: Dispatch> setPopup: Dispatch> setSourceLanguage: Dispatch> + test: boolean + setTest: Dispatch> selectedText?: string targetLanguage: string cordinate: { diff --git a/apps/extension/src/libs/trpc.ts b/apps/extension/src/libs/trpc.ts index e2e5b2cb..48336336 100644 --- a/apps/extension/src/libs/trpc.ts +++ b/apps/extension/src/libs/trpc.ts @@ -5,9 +5,7 @@ import superjson from "superjson" import { sendToBackground } from "@plasmohq/messaging" -function getBaseUrl() { - return `http://localhost:3000` // dev SSR should use localhost -} +const getBaseUrl = () => (process.env.NODE_ENV === "development" ? "http://localhost:3000" : "https://wordigo.app") const trpc = createTRPCReact() diff --git a/apps/extension/src/options/apparence/apparance-form.tsx b/apps/extension/src/options/apparence/apparance-form.tsx index fcebeb5b..b4342629 100644 --- a/apps/extension/src/options/apparence/apparance-form.tsx +++ b/apps/extension/src/options/apparence/apparance-form.tsx @@ -14,10 +14,11 @@ import { } from "@wordigo/ui" import { cn } from "@wordigo/ui/lib/utils" import { ChevronDownIcon } from "lucide-react" -import { useTheme } from "next-themes" import { useForm } from "react-hook-form" import * as z from "zod" +import { useStorage } from "@plasmohq/storage/hook" + const appearanceFormSchema = z.object({ theme: z.enum(["light", "dark"], { required_error: "Please select a theme." @@ -36,16 +37,17 @@ const defaultValues: Partial = { } const ApparanceForm = () => { - const theme = useTheme() + // const theme = useTheme() + const [theme, setRenderTheme, { setStoreValue }] = useStorage("theme") const form = useForm({ resolver: zodResolver(appearanceFormSchema), defaultValues }) - function onSubmit(data: AppearanceFormValues) { + async function onSubmit(data: AppearanceFormValues) { console.log(data.theme) - theme.setTheme(data.theme) + await setStoreValue(data.theme) // toast({ // title: "You submitted the following values:", @@ -91,10 +93,7 @@ const ApparanceForm = () => { Theme Select the theme for the dashboard. - + @@ -143,6 +142,30 @@ const ApparanceForm = () => { Dark + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Blue + + )} diff --git a/apps/extension/src/options/apparence/layout.tsx b/apps/extension/src/options/apparence/layout.tsx index c78df2ca..7c1af065 100644 --- a/apps/extension/src/options/apparence/layout.tsx +++ b/apps/extension/src/options/apparence/layout.tsx @@ -1,4 +1,4 @@ -import { Separator } from "~../../packages/ui" +import { Separator } from "@wordigo/ui" import ApparanceForm from "./apparance-form" diff --git a/apps/extension/src/options/settings/layout.tsx b/apps/extension/src/options/settings/layout.tsx index 7c6f2d2e..ae55c097 100644 --- a/apps/extension/src/options/settings/layout.tsx +++ b/apps/extension/src/options/settings/layout.tsx @@ -1,4 +1,4 @@ -import { Separator } from "~../../packages/ui" +import { Separator } from "@wordigo/ui" import SettingsForm from "./settings-form" diff --git a/apps/extension/src/popup.tsx b/apps/extension/src/popup.tsx index bc2d3e18..f6d307dc 100644 --- a/apps/extension/src/popup.tsx +++ b/apps/extension/src/popup.tsx @@ -1,13 +1,10 @@ -import { Portal } from "@radix-ui/react-portal" - import "@wordigo/ui/styles/globals.css" import styleText from "data-text:@wordigo/ui/styles/globals.css" -import { Toaster } from "~../../packages/ui" import TranslatePopup from "~features/popup/components/Popup" import { PopupContext, usePopup } from "~features/popup/context/popup" -import { TRPCProvider } from "~options/providers/trpc-provider" +import Provider from "~providers" export const getShadowHostId = () => "wordigo-translate-content" @@ -21,14 +18,11 @@ const Popup = () => { const popup = usePopup({}) return ( - - + - - - + - + ) } diff --git a/apps/extension/src/providers/index.tsx b/apps/extension/src/providers/index.tsx index c99f3159..10e942fd 100644 --- a/apps/extension/src/providers/index.tsx +++ b/apps/extension/src/providers/index.tsx @@ -1,18 +1,17 @@ -import { Portal } from "@radix-ui/react-portal" -import { ThemeProvider } from "next-themes" +import * as Portal from "@radix-ui/react-portal" +import { Toaster } from "@wordigo/ui" import type { PropsWithChildren } from "react" -import { Toaster } from "~../../packages/ui" -import { TRPCProvider } from "~options/providers/trpc-provider" +import { TRPCProvider } from "./trpc-provider" const Provider = ({ children }: PropsWithChildren) => { + const portalContainer = document.getElementById("el-translate-container") || document.body + return ( - - - {children} - - - + + {children} + + ) } diff --git a/apps/extension/src/options/providers/trpc-provider.tsx b/apps/extension/src/providers/trpc-provider.tsx similarity index 100% rename from apps/extension/src/options/providers/trpc-provider.tsx rename to apps/extension/src/providers/trpc-provider.tsx diff --git a/apps/extension/src/styles/globals.css b/apps/extension/src/styles/globals.css index bd6213e1..14231f34 100644 --- a/apps/extension/src/styles/globals.css +++ b/apps/extension/src/styles/globals.css @@ -1,3 +1,73 @@ @tailwind base; @tailwind components; -@tailwind utilities; \ No newline at end of file +@tailwind utilities; + +@layer base { + [data-theme="light"] { + --background: 0 0% 100%; + --foreground: 222.2 84% 4.9%; + + --muted: 210 40% 96.1%; + --muted-foreground: 215.4 16.3% 46.9%; + + --popover: 0 0% 100%; + --popover-foreground: 222.2 84% 4.9%; + + --card: 0 0% 100%; + --card-foreground: 222.2 84% 4.9%; + + --border: 214.3 31.8% 91.4%; + --input: 214.3 31.8% 91.4%; + + --primary: 222.2 47.4% 11.2%; + --primary-foreground: 210 40% 98%; + + --secondary: 210 40% 96.1%; + --secondary-foreground: 222.2 47.4% 11.2%; + + --accent: 210 40% 96.1%; + --accent-foreground: ; + + --destructive: 0 84.2% 60.2%; + --destructive-foreground: 210 40% 98%; + + --ring: 215 20.2% 65.1%; + + --radius: 0.5rem; + } + + [data-theme="dark"] { + --background: 222.2 84% 4.9%; + --foreground: 210 40% 98%; + + --muted: 217.2 32.6% 17.5%; + --muted-foreground: 215 20.2% 65.1%; + + --popover: 222.2 84% 4.9%; + --popover-foreground: 210 40% 98%; + + --card: 222.2 84% 4.9%; + --card-foreground: 210 40% 98%; + + --border: 217.2 32.6% 17.5%; + --input: 217.2 32.6% 17.5%; + + --primary: 210 40% 98%; + --primary-foreground: 222.2 47.4% 11.2%; + + --secondary: 217.2 32.6% 17.5%; + --secondary-foreground: 210 40% 98%; + + --accent: 217.2 32.6% 17.5%; + --accent-foreground: ; + + --destructive: 0 62.8% 30.6%; + --destructive-foreground: 0 85.7% 97.3%; + + --ring: 217.2 32.6% 17.5%; + } +} + +#plasmo-shadow-container { + z-index: 2147483646 !important; +} \ No newline at end of file diff --git a/apps/extension/tailwind.config.js b/apps/extension/tailwind.config.js index dc3cc4aa..c9953397 100644 --- a/apps/extension/tailwind.config.js +++ b/apps/extension/tailwind.config.js @@ -1 +1,5 @@ -module.exports = require('@wordigo/tailwind-config') \ No newline at end of file +module.exports = { + ...require('@wordigo/tailwind-config'), + mode: 'jit', + darkMode: "[data-theme]" +} \ No newline at end of file diff --git a/apps/extension/tsconfig.json b/apps/extension/tsconfig.json index d3ad826f..6acf340d 100644 --- a/apps/extension/tsconfig.json +++ b/apps/extension/tsconfig.json @@ -1,11 +1,19 @@ { "extends": "plasmo/templates/tsconfig.base", - "exclude": ["node_modules"], - "include": [".plasmo/index.d.ts", "./**/*.ts", "./**/*.tsx"], + "exclude": [ + "node_modules" + ], + "include": [ + ".plasmo/index.d.ts", + "./**/*.ts", + "./**/*.tsx" + ], "compilerOptions": { "paths": { - "~*": ["./*"] + "~*": [ + "./src/*" + ] }, "baseUrl": "." } -} +} \ No newline at end of file diff --git a/packages/config/tailwind/index.ts b/packages/config/tailwind/index.ts index 8424b3cf..4f21845e 100644 --- a/packages/config/tailwind/index.ts +++ b/packages/config/tailwind/index.ts @@ -4,6 +4,7 @@ export default { darkMode: ["class"], content: [ "./src/app/**/*.{ts,tsx}", + "./src/**/*.{ts,tsx}", "./**/**/**/*.{ts,tsx}", "./**/*.{ts,tsx}", "./*.{ts,tsx}",