Skip to content

Commit

Permalink
feat: cancel race when creator
Browse files Browse the repository at this point in the history
  • Loading branch information
antonstjernquist committed Aug 24, 2022
1 parent 5d61a25 commit 564d4ec
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function getDistance(v1: Vector, v2: Vector) {
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}

// RegisterNuiCB(RacingEvents.StopRace, (trackName: string, cb) => {
// emitNet(QBRacingEvents.Stop, trackName);
// cb({ status: 'ok' });
// });
RegisterNuiCB(RacingEvents.StopRace, (raceId: string, cb) => {
emitNet(QBRacingEvents.CancelRace, raceId);
cb({ status: 'ok' });
});
3 changes: 2 additions & 1 deletion server/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RawUser, User } from '../types/User';
import { Server } from 'qbcore.js';
import { RawTrack, Track, RaceRecord, Race, QBRace } from '../types/Racing';
import { RacingEvents } from '../types/Events';
import { QBRacingEvents, RacingEvents } from '../types/Events';
import { SQLJSON } from '../types/Common';
console.log('Server started!');

Expand Down Expand Up @@ -56,6 +56,7 @@ onNet(RacingEvents.DeleteTrack, async (raceId: string) => {
);

if (affectedRows > 0) {
emit(QBRacingEvents.CancelRace, raceId);
emitNet(RacingEvents.SendDeleteTrack, src, true);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Footer = () => {
<BottomNavigation value={page} onChange={handleChange} showLabels>
<BottomNavigationAction
label={'Races'}
value="/"
value=""
component={NavLink}
icon={<FormatListBulletedRoundedIcon />}
to={`${path}`}
Expand Down
6 changes: 5 additions & 1 deletion src/components/RaceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ const RaceCard = ({ race, onUpdate }: RaceCardProps) => {
) : (
<CardActions disableSpacing>
<Stack direction="row" spacing={1} marginLeft="auto">
{isCreator && <Button color="error">Delete</Button>}
{isCreator && (
<Button color="error" onClick={handleStop}>
Delete
</Button>
)}

{isCompeting ? (
<Button color="error" onClick={handleLeave}>
Expand Down
2 changes: 2 additions & 0 deletions types/Events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export enum QBRacingEvents {
WaitingDistanceCheck = 'qb-lapraces:client:WaitingDistanceCheck',
GetRacingData = 'qb-lapraces:server:GetRacingData',
GetIsAuthorizedToCreateRaces = 'qb-lapraces:server:IsAuthorizedToCreateRaces',
UpdateRaceState = 'qb-lapraces:server:UpdateRaceState',
CancelRace = 'qb-lapraces:server:CancelRace',
}

export enum NUIEvents {
Expand Down

0 comments on commit 564d4ec

Please sign in to comment.