Skip to content

Commit

Permalink
wip: bunch of small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Nov 9, 2023
1 parent 5ef1547 commit f9d9525
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 483 deletions.
8 changes: 2 additions & 6 deletions core/components/WebServer/getReactIndex.ts
Expand Up @@ -22,8 +22,7 @@ let htmlFile: string;

// NOTE: https://vitejs.dev/guide/backend-integration.html
const viteOrigin = process.env.TXADMIN_DEV_VITE_URL!;
const devModulesScript = `<!-- Dev scripts required for HMR -->
<script type="module">
const devModulesScript = `<script type="module">
import { injectIntoGlobalHook } from "${viteOrigin}/@react-refresh";
injectIntoGlobalHook(window);
window.$RefreshReg$ = () => {};
Expand Down Expand Up @@ -132,10 +131,7 @@ export default async function getReactIndex(ctx: CtxWithVars | AuthedCtx) {
replacers.basePath = `<base href="${basePath}">`;
replacers.ogTitle = `txAdmin - ${serverName}`;
replacers.ogDescripttion = `Manage & Monitor your FiveM/RedM Server with txAdmin v${txEnv.txAdminVersion} atop FXServer ${txEnv.fxServerVersion}`;
replacers.txConstsInjection = `<!-- Injected Consts -->
<script>
window.txConsts = ${JSON.stringify(injectedConsts)};
</script>`;
replacers.txConstsInjection = `<script>window.txConsts = ${JSON.stringify(injectedConsts)};</script>`;
replacers.devModules = convars.isDevMode ? devModulesScript : '';

//Prepare custom themes style tag
Expand Down
3 changes: 3 additions & 0 deletions core/components/WebServer/index.ts
Expand Up @@ -119,6 +119,9 @@ export default class WebServer {
ctx.status = 404;
console.verbose.warn(`Request 404 error: ${ctx.path}`);
return ctx.utils.render('standalone/404');
}else if (ctx.path.endsWith('.map')){
ctx.status = 404;
return ctx.send('Not found');
} else {
return ctx.utils.serveReactIndex();
}
Expand Down
2 changes: 1 addition & 1 deletion core/components/WebServer/middlewares/authMws.ts
Expand Up @@ -28,7 +28,7 @@ const webLogoutPage = `<style>
window.parent.postMessage({ type: 'logoutNotice' });
// If parent redirect didn't work, redirect here
setTimeout(function() {
window.location.href = '/login#expired';
window.parent.location.href = '/login#expired';
}, 2000);
</script>`;

Expand Down
1 change: 0 additions & 1 deletion core/components/WebServer/middlewares/sessionMws.ts
Expand Up @@ -103,7 +103,6 @@ export const koaSessMw = (cookieName: string, store: SessionMemoryStorage) => {
path: '/',
maxAge: store.maxAgeMs,
httpOnly: true,
sameSite: 'none',
secure: false,
overwrite: true,
signed: false,
Expand Down
9 changes: 5 additions & 4 deletions docs/dev_notes.md
Expand Up @@ -80,10 +80,10 @@ Processo:
- [ ][3d] playerlist
- [ ][3h] playerlist click opens legacy player modal (`iframe.contentWindow.postMessage("openModal", ???);`)
- [ ][5d] full auth flow
- [ ] password login
- [ ] cfx.re login
- [ ] error page
- [ ] master account pin add page
- [x] password login
- [x] cfx.re login
- [x] error page
- [x] master account pin add page
- [ ] master account bkp password page
- [ ] disable menu links based on permissions
- [ ] flow to refresh the permissions on the client side
Expand Down Expand Up @@ -119,6 +119,7 @@ Quickies
- [ ] add `maxage` to `koa-static` config
- [ ] add `cache-control` and/or `vary` to all pages
- [ ] deprecate StatisticsManager.pageViews as its now untrackable?
- [ ] remove testing page
- [ ] xxxxxxxx


Expand Down
21 changes: 17 additions & 4 deletions panel/src/components/MainPageLink.tsx
@@ -1,5 +1,6 @@
import { pageErrorStatusAtom, useContentRefresh } from "@/hooks/mainPageStatus";
import { useAtomValue } from "jotai";
import { forwardRef } from "react";
import { Link } from "wouter";

type MainPageLinkProps = {
Expand All @@ -8,20 +9,32 @@ type MainPageLinkProps = {
children: React.ReactNode;
className?: string;
};
export default function MainPageLink({ href, children, className, isActive }: MainPageLinkProps) {
function MainPageLinkInner(
props: MainPageLinkProps,
ref: React.ForwardedRef<HTMLAnchorElement>
) {
const isPageInError = useAtomValue(pageErrorStatusAtom);
const refreshContent = useContentRefresh();
const checkOnClick = (e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
if (isActive || isPageInError) {
if (props.isActive || isPageInError) {
console.log('Page is already active or in error state. Forcing error boundry + router re-render.');
refreshContent();
e.preventDefault();
}
}

return (
<Link href={href} onClick={checkOnClick} className={className}>
{children}
<Link
// @ts-ignore - idk why this errors
ref={ref}
href={props.href}
onClick={checkOnClick}
className={props.className}
>
{props.children}
</Link>
);
}

const MainPageLink = forwardRef(MainPageLinkInner);
export default MainPageLink;
2 changes: 1 addition & 1 deletion panel/src/layout/DesktopNavbar.tsx
Expand Up @@ -21,7 +21,7 @@ type HeaderMenuLinkProps = {
function HeaderMenuLink(props: HeaderMenuLinkProps) {
const [isActive] = useRoute(props.href);
return (
<NavigationMenuItem asChild>
<NavigationMenuItem>
<NavigationMenuLink asChild active={isActive}>
<MainPageLink
href={props.href}
Expand Down
3 changes: 3 additions & 0 deletions panel/src/layout/ServerSidebar.tsx
Expand Up @@ -65,6 +65,9 @@ export function ServerSidebar() {
<LuDna className="mr-2 h-4 w-4" />Advanced
</ServerMenuLink>
)}
<ServerMenuLink href="/test" className='text-yellow-700 dark:text-yellow-200'>
<LuDna className="mr-2 h-4 w-4" />Test
</ServerMenuLink>
</div>
</div>
<div className="flex justify-center items-center h-[246px]
Expand Down
4 changes: 2 additions & 2 deletions panel/src/main.tsx
Expand Up @@ -48,11 +48,11 @@ export function AuthContextSwitch() {
return <MainShell />;
} else {
//Unless the user is already in the auth pages, redirect to the login page
console.log('User is not authenticated. Redirecting to login page.');
if (!window.txConsts.hasMasterAccount && !window.location.pathname.startsWith('/addMaster')) {
console.log(window.location.pathname);
console.log('No master account detected. Redirecting to addMaster page.');
window.history.replaceState(null, '', '/addMaster/pin');
} else if (!isAuthRoute(window.location.pathname)) {
console.log('User is not authenticated. Redirecting to login page.');
const suffix = window.location.pathname + window.location.search + window.location.hash;
const newSuffix = suffix === '/'
? `/login`
Expand Down
4 changes: 2 additions & 2 deletions panel/src/pages/auth/Login.tsx
Expand Up @@ -152,15 +152,15 @@ export default function Login() {
<Input
id="frm-login" type="text" ref={usernameRef}
placeholder="username"
required
autoCapitalize='off' autoComplete='off' required
/>
</div>
<div className="grid gap-2">
<Label htmlFor="frm-password">Password</Label>
<Input
id="frm-password" type="password" ref={passwordRef}
placeholder='password'
required
autoCapitalize='off' autoComplete='off' required
/>
</div>
</div>
Expand Down
43 changes: 0 additions & 43 deletions web/standalone/404.ejs

This file was deleted.

0 comments on commit f9d9525

Please sign in to comment.