Skip to content

Commit

Permalink
wip: cleaned legacy player modal/list + randoms
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Dec 27, 2023
1 parent 6f5e917 commit 12d8964
Show file tree
Hide file tree
Showing 19 changed files with 108 additions and 1,038 deletions.
10 changes: 5 additions & 5 deletions docs/dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,13 @@ setTimeout(() => {
- [x] admin manager should open "my account" when trying to edit self
- [x] maybe separate the backend routes
- [x][3d] playerlist
- [ ][2d] implement new player modal
- [x][2d] implement new player modal
- [x] legacy pages should open the new modal
- [x] write tsx + handling of data
- [ ] all actions
- [ ] clean legacy modal and playerlist code
- [ ] make sure it is responsive
- [ ] check behavior on error (invalid player, 500, etc)
- [x] all actions
- [x] make sure it is responsive
- [x] check behavior on error (invalid player, 500, etc)
- [x] clean legacy modal and playerlist code
- [ ][5d] full auth flow
- [x] password login
- [x] cfx.re login
Expand Down
1 change: 0 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ files {
'web/public/js/humanizeDuration.min.js',
'web/public/js/txadmin/base.js',
'web/public/js/txadmin/main.js',
'web/public/js/txadmin/players.js',
'web/public/xtermjs/xterm.min.css',
'web/public/xtermjs/xterm.min.js',
'web/public/xtermjs/xterm-addon-fit.min.js',
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@tanstack/react-virtual": "^3.0.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"is-mobile": "^4.0.0",
"jotai": "^2.5.1",
"jotai-effect": "^0.2.3",
"lucide-react": "^0.300.0",
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/ui/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DialogContent = React.forwardRef<
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" />
<X className="h-6 w-6" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
Expand Down
1 change: 1 addition & 0 deletions panel/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type OpenPlayerModalMessage = { type: 'openPlayerModal', ref: PlayerModalRefType
export declare global {
interface Window {
txConsts: InjectedTxConsts;
txIsMobile: boolean;
invokeNative?: (nativeName: string, ...args: any[]) => void;
}
type MessageEventFromIframe = MessageEvent<LogoutNoticeMessage>
Expand Down
2 changes: 2 additions & 0 deletions panel/src/layout/playerModal/IdsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function IdsBlock({ title, emptyMessage, currIds, allIds, isSmaller }: IdsBlockP
{hasCopiedIds ? (
<span className="text-sm text-success-inline">Copied!</span>
) : (
// TODO: a button to erase the ids from the database can be added here,
// requires tooltip and confirm modal though
<button onClick={handleCopyIds}>
<CopyIcon className="h-4 text-secondary hover:text-primary" />
</button>
Expand Down
45 changes: 29 additions & 16 deletions panel/src/layout/playerModal/InfoTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,27 @@ function PlayerNotesBox({ playerRef, player }: { playerRef: PlayerModalRefType,
path: `/player/save_note`,
});

const doSaveNotes = () => {
setNotesLogText('Saving...');
playerNotesApi({
queryParams: playerRef,
data: {
note: textAreaRef.current?.value.trim(),
},
success: (data) => {
if ('error' in data) {
setNotesLogText(data.error);
} else {
setNotesLogText('Saved!');
}
},
});
}

const handleKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
if (event.key === 'Enter' && !event.shiftKey) {
if (event.key === 'Enter' && !event.shiftKey && !window.txIsMobile) {
event.preventDefault();
setNotesLogText('Saving...');
playerNotesApi({
queryParams: playerRef,
data: {
note: textAreaRef.current?.value.trim(),
},
success: (data) => {
if('error' in data){
setNotesLogText(data.error);
}else{
setNotesLogText('Saved!');
}
},
});
doSaveNotes();
}
}

Expand All @@ -74,6 +78,15 @@ function PlayerNotesBox({ playerRef, player }: { playerRef: PlayerModalRefType,
? 'Type your notes about the player.'
: 'Cannot set notes for players that are not registered.'}
/>
{window.txIsMobile && <div className="mt-2 w-full">
<Button
variant="outline"
size='xs'
onClick={doSaveNotes}
disabled={!player.isRegistered}
className="w-full"
>Save Note</Button>
</div>}
</>
}

Expand Down Expand Up @@ -119,7 +132,7 @@ export default function InfoTab({ playerRef, player, setSelectedTab, refreshModa
successMsg: 'Whitelist changed.',
},
success: (data, toastId) => {
if('success' in data){
if ('success' in data) {
refreshModalData();
}
},
Expand Down
2 changes: 1 addition & 1 deletion panel/src/layout/playerModal/PlayerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export default function PlayerModal() {
))}
</div>
{/* NOTE: consistent height: sm:h-[16.5rem] */}
<ScrollArea className="w-full max-h-[calc(100vh-3.125rem-4rem-5rem)] min-h-[16.5rem] px-4 py-2 md:py-0">
<ScrollArea className="w-full max-h-[calc(100vh-3.125rem-4rem-5rem)] min-h-[16.5rem] md:max-h-[50vh] px-4 py-2 md:py-0">
{!modalData ? (
<PlayerModalMidMessage>
{modalError ? (
Expand Down
8 changes: 4 additions & 4 deletions panel/src/layout/playerModal/PlayerModalFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default function PlayerModalFooter({ playerRef, player }: PlayerModalFoot
}

const handleGiveAdmin = () => {
if(!player) return;
if (!player) return;
const params = new URLSearchParams();
params.set("autofill", "true");
params.set("name", player.pureName);
Expand All @@ -68,7 +68,7 @@ export default function PlayerModalFooter({ playerRef, player }: PlayerModalFoot
}

const handleDm = () => {
if(!player) return;
if (!player) return;
openPromptDialog({
title: `Direct Message ${player.displayName}`,
message: 'Type direct message below',
Expand All @@ -88,7 +88,7 @@ export default function PlayerModalFooter({ playerRef, player }: PlayerModalFoot
}

const handleKick = () => {
if(!player) return;
if (!player) return;
openPromptDialog({
title: `Kick ${player.displayName}`,
message: 'Type the kick reason or leave it blank (press enter)',
Expand All @@ -107,7 +107,7 @@ export default function PlayerModalFooter({ playerRef, player }: PlayerModalFoot
}

const handleWarn = () => {
if(!player) return;
if (!player) return;
openPromptDialog({
title: `Warn ${player.displayName}`,
message: 'Type the warn reason.',
Expand Down
4 changes: 1 addition & 3 deletions panel/src/layout/playerlistSidebar/PlayerlistSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export function PlayerlistSidebar({ isSheet }: PlayerSidebarProps) {
: 'calc(100vh - 3.5rem - 1px - 2rem)',
}}
>
<div
className="rounded-xl border border-border bg-card text-card-foreground shadow-sm shrink-0"
>
<div className="rounded-xl border border-border bg-card text-card-foreground shadow-sm shrink-0">
<PlayerlistSummary />
</div>
<div
Expand Down
7 changes: 7 additions & 0 deletions panel/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { isValidRedirectPath } from './lib/utils.ts';
import ThemeProvider from './components/ThemeProvider.tsx';
import { StrictMode } from 'react';
import { isMobile } from 'is-mobile';

//Detecting if the user is on a mobile device
try {
window.txIsMobile = isMobile({ tablet: true });
} catch (error) {
window.txIsMobile = false;
}

//If the initial routing is from WebPipe, remove it from the pathname so the router can handle it
if (window.location.pathname.substring(0, 8) === '/WebPipe') {
Expand Down
2 changes: 1 addition & 1 deletion resource/sv_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ txaEventHandlers.playerWarned = function(eventData)
end
txPrint('Warning '..pName..' with reason: '..eventData.reason)
else
logError('handleWarnEvent: player not found')
txPrint('handleWarnEvent: player not found')
end
end

Expand Down
2 changes: 1 addition & 1 deletion web/main/adminManager.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
const discordValue = params.get('discord');
autofill = {
name: params.get('name'),
citizenfxID: params.get('citizenfx'),
citizenfxID: params.get('citizenfx') ?? '',
discordID: discordValue && discordValue.includes(':') ? discordValue.split(':')[1] : '',
}
window.history.pushState(null, 'txAdmin', 'adminManager?');
Expand Down
4 changes: 0 additions & 4 deletions web/parts/footer.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
</div>
</div>


<%- await include('parts/playerInfoModal.ejs', locals) %>

<!-- CoreUI and necessary plugins-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
Expand All @@ -21,6 +18,5 @@
<script src="<%= resourcePath %>js/socket.io.min.js"></script>
<script src="<%= resourcePath %>js/txadmin/base.js"></script>
<script src="<%= resourcePath %>js/txadmin/main.js"></script>
<script src="<%= resourcePath %>js/txadmin/players.js"></script>
</body>
</html>
26 changes: 0 additions & 26 deletions web/parts/header.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,6 @@
</head>

<body class="c-app <%= uiTheme %>">
<!-- Player List -->
<% if (isWebInterface) { %>
<div class="c-sidebar c-sidebar-md c-sidebar-light c-sidebar-fixed
c-sidebar-right c-sidebar-xl-show playerlist-sidebar" id="plist">
<div class="tab-pane" role="tabpanel">
<div class="list-group list-group-accent">
<div class="list-group-item list-group-item-accent-secondary playerlist-header plheader">
<span class="plheader-label font-weight-bold text-muted text-uppercase">
Players:
</span>
<span class="plheader-bignum float-right" id="plist-count">--</span>
</div>
<div class="list-group-item list-group-item-accent-secondary playerlist-search">
<input class="form-control form-control-sm text-center" type="text"
placeholder="Search" id="plist-search">
</div>
<div class="playerlist thin-scroll" id="playerlist">
<div class="list-group-item text-center p-3 font-weight-bold" id="playerlist-message">
loading...
</div>
</div>
</div>
</div>
</div>
<% } %>

<!-- Center Content -->
<div class="c-wrapper c-fixed-components">

Expand Down

0 comments on commit 12d8964

Please sign in to comment.