@taruvi/navkit 0.0.39 → 0.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/App.tsx +8 -7
- package/src/NavkitContext.tsx +11 -6
- package/src/types.ts +1 -0
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -13,8 +13,9 @@ import taruviLogoWhite from "./assets/taruvi-logo-white.png";
|
|
|
13
13
|
import type { Client } from "@taruvi/sdk"
|
|
14
14
|
|
|
15
15
|
const NavkitContent = () => {
|
|
16
|
-
const { isUserAuthenticated, siteSettings, appSettings, appName, userData, jwtToken, themeMode } = useNavigation();
|
|
17
|
-
const
|
|
16
|
+
const { isUserAuthenticated, siteSettings, appSettings, appSettingsLoaded, appName, userData, jwtToken, themeMode } = useNavigation();
|
|
17
|
+
const resolvedAppName = appName || appSettings?.displayName
|
|
18
|
+
const showTaruviLogo = appSettingsLoaded && !resolvedAppName && !appSettings?.icon
|
|
18
19
|
const styles = getAppStyles(themeMode)
|
|
19
20
|
const [showAppLauncher, setShowAppLauncher] = useState<boolean>(false)
|
|
20
21
|
const [showProfileMenu, setShowProfileMenu] = useState<boolean>(false)
|
|
@@ -39,16 +40,16 @@ const NavkitContent = () => {
|
|
|
39
40
|
<Box component={"a"} href="/" sx={styles.leftSection}>
|
|
40
41
|
{showTaruviLogo ? (
|
|
41
42
|
<Box component="img" src={taruviLogoWhite} sx={styles.taruviSpaceLogo} />
|
|
42
|
-
) : (
|
|
43
|
+
) : appSettingsLoaded ? (
|
|
43
44
|
<>
|
|
44
45
|
{appSettings?.icon ? <Box component="img" src={appSettings?.icon} sx={styles.logo} /> : <></>}
|
|
45
|
-
{
|
|
46
|
+
{resolvedAppName &&
|
|
46
47
|
<Typography sx={styles.appName} onClick={() => (window.location.href = "/")}>
|
|
47
|
-
{
|
|
48
|
+
{resolvedAppName.length > 40 ? `${resolvedAppName.substring(0, 40)}...` : resolvedAppName}
|
|
48
49
|
</Typography>
|
|
49
50
|
}
|
|
50
51
|
</>
|
|
51
|
-
)}
|
|
52
|
+
) : null}
|
|
52
53
|
</Box>
|
|
53
54
|
<Box component={"div"} sx={styles.rightSection}>
|
|
54
55
|
<Shortcuts showChat={setShowChat} onMenuToggle={() => setShowShortcutsMenu(!showShortcutsMenu)} />
|
|
@@ -130,4 +131,4 @@ const Navkit = ({ client, getTheme, appName }: NavkitProps) => {
|
|
|
130
131
|
)
|
|
131
132
|
}
|
|
132
133
|
|
|
133
|
-
export default Navkit
|
|
134
|
+
export default Navkit
|
package/src/NavkitContext.tsx
CHANGED
|
@@ -31,7 +31,8 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName }: Nav
|
|
|
31
31
|
frontendUrl: '',
|
|
32
32
|
enableDarkMode: false,
|
|
33
33
|
})
|
|
34
|
-
const appSettings =
|
|
34
|
+
const [appSettings, setAppSettings] = useState<AppSettings>({})
|
|
35
|
+
const [appSettingsLoaded, setAppSettingsLoaded] = useState<boolean>(false)
|
|
35
36
|
|
|
36
37
|
const [isDesk, setIsDesk] = useState<boolean>(false)
|
|
37
38
|
const [appsList, setAppsList] = useState<AppData[]>([])
|
|
@@ -86,15 +87,19 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName }: Nav
|
|
|
86
87
|
|
|
87
88
|
// Fetch app settings to get the app name
|
|
88
89
|
try {
|
|
90
|
+
setAppSettingsLoaded(false)
|
|
89
91
|
const { data } = appName ? { data: { display_name: appName } } : await new App(client).settings().execute() as { data: { display_name?: string, icon?: string, primary_color?: string, secondary_color?: string } }
|
|
90
|
-
|
|
92
|
+
setAppSettings({
|
|
91
93
|
displayName: data?.display_name,
|
|
92
94
|
icon: data?.icon,
|
|
93
95
|
primaryColor: data?.primary_color,
|
|
94
96
|
secondaryColor: data?.secondary_color
|
|
95
|
-
}
|
|
97
|
+
})
|
|
96
98
|
} catch {
|
|
97
99
|
// App settings not available, continue without app settings
|
|
100
|
+
setAppSettings({})
|
|
101
|
+
} finally {
|
|
102
|
+
setAppSettingsLoaded(true)
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
const rawSettings = (fetchedSettings?.data ?? fetchedSettings)?.settings ?? {}
|
|
@@ -126,7 +131,7 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName }: Nav
|
|
|
126
131
|
}
|
|
127
132
|
}
|
|
128
133
|
|
|
129
|
-
}, [client])
|
|
134
|
+
}, [appName, client])
|
|
130
135
|
|
|
131
136
|
useLayoutEffect(() => {
|
|
132
137
|
const init = async () => {
|
|
@@ -169,7 +174,7 @@ export const NavkitProvider = ({ children, client, onThemeChange, appName }: Nav
|
|
|
169
174
|
}, [themeMode, onThemeChange])
|
|
170
175
|
|
|
171
176
|
return (
|
|
172
|
-
<NavigationContext.Provider value={{ navigateToUrl, isDesk, appsList, userData, siteSettings: siteSettings.current, appSettings
|
|
177
|
+
<NavigationContext.Provider value={{ navigateToUrl, isDesk, appsList, userData, siteSettings: siteSettings.current, appSettings, appSettingsLoaded, appName, jwtToken, isUserAuthenticated, client, auth, themeMode, toggleTheme }}>
|
|
173
178
|
{children}
|
|
174
179
|
</NavigationContext.Provider>
|
|
175
180
|
)
|
|
@@ -181,4 +186,4 @@ export const useNavigation = () => {
|
|
|
181
186
|
throw new Error('useNavigation must be used within a NavkitProvider')
|
|
182
187
|
}
|
|
183
188
|
return context
|
|
184
|
-
}
|
|
189
|
+
}
|