Skip to content

Commit

Permalink
sort player aliases by last seen at
Browse files Browse the repository at this point in the history
  • Loading branch information
tudddorrr committed Nov 2, 2024
1 parent 3d98d60 commit 4e27588
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/__mocks__/playerAliasMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function playerAliasMock(extra: Partial<PlayerAlias> = {}): Playe
service: PlayerAliasService.STEAM,
identifier: 'yxre12',
player: playerMock(),
lastSeenAt: new Date().toISOString(),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
...extra
Expand Down
2 changes: 1 addition & 1 deletion src/components/PlayerAliases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type PlayerAliasesProps = {
export default function PlayerAliases({
aliases
}: PlayerAliasesProps) {
const sortedAliases = useSortedItems(aliases, 'createdAt')
const sortedAliases = useSortedItems(aliases, 'lastSeenAt')

const getIcon = useCallback((alias: PlayerAlias) => {
/* v8ignore next */
Expand Down
6 changes: 3 additions & 3 deletions src/components/__tests__/PlayerAliases.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ describe('<PlayerAliases />', () => {

it('should render the latest alias and an indicator for how many more', () => {
const aliases: PlayerAlias[] = [
playerAliasMock({ service: PlayerAliasService.STEAM, identifier: 'yxre12', createdAt: '2024-10-28 10:00:00' }),
playerAliasMock({ service: PlayerAliasService.USERNAME, identifier: 'ryet12', createdAt: '2024-10-27 10:00:00' }),
playerAliasMock({ service: PlayerAliasService.EPIC, identifier: 'epic_23rd', createdAt: '2024-10-26 10:00:00' })
playerAliasMock({ service: PlayerAliasService.STEAM, identifier: 'yxre12', lastSeenAt: '2024-10-28 10:00:00' }),
playerAliasMock({ service: PlayerAliasService.USERNAME, identifier: 'ryet12', lastSeenAt: '2024-10-27 10:00:00' }),
playerAliasMock({ service: PlayerAliasService.EPIC, identifier: 'epic_23rd', lastSeenAt: '2024-10-26 10:00:00' })
]

render(<PlayerAliases aliases={aliases} />)
Expand Down
1 change: 1 addition & 0 deletions src/entities/playerAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const playerAliasSchema = z.object({
service: z.string(),
identifier: z.string(),
player: z.lazy(() => basePlayerSchema),
lastSeenAt: z.string().datetime(),
createdAt: z.string().datetime(),
updatedAt: z.string().datetime()
})
Expand Down
6 changes: 3 additions & 3 deletions src/pages/PlayerProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function PlayerProfile() {
const [player] = usePlayer()
const navigate = useNavigate()

const sortedAliases = useSortedItems(player?.aliases ?? [], 'createdAt')
const sortedAliases = useSortedItems(player?.aliases ?? [], 'lastSeenAt')

Check warning on line 57 in src/pages/PlayerProfile.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PlayerProfile.tsx#L57

Added line #L57 was not covered by tests

const activeGame = useRecoilValue(activeGameState) as SelectedActiveGame
const user = useRecoilValue(userState) as AuthedUser
Expand Down Expand Up @@ -105,7 +105,7 @@ export default function PlayerProfile() {

<SecondaryTitle>Aliases</SecondaryTitle>

<Table columns={['Alias', 'Created at', 'Updated at']}>
<Table columns={['Alias', 'Created at', 'Last seen']}>

Check warning on line 108 in src/pages/PlayerProfile.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PlayerProfile.tsx#L108

Added line #L108 was not covered by tests
<TableBody
iterator={sortedAliases}
configureClassnames={(_, idx) => ({
Expand All @@ -117,7 +117,7 @@ export default function PlayerProfile() {
<>
<TableCell className='min-w-60'><PlayerAliases aliases={[alias]} /></TableCell>
<DateCell>{format(new Date(alias.createdAt), 'dd MMM Y, HH:mm')}</DateCell>
<DateCell>{format(new Date(alias.updatedAt), 'dd MMM Y, HH:mm')}</DateCell>
<DateCell>{format(new Date(alias.lastSeenAt), 'dd MMM Y, HH:mm')}</DateCell>

Check warning on line 120 in src/pages/PlayerProfile.tsx

View check run for this annotation

Codecov / codecov/patch

src/pages/PlayerProfile.tsx#L120

Added line #L120 was not covered by tests
</>
)}
</TableBody>
Expand Down

0 comments on commit 4e27588

Please sign in to comment.