diff --git a/.prettierignore b/.prettierignore index 1640ee12..83721165 100644 --- a/.prettierignore +++ b/.prettierignore @@ -4,3 +4,4 @@ src/assets/css/themes/*.css src/assets/css/code-themes/*.css stats.json dist +pnpm-lock.yaml \ No newline at end of file diff --git a/lemmy-translations b/lemmy-translations index 9a8a86ea..b0dab329 160000 --- a/lemmy-translations +++ b/lemmy-translations @@ -1 +1 @@ -Subproject commit 9a8a86ea2edbd0ebed98f649805e69431b692dab +Subproject commit b0dab329ce23cfaec4a3a034ea2fee210888922e diff --git a/src/shared/components/common/url-list-textarea.tsx b/src/shared/components/common/url-list-textarea.tsx new file mode 100644 index 00000000..7e6972f9 --- /dev/null +++ b/src/shared/components/common/url-list-textarea.tsx @@ -0,0 +1,77 @@ +import { linkEvent, Component } from "inferno"; +import { I18NextService } from "../../services/I18NextService"; + +interface UrlListTextareaProps { + urls: string[]; + onUpdate(urls: string[]): void; +} + +interface UrlListTextareaState { + text: string; +} + +function handleTextChange(i: UrlListTextarea, event: any) { + i.setState({ text: event.target.value }); +} + +function handleTextBlur(i: UrlListTextarea, event: any) { + const inputValue: string = event.currentTarget?.value ?? ""; + + const intermediateText = inputValue.replace(/\s+/g, "\n"); + const newUrls: string[] = []; + + for (const str of intermediateText.split("\n")) { + let url: string; + + try { + url = new URL(str).toString(); + } catch { + try { + url = new URL("https://" + str).toString(); + } catch { + continue; + } + } + + if (newUrls.every(u => u !== url)) { + newUrls.push(url); + } + } + + i.setState({ text: newUrls.join("\n") }); + i.props.onUpdate(newUrls); +} + +export default class UrlListTextarea extends Component< + UrlListTextareaProps, + UrlListTextareaState +> { + state: UrlListTextareaState = { + text: "", + }; + + render() { + return ( +
+ + +
+