diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 0000000..92743fe --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,32 @@ +name: 'Linting' + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + cargo-check: + strategy: + fail-fast: false + matrix: + include: + - platform: 'macos-latest' + args: '--target aarch64-apple-darwin' + - platform: 'windows-latest' + args: '' + + runs-on: ${{ matrix.platform }} + steps: + - uses: actions/checkout@v4 + + - name: Install Rust stable + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin' || '' }} + + - name: Run Cargo check + run: | + cd src-tauri + cargo check \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f19b493..c5b242d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,8 +17,6 @@ jobs: include: - platform: 'macos-latest' # for Arm based macs (M1 and above). args: '--target aarch64-apple-darwin' - - platform: 'macos-latest' # for Intel based macs. - args: '--target x86_64-apple-darwin' - platform: 'windows-latest' args: '' diff --git a/src/app/page.tsx b/src/app/page.tsx index bfa9df0..a91cc0b 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,7 +1,7 @@ "use client"; import { invoke } from "@tauri-apps/api/core"; -import { Select, SelectItem } from "@nextui-org/react"; +import { button, Select, SelectItem } from "@nextui-org/react"; import { listen } from "@tauri-apps/api/event"; import { TextInput } from "./sections/input"; import { Result } from "./sections/result"; @@ -11,7 +11,9 @@ import { BottomBar } from "./sections/bottomBar"; import { SettingContext } from "./providers/settings"; import { FaRegArrowAltCircleRight } from "react-icons/fa"; import { IoStopCircleOutline } from "react-icons/io5"; +import { HiSwitchHorizontal } from "react-icons/hi"; import { AppSettings } from "./types/settings"; +import { Tabs, Tab } from "@nextui-org/react"; async function tauri_get_result( text: string, @@ -105,46 +107,58 @@ const LanguageSelections = ({ selectedLang?: LanguageConfig; changeLangConfig: (lang: LanguageConfig) => void; }) => { - // const sourceLangues = [ - // { value: "en", label: "English" }, - // { value: "es", label: "Spanish" }, - // { value: "fr", label: "French" }, - // ]; const targetLangues = [ { value: "vi", label: "Tiếng Việt" }, { value: "en", label: "English" }, ]; + const handleLanguageSwitch = () => { + if (selectedLang) { + const newConfig = { + sourceLang: selectedLang.targetLang, + targetLang: selectedLang.sourceLang, + }; + changeLangConfig(newConfig); + } + }; + return (

Output language:

- +
+ + +
); }; @@ -158,6 +172,21 @@ export default function Home() { homeContext.changeInputText(text); }, []); + const data = [ + { + title: "Translate", + content: homeContext.result?.translate ?? "", + }, + { + title: "Correct", + content: homeContext.result?.correct ?? "", + }, + { + title: "Refine", + content: homeContext.result?.refine ?? "", + }, + ]; + useEffect(() => { startSerialEventListener(); }, []); @@ -218,22 +247,35 @@ export default function Home() { }; }, [homeContext, appSettings]); + const handleModeChange = useCallback((key: string | number) => { + const index = typeof key === 'string' ? parseInt(key, 10) : key; + const newMode = data[index].title as Mode; + homeContext.setCurrentMode(newMode); + if (homeContext.inputText && homeContext.inputText.trim() !== '') { + // Use the new mode directly in the triggerTranslation call + triggerTranslation({ ...homeContext, currentMode: newMode }, appSettings); + } + }, [homeContext, appSettings]); + return (
- -
- -
+ + {data.map((item, index) => ( + + + + ))} +
-
+
{homeContext.translating ? ( void; +}) => { + const targetLanguages = [ + { value: "vi", label: "Tiếng Việt" }, + { value: "en", label: "English" }, + ]; + + const handleLanguageSwitch = () => { + if (selectedLang) { + const newConfig = { + sourceLang: selectedLang.targetLang, + targetLang: selectedLang.sourceLang, + }; + changeLangConfig(newConfig); + } + }; + + return ( +
+
+ + +
+
+ ); +}; + +export { LanguageSelections }; diff --git a/src/app/sections/result.tsx b/src/app/sections/result.tsx index 2b6a5a9..0293750 100644 --- a/src/app/sections/result.tsx +++ b/src/app/sections/result.tsx @@ -12,6 +12,7 @@ import { import { LuClipboardCopy } from "react-icons/lu"; import { TranslateContext } from "../providers/translate"; import { MdClear } from "react-icons/md"; +import { LanguageSelections } from "./language-selection"; const TextCard = ({ title, @@ -89,40 +90,25 @@ const Result = ({ mode?: Mode; }) => { const homeContext = useContext(TranslateContext); - const data = [ - { - title: "Translate", - content: result?.translate ?? "", - }, - { - title: "Correct", - content: result?.correct ?? "", - }, - { - title: "Refine", - content: result?.refine ?? "", - }, - ]; + + console.log("Result:", result); + console.log("Mode", mode); + + // Result: { translate: 'Hello', correct: '', refine: '' } + console.log("Text",); + return (
- { - const mode = data[index as number].title as Mode; - homeContext.setCurrentMode(mode); - }} - > - {data.map((item, index) => ( - - - - ))} - + +
); };