Skip to content

Commit

Permalink
refactor: consolidate builder utils funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Mar 6, 2024
1 parent 5621a81 commit d84c436
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/features/builder/Motd.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import { useLayoutStore } from '@store/useLayoutStore'
import { useStorage } from '@store/useStorage'
import { CUSTOM_COMPONENT, MOTD_CHECK } from '@services/queries/config'
import { Loading } from '@components/Loading'
import { getBlockContent } from '@utils/getBlockContent'

import { CustomTile } from './components/CustomTile'
import { CustomDialog } from './components/CustomDialog'
import { getBlockContent } from './utils'

const DEFAULT =
/** @type {import('@rm/types').Config['map']['messageOfTheDay']} */ ({
Expand Down
3 changes: 2 additions & 1 deletion src/features/builder/components/CustomDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { useTranslation } from 'react-i18next'

import { Header } from '@components/dialogs/Header'
import { Footer } from '@components/dialogs/Footer'
import { getBlockContent } from '@utils/getBlockContent'

import { getBlockContent } from '../utils'

export function CustomDialog({
configObj,
Expand Down
3 changes: 1 addition & 2 deletions src/features/builder/components/CustomTile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import * as React from 'react'
import Grid from '@mui/material/Unstable_Grid2'

import { getGridSizes } from '@utils/getGridSizes'

import { Generator } from './Generator'
import { getGridSizes } from '../utils'

/**
*
Expand Down
3 changes: 1 addition & 2 deletions src/features/builder/components/Generator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ import { LocalLogin } from '@components/auth/Local'
import { TelegramWidget } from '@components/auth/Telegram'
import { Img } from '@components/Img'
import { LocaleSelection } from '@components/inputs/LocaleSelection'
import { getBlockContent } from '@utils/getBlockContent'
import { getGridSizes } from '@utils/getGridSizes'

import { LinkWrapper } from './LinkWrapper'
import { CustomText } from './CustomText'
import { CustomButton } from './CustomButton'
import { getGridSizes, getBlockContent } from '../utils'

/**
*
Expand Down
13 changes: 13 additions & 0 deletions src/utils/getGridSizes.js → src/features/builder/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// @ts-check

/**
*
* @param {string | Record<string, string>} content
* @returns
*/
export function getBlockContent(content) {
if (!content) return ''
if (typeof content === 'string') return content
return typeof content === 'object'
? content[localStorage.getItem('i18nextLng')] || Object.values(content)[0]
: ''
}

/** @param {import("@rm/types").GridSizes} sizeObj */
export function getGridSizes(sizeObj) {
return {
Expand Down
14 changes: 0 additions & 14 deletions src/utils/getBlockContent.js

This file was deleted.

0 comments on commit d84c436

Please sign in to comment.