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` +}