From 96d9a012ee3aa49584ff013b5ce0a6537afa2f5e Mon Sep 17 00:00:00 2001 From: Anastasiia Date: Sat, 27 Apr 2024 15:03:35 +0300 Subject: [PATCH] MSP-3237 add UIUtils in utils --- src/pages/ProfilePage/profile-page.type.ts | 11 +++++++++ src/utils/UIUtiles.tsx | 26 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/utils/UIUtiles.tsx diff --git a/src/pages/ProfilePage/profile-page.type.ts b/src/pages/ProfilePage/profile-page.type.ts index 03aff61..8bb4565 100644 --- a/src/pages/ProfilePage/profile-page.type.ts +++ b/src/pages/ProfilePage/profile-page.type.ts @@ -15,3 +15,14 @@ export type ProfileType = { status: StateProfileStatus error: string } + +export type UIDataType = { + name: string + primaryColor: string +} + +export type UIType = { + ui: UIDataType + status: StateProfileStatus + error: string +} diff --git a/src/utils/UIUtiles.tsx b/src/utils/UIUtiles.tsx new file mode 100644 index 0000000..317ab96 --- /dev/null +++ b/src/utils/UIUtiles.tsx @@ -0,0 +1,26 @@ +import { UIDataType } from '@pages/ProfilePage/profile-page.type.ts' + +const drawSVG = (color: string) => + `` + +export const createSVG = (color: string) => { + const svgString = drawSVG(color) + return btoa(svgString) // base64 +} + +export const initSVG = (color: string) => { + const favicon = document.createElement('link') + favicon.id = 'favicon' + favicon.rel = 'shortcut icon' + favicon.type = 'image/x-icon' + favicon.href = `data:image/svg+xml;base64,${createSVG(color)}` + return favicon +} + +export const initUI = (ui: UIDataType) => { + let favicon = document.getElementById('favicon') + favicon = initSVG(ui.primaryColor) + const titles = document.getElementsByTagName('title') + document.head.insertBefore(favicon, titles[0]) + document.title = `${ui.name} — MSP` +}