update new Flight Tracker

This commit is contained in:
João Mendes 2022-11-13 22:39:02 +00:00
parent 10342b46b2
commit 989c52866d
7 changed files with 25 additions and 9 deletions

View File

@ -7,9 +7,11 @@ import {
IImageProps, IImageProps,
Stack, Stack,
} from 'office-ui-fabric-react'; } from 'office-ui-fabric-react';
import { useRecoilState } from 'recoil';
import { EInformationType } from '../../constants/EInformationType'; import { EInformationType } from '../../constants/EInformationType';
import { IFlightTrackerListItem } from '../../models/IFlightTrackerListItem'; import { IFlightTrackerListItem } from '../../models/IFlightTrackerListItem';
import { globalState } from '../../recoil/atoms';
import { FlightStatus } from '../FlightStatus/FlightStatus'; import { FlightStatus } from '../FlightStatus/FlightStatus';
import { import {
FlightTrackerListItemAttribute, FlightTrackerListItemAttribute,
@ -27,12 +29,23 @@ export const FlightTrackerListItem: React.FunctionComponent<IFlightTrackerListIt
) => { ) => {
const { flights, flightInformationType } = props; const { flights, flightInformationType } = props;
const { itemContainer, controlStyles } = useFlightTrackerStyles(); const { itemContainer, controlStyles } = useFlightTrackerStyles();
const [appState, setGlobalState] = useRecoilState(globalState);
const imageProps: IImageProps = React.useMemo(() => { const imageProps: IImageProps = React.useMemo(() => {
return { src: flights.flightCompanyImage, width: 22, height: 22 }; return { src: flights.flightCompanyImage, width: 22, height: 22 };
}, [flights.flightCompanyImage]); }, [flights.flightCompanyImage]);
const divRef = React.useRef<HTMLDivElement>(null); const divRef = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
if (divRef.current) {
setGlobalState((prevState) => {
return {
...prevState,
itemHeight: divRef.current.clientHeight,
};
});
}
},[divRef.current, setGlobalState]);
return ( return (
<> <>
<div ref={divRef}> <div ref={divRef}>

View File

@ -15,7 +15,7 @@ import { globalState } from '../../recoil/atoms';
export const useFlightTrackerStyles = () => { export const useFlightTrackerStyles = () => {
const [globalStateApp] = useRecoilState(globalState); const [globalStateApp] = useRecoilState(globalState);
const { currentTheme, numberItemsPerPage } = globalStateApp; const { currentTheme, numberItemsPerPage, itemHeight } = globalStateApp;
const listHeaderStyles: ITextStyles = React.useMemo(() => { const listHeaderStyles: ITextStyles = React.useMemo(() => {
return { root: { fontWeight: FontWeights.semibold, color: currentTheme?.semanticColors?.bodyText } }; return { root: { fontWeight: FontWeights.semibold, color: currentTheme?.semanticColors?.bodyText } };
@ -56,7 +56,7 @@ export const useFlightTrackerStyles = () => {
const scollableContainerStyles: Partial<IScrollablePaneStyles> = React.useMemo(() => { const scollableContainerStyles: Partial<IScrollablePaneStyles> = React.useMemo(() => {
return { return {
root: { position: "relative", height: (87 * numberItemsPerPage) - 50 , root: { position: "relative", height: ((itemHeight * numberItemsPerPage)) - 20, //max height of the scrollable container
}, },
contentContainer: { "::-webkit-scrollbar-thumb": { contentContainer: { "::-webkit-scrollbar-thumb": {
@ -69,7 +69,7 @@ export const useFlightTrackerStyles = () => {
"scrollbar-color": currentTheme?.semanticColors.bodyFrameBackground, "scrollbar-color": currentTheme?.semanticColors.bodyFrameBackground,
"scrollbar-width": "thin", }, "scrollbar-width": "thin", },
}; };
}, [currentTheme, numberItemsPerPage]); }, [currentTheme, numberItemsPerPage, itemHeight]);
const stackContainerStyles: IStackStyles= React.useMemo(() => { const stackContainerStyles: IStackStyles= React.useMemo(() => {
return { return {

View File

@ -26,6 +26,8 @@ import { useSelectAirportStyles } from './useSelectAirportStyles';
export interface ITagExtended extends ITag { export interface ITagExtended extends ITag {
airportData: IAirport; airportData: IAirport;
} }
const SELECTED_AIRPORT_SESSION_STORAGE_KEY = "___selectedAirport___";
export const SelectAirportPicker: React.FunctionComponent = () => { export const SelectAirportPicker: React.FunctionComponent = () => {
const divRef = React.useRef<HTMLDivElement>(null); const divRef = React.useRef<HTMLDivElement>(null);
@ -34,7 +36,7 @@ export const SelectAirportPicker: React.FunctionComponent = () => {
const [selectedAirport, setSelectedAirports] = React.useState<ITag[]>([]); const [selectedAirport, setSelectedAirports] = React.useState<ITag[]>([]);
const { controlStyles, selecteAirportPickerStyles } = useSelectAirportStyles(); const { controlStyles, selecteAirportPickerStyles } = useSelectAirportStyles();
const { context } = appState; const { context } = appState;
const SELECTED_AIRPORT_SESSION_STORAGE_KEY = "___selectedAirport___";
const [getSelectedAirportFromSessionStorage, SetSelectedAirporttoSessionStorage] = useLocalStorage(); const [getSelectedAirportFromSessionStorage, SetSelectedAirporttoSessionStorage] = useLocalStorage();
const inputProps: IInputProps = React.useMemo(() => { const inputProps: IInputProps = React.useMemo(() => {
return { return {

View File

@ -38,3 +38,4 @@ export const RAPID_API_KEY_COUNTRY_FLAGS = "a96bf6dd14mshaba3c61477da062p1a89f2
export const RAPID_API_HOST_COUNTRY_FLAGS = "country-flags.p.rapidapi.com"; export const RAPID_API_HOST_COUNTRY_FLAGS = "country-flags.p.rapidapi.com";
export const RAPID_API_KEY_FLIGHT_RADAR = "a96bf6dd14mshaba3c61477da062p1a89f2jsn5190b7082e8e"; export const RAPID_API_KEY_FLIGHT_RADAR = "a96bf6dd14mshaba3c61477da062p1a89f2jsn5190b7082e8e";
export const RAPID_API_HOST_FLIGHT_RADAR = "flight-radar1.p.rapidapi.com"; export const RAPID_API_HOST_FLIGHT_RADAR = "flight-radar1.p.rapidapi.com";

View File

@ -18,5 +18,5 @@ export interface IGlobalState {
isScrolling: boolean; isScrolling: boolean;
hasMore: boolean; hasMore: boolean;
webpartContainerWidth: number; webpartContainerWidth: number;
itemHeight:number;
} }

View File

@ -18,7 +18,7 @@ export const globalState = atom<IGlobalState>({
currentPage: 0, currentPage: 0,
isScrolling: false, isScrolling: false,
hasMore: true, hasMore: true,
webpartContainerWidth: 0 webpartContainerWidth: 0,
itemHeight:87
}, },
}); });

View File

@ -138,7 +138,7 @@ export default class FlightTrackerWebPart extends BaseClientSideWebPart<IFlightT
PropertyPaneSlider("numberItemsPerPage", { PropertyPaneSlider("numberItemsPerPage", {
label: strings.NumberItemsPerPageLabel, label: strings.NumberItemsPerPageLabel,
value: this.properties.numberItemsPerPage, value: this.properties.numberItemsPerPage,
min: 5, min: 1,
max: 20, max: 20,
showValue: true, showValue: true,
}) })