Skip to content

Commit 4f105f7

Browse files
authored
Merge pull request #11 from PFConnect/main
dsfsdfdfsfds
2 parents 4bc7752 + 11fa8ea commit 4f105f7

3 files changed

Lines changed: 236 additions & 57 deletions

File tree

src/pages/ACARS.tsx

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import Button from '../components/common/Button';
77
import { createFlightsSocket } from '../sockets/flightsSocket';
88
import { createOverviewSocket } from '../sockets/overviewSocket';
99
import { useData } from '../hooks/data/useData';
10-
import { useSettings } from '../hooks/settings/useSettings';
11-
import { linearToLogVolume, playAudioWithGain } from '../utils/playSound';
10+
import { useAuth } from '../hooks/auth/useAuth';
1211
import { parseCallsign, getAirportName } from '../utils/callsignParser';
1312
import type { Flight } from '../types/flight';
1413
import type { OverviewSession } from '../sockets/overviewSocket';
@@ -43,6 +42,7 @@ export default function ACARS() {
4342
const [isAuthError, setIsAuthError] = useState(false);
4443
const [pdcRequested, setPdcRequested] = useState(false);
4544
const [sessionAccessId, setSessionAccessId] = useState<string | null>(null);
45+
const { user } = useAuth();
4646
const [notes, setNotes] = useState<string>('');
4747
const [terminalWidth, setTerminalWidth] = useState(50);
4848
const [notesWidth, setNotesWidth] = useState(20);
@@ -831,27 +831,49 @@ NOTES:
831831
</div>
832832
{session.controllers &&
833833
session.controllers.length > 0 ? (
834-
<div className="ml-2 mt-0.5 space-y-0.5">
835-
{session.controllers.map(
836-
(controller, idx) => (
837-
<div
838-
key={idx}
839-
className="text-[10px] flex items-center gap-1"
840-
>
841-
<span className="text-gray-500">
842-
843-
</span>
844-
<span className="text-gray-300">
845-
{
846-
controller.username
847-
}
848-
</span>
849-
<span className="text-gray-600">
850-
({controller.role})
851-
</span>
834+
<div className="ml-2 mt-1 space-y-1">
835+
{session.controllers.map((controller, idx) => {
836+
const isCurrentUser =
837+
!!user &&
838+
controller.username === user.username;
839+
const isVatsimLinked =
840+
isCurrentUser && !!user?.vatsimCid;
841+
const hasControllerRating =
842+
isVatsimLinked &&
843+
!!user?.vatsimRatingShort &&
844+
user.vatsimRatingShort !== 'OBS';
845+
const infoText = hasControllerRating
846+
? 'This user holds a controller rating on VATSIM'
847+
: 'This user is registered on VATSIM';
848+
return (
849+
<div key={idx} className="">
850+
<div className="flex items-center gap-2">
851+
<span className="text-gray-400 text-base"></span>
852+
<span className="text-white text-base md:text-lg font-semibold">
853+
{controller.username}
854+
</span>
855+
{isVatsimLinked && (
856+
<span className="relative group inline-flex items-center justify-center rounded-full bg-white p-0.5">
857+
<img
858+
src="/assets/images/vatsim.svg"
859+
alt="VATSIM"
860+
className="h-3 w-3"
861+
style={{ transform: 'rotate(180deg)' }}
862+
/>
863+
<span
864+
className="absolute left-full top-1/2 -translate-y-1/2 ml-2 whitespace-nowrap rounded-md px-2 py-1 text-[10px] md:text-xs font-medium text-white bg-gradient-to-r from-cyan-500 to-green-500 shadow-lg opacity-0 group-hover:opacity-100 pointer-events-none transition-opacity duration-100"
865+
>
866+
{infoText}
867+
</span>
868+
</span>
869+
)}
870+
<span className="text-gray-500 text-sm md:text-base">
871+
({controller.role})
872+
</span>
873+
</div>
852874
</div>
853-
)
854-
)}
875+
);
876+
})}
855877
</div>
856878
) : (
857879
<div className="text-[10px] text-gray-500 ml-2">

src/pages/PilotProfile.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import {
3636
Legend,
3737
} from 'chart.js';
3838
import Button from '../components/common/Button';
39-
39+
import { useNavigate } from 'react-router-dom';
4040
ChartJS.register(
4141
CategoryScale,
4242
LinearScale,
@@ -109,7 +109,7 @@ export default function PilotProfile() {
109109
const [loading, setLoading] = useState(true);
110110
const [error, setError] = useState('');
111111
const [shareClicked, setShareClicked] = useState(false);
112-
112+
const navigate = useNavigate()
113113
useEffect(() => {
114114
fetchProfile();
115115
}, [username]);
@@ -120,7 +120,31 @@ export default function PilotProfile() {
120120
setShareClicked(true);
121121
setTimeout(() => setShareClicked(false), 2000);
122122
};
123-
123+
const handleShareFlight = async (flightid: string): Promise<string> => {
124+
try {
125+
const res = await fetch(
126+
`${import.meta.env.VITE_SERVER_URL}/api/logbook/flights/${flightid}/share`,
127+
{
128+
method: 'POST',
129+
credentials: 'include',
130+
}
131+
);
132+
if (!res.ok) return '';
133+
const data = await res.json();
134+
if (data.shareToken) return `/flight/${data.shareToken}`;
135+
if (data.shareUrl) {
136+
try {
137+
const u = new URL(data.shareUrl);
138+
return u.pathname || data.shareUrl;
139+
} catch {
140+
return data.shareUrl;
141+
}
142+
}
143+
} catch (e) {
144+
console.error(e);
145+
}
146+
return '';
147+
};
124148
const fetchProfile = async () => {
125149
try {
126150
const res = await fetch(
@@ -682,6 +706,10 @@ export default function PilotProfile() {
682706
return (
683707
<div
684708
key={flight.id}
709+
onClick={async () => {
710+
const url = await handleShareFlight(String(flight.id));
711+
if (url) navigate(url);
712+
}}
685713
className="bg-gray-900/50 rounded-xl border-2 border-gray-800 p-4 hover:border-blue-700/50 transition-all"
686714
>
687715
<div className="flex items-center justify-between">
@@ -701,8 +729,7 @@ export default function PilotProfile() {
701729
</div>
702730
<div className="flex items-center gap-4 text-sm text-gray-400">
703731
<span className="font-mono">
704-
{flight.departure_icao}{' '}
705-
{flight.arrival_icao}
732+
{flight.departure_icao}{flight.arrival_icao}
706733
</span>
707734
<span></span>
708735
<span>

0 commit comments

Comments
 (0)