Skip to content

Commit

Permalink
Frontend imprevements.
Browse files Browse the repository at this point in the history
  • Loading branch information
iberdinsky-skilld committed Jul 31, 2024
1 parent ec33fb0 commit 023e7bf
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
Binary file modified client/public/favicon.ico
Binary file not shown.
49 changes: 49 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import routerBindings, {
DocumentTitleHandler,
UnsavedChangesNotifier,
} from '@refinedev/react-router-v6'
import { useEffect } from 'react'
import {
BrowserRouter,
Navigate,
Expand All @@ -24,10 +25,58 @@ import { ActionList, ActionShow } from './pages/actions'
import { FlowShow } from './pages/flow'
import { dataProvider as launchrDataProvider } from './rest-data-provider'
import { ThemeProvider } from './ThemeProvider'
import { svgToBase64 } from './utils/helpers'

const apiUrl = import.meta.env.VITE_API_URL

const fetchData = async () => {
const response = await fetch(`${apiUrl}/customisation`, {
method: 'GET',
})
const data = await response.json()
if (data?.plasmactl_web_ui_platform_favicon) {
const base64Favicon = svgToBase64(data.plasmactl_web_ui_platform_favicon)
sessionStorage.setItem('plasmactl_web_ui_platform_favicon', base64Favicon)
setFavicon(base64Favicon)

sessionStorage.setItem(
'plasmactl_web_ui_platform_logo',
data?.plasmactl_web_ui_platform_logo
)
}
if (data?.plasmactl_web_ui_platform_logo) {
const base64Logo = svgToBase64(data.plasmactl_web_ui_platform_logo)
sessionStorage.setItem('plasmactl_web_ui_platform_logo', base64Logo)
}

if (data?.plasmactl_web_ui_platform_name) {
sessionStorage.setItem(
'plasmactl_web_ui_platform_name',
data?.plasmactl_web_ui_platform_name
)
}
}

const setFavicon = (faviconUrl: string) => {
const link: HTMLLinkElement =
(document.querySelector("link[rel*='icon']") as HTMLLinkElement) ||
(document.createElement('link') as HTMLLinkElement)
link.type = 'image/svg+xml'
link.rel = 'icon'
link.href = faviconUrl
document.getElementsByTagName('head')[0].append(link)
}

export function App() {
useEffect(() => {
const favicon = sessionStorage.getItem('plasmactl_web_ui_platform_favicon')
if (favicon) {
setFavicon(favicon)
} else {
fetchData()
}
}, [])

return (
<AppProvider>
<ActionProvider>
Expand Down
10 changes: 8 additions & 2 deletions client/src/components/layout/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,22 @@ export const ThemedTitleV2: FC<RefineLayoutThemedTitleProps> = ({
...wrapperStyles,
}}
>
<img src={Logo} width="24" height="24" alt={t('Logo')} />
<img
src={sessionStorage.getItem('plasmactl_web_ui_platform_logo') || Logo}
width="24"
height="24"
alt={t('Logo')}
/>
<Typography
variant="h5"
fontWeight={700}
color="text.primary"
fontSize="15px"
textOverflow="ellipsis"
overflow="hidden"
sx={{ textTransform: 'uppercase' }}
>
{text}
{sessionStorage.getItem('plasmactl_web_ui_platform_name') || text}
</Typography>
</MuiLink>
)
Expand Down
9 changes: 9 additions & 0 deletions client/src/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ export const extractDateTimeFromId = (id: string) => {

return formattedDate
}

export const svgToBase64 = (svg: string) => {
const base64 = btoa(
encodeURIComponent(svg).replaceAll(/%([\dA-F]{2})/g, (_, p1) =>
String.fromCodePoint(Number.parseInt(p1, 16))
)
)
return `data:image/svg+xml;base64,${base64}`
}
6 changes: 5 additions & 1 deletion client/src/utils/react-flow-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,11 @@ export const getNodesAndEdges = (

const nodes: IFolder = {
id: 'start',
data: { label: 'Platform name' },
data: {
label:
sessionStorage.getItem('plasmactl_web_ui_platform_name') ||
'Platform name',
},
type: 'node-start',
folders: {},
actions: {},
Expand Down

0 comments on commit 023e7bf

Please sign in to comment.