Skip to content

Commit

Permalink
refactor(web): move strings for uuid-url-input to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
elbotho committed Jan 9, 2025
1 parent cfa30e7 commit 287b27e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
30 changes: 18 additions & 12 deletions apps/web/src/components/author/uuid-url-input.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 (
<div className="my-4 border-t-2 pt-5">
<input
className="serlo-input-font-reset w-72 rounded-xl bg-editor-primary-200 p-2 font-bold placeholder-almost-black outline-none placeholder:font-normal focus:bg-editor-primary"
placeholder={modalStrings.placeholder}
placeholder={uuidToolStrings.placeholder}
onChange={(event) => {
if (event.target.value.length === 0) {
setMaybeUuid(null)
Expand All @@ -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

Expand All @@ -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 (
<>
Expand Down
11 changes: 11 additions & 0 deletions apps/web/src/data/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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%',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
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'

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'
Expand All @@ -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) {
Expand All @@ -47,7 +50,7 @@ export function ArticleRelatedTaxonomy({

return (
<div className="mt-5 border-t-2 pt-6">
{articleStrings.addModal.addFromFolderTitle}
{uuidToolStrings.addFromFolderTitle}
<a
className="ml-2 font-bold text-brand"
target="_blank"
Expand Down Expand Up @@ -76,7 +79,7 @@ export function ArticleRelatedTaxonomy({
? strings.entities.exerciseFolder
: strings.categories[getCategoryByTypename(typename)]}
</b>
{isTax ? articleStrings.addModal.exerciseFolderNote : null}
{isTax ? uuidToolStrings.exerciseFolderNote : null}
<ul>{dataArray.map((item) => renderLi(item, typename))}</ul>
</div>
)
Expand Down
11 changes: 0 additions & 11 deletions packages/editor/src/i18n/strings/de/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
9 changes: 0 additions & 9 deletions packages/editor/src/i18n/strings/en/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 287b27e

Please sign in to comment.