-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #779 from gettakaro/gameserver-dashboard
- Loading branch information
Showing
10 changed files
with
286 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/lib-db/src/migrations/sql/20231223132631-pog-online.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Knex } from 'knex'; | ||
|
||
export async function up(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('playerOnGameServer', (table) => { | ||
table.boolean('online').defaultTo(false); | ||
}); | ||
} | ||
|
||
export async function down(knex: Knex): Promise<void> { | ||
await knex.schema.alterTable('playerOnGameServer', (table) => { | ||
table.dropColumn('online'); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
packages/web-main/src/pages/gameserver/cards/ChatMessages.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
EventOutputDTO, | ||
EventSearchInputAllowedFiltersEventNameEnum, | ||
EventSearchInputDTOSortDirectionEnum, | ||
} from '@takaro/apiclient'; | ||
import { Loading, styled } from '@takaro/lib-components'; | ||
import { useSelectedGameServer } from 'hooks/useSelectedGameServerContext'; | ||
import { useSocket } from 'hooks/useSocket'; | ||
import { useEvents } from 'queries/events'; | ||
import { FC, useEffect } from 'react'; | ||
|
||
const SteamAvatar = styled.img` | ||
width: 2rem; | ||
height: 100%; | ||
border-radius: 50%; | ||
margin: auto; | ||
`; | ||
|
||
const ChatContainer = styled.div` | ||
border-radius: 8px; | ||
max-height: 20vh; | ||
overflow-y: scroll; | ||
`; | ||
|
||
const Message = styled.span` | ||
display: block; | ||
padding: 5px; | ||
border-bottom: 1px solid ${({ theme }) => theme.colors.backgroundAlt}; | ||
height: 2rem; | ||
& > * { | ||
margin-right: 1rem; | ||
} | ||
`; | ||
|
||
const PlayerName = styled.span` | ||
font-weight: bold; | ||
margin-right: 10px; | ||
`; | ||
|
||
const ChatMessage: FC<{ chatMessage: EventOutputDTO }> = ({ chatMessage }) => { | ||
if (!chatMessage.meta || !('message' in chatMessage.meta)) return null; | ||
let avatarUrl = '/favicon.ico'; | ||
|
||
if (chatMessage.player?.steamAvatar) avatarUrl = chatMessage.player?.steamAvatar; | ||
|
||
const friendlyTimeStamp = new Date(chatMessage.createdAt).toLocaleTimeString(); | ||
|
||
return ( | ||
<Message> | ||
<span>{friendlyTimeStamp}</span> | ||
<SteamAvatar src={avatarUrl} /> | ||
<PlayerName>{chatMessage.player?.name}</PlayerName> | ||
<span>{chatMessage.meta.message as string}</span> | ||
</Message> | ||
); | ||
}; | ||
|
||
export const ChatMessagesCard: FC = () => { | ||
const { selectedGameServerId } = useSelectedGameServer(); | ||
const { socket } = useSocket(); | ||
|
||
const { data, isLoading, refetch } = useEvents({ | ||
filters: { | ||
gameserverId: [selectedGameServerId], | ||
eventName: [EventSearchInputAllowedFiltersEventNameEnum.ChatMessage], | ||
}, | ||
sortBy: 'createdAt', | ||
sortDirection: EventSearchInputDTOSortDirectionEnum.Desc, | ||
extend: ['player'], | ||
}); | ||
|
||
useEffect(() => { | ||
socket.on('event', (event: EventOutputDTO) => { | ||
if (event.eventName === 'chat-message') refetch(); | ||
}); | ||
|
||
return () => { | ||
socket.off('event'); | ||
}; | ||
}, []); | ||
|
||
if (isLoading) return <Loading />; | ||
|
||
const components = data?.pages[0].data?.map((event) => <ChatMessage key={event.id} chatMessage={event} />); | ||
|
||
return <ChatContainer>{components}</ChatContainer>; | ||
}; |
Oops, something went wrong.