From 287b27edc14dae3f966727682a2dce9869a31e49 Mon Sep 17 00:00:00 2001 From: Botho <1258870+elbotho@users.noreply.github.com> Date: Thu, 9 Jan 2025 17:09:31 +0100 Subject: [PATCH] refactor(web): move strings for uuid-url-input to frontend --- .../src/components/author/uuid-url-input.tsx | 30 +++++++++++-------- apps/web/src/data/en/index.ts | 11 +++++++ .../article-related-taxonomy.tsx | 11 ++++--- packages/editor/src/i18n/strings/de/edit.ts | 11 ------- packages/editor/src/i18n/strings/en/edit.ts | 9 ------ 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/apps/web/src/components/author/uuid-url-input.tsx b/apps/web/src/components/author/uuid-url-input.tsx index fbba1bfa18..baa2827701 100644 --- a/apps/web/src/components/author/uuid-url-input.tsx +++ b/apps/web/src/components/author/uuid-url-input.tsx @@ -1,10 +1,10 @@ -import { useEditStrings } from '@editor/i18n/edit-strings-provider' import { gql } from 'graphql-request' import { useState } from 'react' import { FaIcon } from '../fa-icon' import { useGraphqlSwr } from '@/api/use-graphql-swr' import { useInstanceData } from '@/contexts/instance-context' +import { useLoggedInData } from '@/contexts/logged-in-data-context' import { UuidType, UuidWithRevType } from '@/data-types' import { TaxonomyTermType, @@ -38,13 +38,16 @@ export function UuidUrlInput({ const { data, error } = useSimpleUuidFetch(maybeUuid) const { strings } = useInstanceData() - const modalStrings = useEditStrings().templatePlugins.article.addModal + const loggedInData = useLoggedInData() + + if (!loggedInData) return null + const uuidToolStrings = loggedInData.strings.uuidUrlInput return (
{ if (event.target.value.length === 0) { setMaybeUuid(null) @@ -69,16 +72,16 @@ export function UuidUrlInput({ function renderFeedback() { if (maybeUuid === null) return null - if (maybeUuid === false) return modalStrings.invalidInput + if (maybeUuid === false) return uuidToolStrings.invalidInput if (error) { // eslint-disable-next-line no-console console.error(error) - return modalStrings.fetchError + return uuidToolStrings.fetchError } - if (!data) return modalStrings.loading + if (!data) return uuidToolStrings.loading const { uuid } = data - if (!uuid) return modalStrings.notFound + if (!uuid) return uuidToolStrings.notFound const { __typename: typename, id } = uuid @@ -90,18 +93,21 @@ export function UuidUrlInput({ Object.hasOwn(uuid, 'type') && uuid.type ? uuid.type : undefined if (!supportedEntityTypes.includes(typename as UuidWithRevType)) - return modalStrings.unsupportedType.replace('%type%', typename) + return uuidToolStrings.unsupportedType.replace('%type%', typename) if (taxonomyType && !supportedTaxonomyTypes.includes(taxonomyType)) - return modalStrings.unsupportedType.replace('%type%', taxonomyType ?? '') + return uuidToolStrings.unsupportedType.replace( + '%type%', + taxonomyType ?? '' + ) if (unsupportedIds && unsupportedIds.includes(id)) - return modalStrings.unsupportedId + return uuidToolStrings.unsupportedId - if (!id) return modalStrings.notFound + if (!id) return uuidToolStrings.notFound if (!typename.includes(UuidType.Exercise) && !title) - return modalStrings.notFound + return uuidToolStrings.notFound return ( <> diff --git a/apps/web/src/data/en/index.ts b/apps/web/src/data/en/index.ts index dae373abd2..84f11a0149 100644 --- a/apps/web/src/data/en/index.ts +++ b/apps/web/src/data/en/index.ts @@ -696,6 +696,17 @@ export const loggedInData = { saveButtonText: 'Save order', }, }, + uuidUrlInput: { + invalidInput: 'Invalid id or url', + fetchError: 'Something went wrong, please try later', + loading: 'Loading…', + notFound: 'Could not find that content', + unsupportedType: 'Sorry, type [%type%] is not supported here', + unsupportedId: 'Sorry, this ID is not supported here', + addFromFolderTitle: 'From the folder', + placeholder: 'Paste Serlo ID or URL here', + exerciseFolderNote: 'Only one can be selected here', + }, roles: { addButton: 'Add as %role%', }, diff --git a/apps/web/src/serlo-editor-integration/components/article-add-modal/article-related-taxonomy.tsx b/apps/web/src/serlo-editor-integration/components/article-add-modal/article-related-taxonomy.tsx index 4fa0e32dae..c635064f25 100644 --- a/apps/web/src/serlo-editor-integration/components/article-add-modal/article-related-taxonomy.tsx +++ b/apps/web/src/serlo-editor-integration/components/article-add-modal/article-related-taxonomy.tsx @@ -1,4 +1,3 @@ -import { useEditStrings } from '@editor/i18n/edit-strings-provider' import { SerloAddButton } from '@editor/plugin/helpers/serlo-editor-button' import { faSearch } from '@fortawesome/free-solid-svg-icons' import { gql } from 'graphql-request' @@ -6,6 +5,7 @@ import { gql } from 'graphql-request' import { useGraphqlSwr } from '@/api/use-graphql-swr' import { FaIcon } from '@/components/fa-icon' import { useInstanceData } from '@/contexts/instance-context' +import { useLoggedInData } from '@/contexts/logged-in-data-context' import { useEntityData } from '@/contexts/uuids-context' import { UuidType, type UuidWithRevType } from '@/data-types' import { TaxonomyTermType } from '@/fetcher/graphql-types/operations' @@ -28,7 +28,10 @@ export function ArticleRelatedTaxonomy({ const { data, error } = useFetchParentTaxonomy(entityId ?? 0) const { strings } = useInstanceData() - const articleStrings = useEditStrings().templatePlugins.article + const loggedInData = useLoggedInData() + + if (!loggedInData) return null + const uuidToolStrings = loggedInData.strings.uuidUrlInput const dataAndTerm = getCategorisedDataAndTerm(data, error) if (!dataAndTerm || !entityId) { @@ -47,7 +50,7 @@ export function ArticleRelatedTaxonomy({ return (
- {articleStrings.addModal.addFromFolderTitle} + {uuidToolStrings.addFromFolderTitle} - {isTax ? articleStrings.addModal.exerciseFolderNote : null} + {isTax ? uuidToolStrings.exerciseFolderNote : null}
    {dataArray.map((item) => renderLi(item, typename))}
) diff --git a/packages/editor/src/i18n/strings/de/edit.ts b/packages/editor/src/i18n/strings/de/edit.ts index 00fd704e99..77cd4256e7 100644 --- a/packages/editor/src/i18n/strings/de/edit.ts +++ b/packages/editor/src/i18n/strings/de/edit.ts @@ -450,17 +450,6 @@ export const editStrings = { buttonContent: 'Inhalt hinzufügen', buttonAddType: '%type% hinzufügen', title: 'Weiterführende Inhalte oder Übungsaufgaben hinzufügen', - invalidInput: 'Ungültige ID oder URL', - fetchError: - 'Etwas ist schief gelaufen, bitte versuche es später noch einmal', - loading: 'Wird geladen …', - notFound: 'Inhalt konnte nicht gefunden werden', - unsupportedType: 'Sorry, der Typ [%type%] wird hier nicht unterstützt', - unsupportedId: - 'Sorry, diese ID ist hier nicht erlaubt. (z.B. weil sie schon ausgewählt ist, oder weil du diese ID bearbeitest…)', - addFromFolderTitle: 'Aus dem Ordner', - placeholder: 'Eine Serlo Id oder URL hier einfügen', - exerciseFolderNote: 'Hier kann nur ein Ordner ausgewählt werden', }, }, course: { diff --git a/packages/editor/src/i18n/strings/en/edit.ts b/packages/editor/src/i18n/strings/en/edit.ts index 3c25deed67..ef27663c85 100644 --- a/packages/editor/src/i18n/strings/en/edit.ts +++ b/packages/editor/src/i18n/strings/en/edit.ts @@ -439,15 +439,6 @@ export const editStrings = { buttonContent: 'Add content', buttonAddType: 'Add %type%', title: 'Add related Content or Exercises', - invalidInput: 'Invalid id or url', - fetchError: 'Something went wrong, please try later', - loading: 'Loading…', - notFound: 'Could not find that content', - unsupportedType: 'Sorry, type [%type%] is not supported here', - unsupportedId: 'Sorry, this ID is not supported here', - addFromFolderTitle: 'From the folder', - placeholder: 'Paste Serlo ID or URL here', - exerciseFolderNote: 'Only one can be selected here', }, }, course: {