-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: language and new book forms
- Loading branch information
Showing
8 changed files
with
204 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
frontend/src/features/book/components/NewBookForm/components/ImportURLInfoPopup.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ActionIcon, Paper, Popover, rem } from "@mantine/core"; | ||
import { IconQuestionMark } from "@tabler/icons-react"; | ||
|
||
function ImportURLInfoPopup() { | ||
return ( | ||
<Popover position="top" withArrow shadow="sm"> | ||
<Popover.Target> | ||
<ActionIcon variant="transparent"> | ||
<IconQuestionMark /> | ||
</ActionIcon> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<Paper maw={500} fz="sm"> | ||
<p style={{ marginBottom: rem(5) }}> | ||
This import is very primitive -- it grabs <em>all</em> the headings | ||
and text from an HTML page. | ||
</p> | ||
<p> | ||
This will likely include stuff you don't want. You are able to | ||
edit the resulting text | ||
</p> | ||
</Paper> | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
} | ||
|
||
export default ImportURLInfoPopup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useForm } from "@mantine/form"; | ||
import { getFormDataFromObj } from "@actions/utils"; | ||
|
||
function useNewBookForm(langId) { | ||
const form = useForm({ | ||
initialValues: { | ||
language_id: "", | ||
title: "", | ||
text: "", | ||
importurl: "", | ||
text_file: undefined, | ||
audio_file: undefined, | ||
threshold_page_tokens: 250, | ||
split_by: "paragraphs", | ||
source_uri: "", | ||
book_tags: [], | ||
}, | ||
transformValues: (values) => { | ||
const data = { | ||
...values, | ||
language_id: Number(langId), | ||
}; | ||
|
||
return getFormDataFromObj(data); | ||
}, | ||
}); | ||
|
||
return form; | ||
} | ||
|
||
export default useNewBookForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useForm } from "@mantine/form"; | ||
import { randomId } from "@mantine/hooks"; | ||
|
||
function useLanguageForm() { | ||
const form = useForm({ | ||
mode: "uncontrolled", | ||
initialValues: { | ||
character_substitutions: "´='|`='|’='|‘='|...=…|..=‥", | ||
split_sentences: ".!?", | ||
split_sentence_exceptions: "Mr.|Mrs.|Dr.|[A-Z].|Vd.|Vds.", | ||
word_chars: "a-zA-ZÀ-ÖØ-öø-ȳáéíóúÁÉÍÓÚñÑ", | ||
right_to_left: false, | ||
show_romanization: false, | ||
parser_type: "spacedel", | ||
// minimum dictionaries should be defined on backend with other settings | ||
dictionaries: [ | ||
{ | ||
for: "terms", | ||
type: "embedded", | ||
url: "", | ||
active: true, | ||
key: randomId(), | ||
}, | ||
{ | ||
for: "sentences", | ||
type: "popup", | ||
url: "", | ||
active: true, | ||
key: randomId(), | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
return form; | ||
} | ||
|
||
export default useLanguageForm; |
36 changes: 36 additions & 0 deletions
36
frontend/src/features/language/hooks/useSelectedLanguage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useSearchParams } from "react-router-dom"; | ||
import { | ||
predefinedLanguageQuery, | ||
userLanguageQuery, | ||
} from "@language/api/query"; | ||
|
||
function useSelectedLanguage() { | ||
const [params] = useSearchParams(); | ||
const langId = params.get("langId"); | ||
const predefinedSelected = langId === "0"; | ||
const userSelected = langId && langId !== "0"; | ||
|
||
const { data: predefinedLang, isSuccess: predefSuccess } = useQuery( | ||
predefinedLanguageQuery(params.get("name", null)) | ||
); | ||
const { data: userLang, isSuccess: userSuccess } = useQuery( | ||
userLanguageQuery(langId) | ||
); | ||
|
||
const language = predefinedSelected | ||
? predefinedLang | ||
: userSelected | ||
? userLang | ||
: null; | ||
|
||
const isSuccess = predefinedSelected | ||
? predefSuccess | ||
: userSelected | ||
? userSuccess | ||
: false; | ||
|
||
return { language, isSuccess }; | ||
} | ||
|
||
export default useSelectedLanguage; |
Oops, something went wrong.