commit FlightTracker
|
@ -0,0 +1,378 @@
|
||||||
|
require('@rushstack/eslint-config/patch/modern-module-resolution');
|
||||||
|
module.exports = {
|
||||||
|
extends: ['@microsoft/eslint-config-spfx/lib/profiles/react'],
|
||||||
|
parserOptions: { tsconfigRootDir: __dirname },
|
||||||
|
overrides: [
|
||||||
|
{
|
||||||
|
files: ['*.ts', '*.tsx'],
|
||||||
|
parser: '@typescript-eslint/parser',
|
||||||
|
'parserOptions': {
|
||||||
|
'project': './tsconfig.json',
|
||||||
|
'ecmaVersion': 2018,
|
||||||
|
'sourceType': 'module'
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// Prevent usage of the JavaScript null value, while allowing code to access existing APIs that may require null. https://www.npmjs.com/package/@rushstack/eslint-plugin
|
||||||
|
'@rushstack/no-new-null': 1,
|
||||||
|
// Require Jest module mocking APIs to be called before any other statements in their code block. https://www.npmjs.com/package/@rushstack/eslint-plugin
|
||||||
|
'@rushstack/hoist-jest-mock': 1,
|
||||||
|
// Require regular expressions to be constructed from string constants rather than dynamically building strings at runtime. https://www.npmjs.com/package/@rushstack/eslint-plugin-security
|
||||||
|
'@rushstack/security/no-unsafe-regexp': 1,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/adjacent-overload-signatures': 1,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
//
|
||||||
|
// CONFIGURATION: By default, these are banned: String, Boolean, Number, Object, Symbol
|
||||||
|
'@typescript-eslint/ban-types': [
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
'extendDefaults': false,
|
||||||
|
'types': {
|
||||||
|
'String': {
|
||||||
|
'message': 'Use \'string\' instead',
|
||||||
|
'fixWith': 'string'
|
||||||
|
},
|
||||||
|
'Boolean': {
|
||||||
|
'message': 'Use \'boolean\' instead',
|
||||||
|
'fixWith': 'boolean'
|
||||||
|
},
|
||||||
|
'Number': {
|
||||||
|
'message': 'Use \'number\' instead',
|
||||||
|
'fixWith': 'number'
|
||||||
|
},
|
||||||
|
'Object': {
|
||||||
|
'message': 'Use \'object\' instead, or else define a proper TypeScript type:'
|
||||||
|
},
|
||||||
|
'Symbol': {
|
||||||
|
'message': 'Use \'symbol\' instead',
|
||||||
|
'fixWith': 'symbol'
|
||||||
|
},
|
||||||
|
'Function': {
|
||||||
|
'message': 'The \'Function\' type accepts any function-like value.\nIt provides no type safety when calling the function, which can be a common source of bugs.\nIt also accepts things like class declarations, which will throw at runtime as they will not be called with \'new\'.\nIf you are expecting the function to accept certain arguments, you should explicitly define the function shape.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// RATIONALE: Code is more readable when the type of every variable is immediately obvious.
|
||||||
|
// Even if the compiler may be able to infer a type, this inference will be unavailable
|
||||||
|
// to a person who is reviewing a GitHub diff. This rule makes writing code harder,
|
||||||
|
// but writing code is a much less important activity than reading it.
|
||||||
|
//
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/explicit-function-return-type': [
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
'allowExpressions': true,
|
||||||
|
'allowTypedFunctionExpressions': true,
|
||||||
|
'allowHigherOrderFunctions': false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
// Rationale to disable: although this is a recommended rule, it is up to dev to select coding style.
|
||||||
|
// Set to 1 (warning) or 2 (error) to enable.
|
||||||
|
'@typescript-eslint/explicit-member-accessibility': 0,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/no-array-constructor': 1,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
//
|
||||||
|
// RATIONALE: The "any" keyword disables static type checking, the main benefit of using TypeScript.
|
||||||
|
// This rule should be suppressed only in very special cases such as JSON.stringify()
|
||||||
|
// where the type really can be anything. Even if the type is flexible, another type
|
||||||
|
// may be more appropriate such as "unknown", "{}", or "Record<k,V>".
|
||||||
|
'@typescript-eslint/no-explicit-any': 1,
|
||||||
|
// RATIONALE: The #1 rule of promises is that every promise chain must be terminated by a catch()
|
||||||
|
// handler. Thus wherever a Promise arises, the code must either append a catch handler,
|
||||||
|
// or else return the object to a caller (who assumes this responsibility). Unterminated
|
||||||
|
// promise chains are a serious issue. Besides causing errors to be silently ignored,
|
||||||
|
// they can also cause a NodeJS process to terminate unexpectedly.
|
||||||
|
'@typescript-eslint/no-floating-promises': 2,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'@typescript-eslint/no-for-in-array': 2,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/no-misused-new': 2,
|
||||||
|
// RATIONALE: The "namespace" keyword is not recommended for organizing code because JavaScript lacks
|
||||||
|
// a "using" statement to traverse namespaces. Nested namespaces prevent certain bundler
|
||||||
|
// optimizations. If you are declaring loose functions/variables, it's better to make them
|
||||||
|
// static members of a class, since classes support property getters and their private
|
||||||
|
// members are accessible by unit tests. Also, the exercise of choosing a meaningful
|
||||||
|
// class name tends to produce more discoverable APIs: for example, search+replacing
|
||||||
|
// the function "reverse()" is likely to return many false matches, whereas if we always
|
||||||
|
// write "Text.reverse()" is more unique. For large scale organization, it's recommended
|
||||||
|
// to decompose your code into separate NPM packages, which ensures that component
|
||||||
|
// dependencies are tracked more conscientiously.
|
||||||
|
//
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/no-namespace': [
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
'allowDeclarations': false,
|
||||||
|
'allowDefinitionFiles': false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// RATIONALE: Parameter properties provide a shorthand such as "constructor(public title: string)"
|
||||||
|
// that avoids the effort of declaring "title" as a field. This TypeScript feature makes
|
||||||
|
// code easier to write, but arguably sacrifices readability: In the notes for
|
||||||
|
// "@typescript-eslint/member-ordering" we pointed out that fields are central to
|
||||||
|
// a class's design, so we wouldn't want to bury them in a constructor signature
|
||||||
|
// just to save some typing.
|
||||||
|
//
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
// Set to 1 (warning) or 2 (error) to enable the rule
|
||||||
|
'@typescript-eslint/no-parameter-properties': 0,
|
||||||
|
// RATIONALE: When left in shipping code, unused variables often indicate a mistake. Dead code
|
||||||
|
// may impact performance.
|
||||||
|
//
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/no-unused-vars': [
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
'vars': 'all',
|
||||||
|
// Unused function arguments often indicate a mistake in JavaScript code. However in TypeScript code,
|
||||||
|
// the compiler catches most of those mistakes, and unused arguments are fairly common for type signatures
|
||||||
|
// that are overriding a base class method or implementing an interface.
|
||||||
|
'args': 'none'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/no-use-before-define': [
|
||||||
|
2,
|
||||||
|
{
|
||||||
|
'functions': false,
|
||||||
|
'classes': true,
|
||||||
|
'variables': true,
|
||||||
|
'enums': true,
|
||||||
|
'typedefs': true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// Disallows require statements except in import statements.
|
||||||
|
// In other words, the use of forms such as var foo = require("foo") are banned. Instead use ES6 style imports or import foo = require("foo") imports.
|
||||||
|
'@typescript-eslint/no-var-requires': 'error',
|
||||||
|
// RATIONALE: The "module" keyword is deprecated except when describing legacy libraries.
|
||||||
|
//
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'@typescript-eslint/prefer-namespace-keyword': 1,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
// Rationale to disable: it's up to developer to decide if he wants to add type annotations
|
||||||
|
// Set to 1 (warning) or 2 (error) to enable the rule
|
||||||
|
'@typescript-eslint/no-inferrable-types': 0,
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
// Rationale to disable: declaration of empty interfaces may be helpful for generic types scenarios
|
||||||
|
'@typescript-eslint/no-empty-interface': 0,
|
||||||
|
// RATIONALE: This rule warns if setters are defined without getters, which is probably a mistake.
|
||||||
|
'accessor-pairs': 1,
|
||||||
|
// RATIONALE: In TypeScript, if you write x["y"] instead of x.y, it disables type checking.
|
||||||
|
'dot-notation': [
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
'allowPattern': '^_'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
'eqeqeq': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'for-direction': 1,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'guard-for-in': 2,
|
||||||
|
// RATIONALE: If you have more than 2,000 lines in a single source file, it's probably time
|
||||||
|
// to split up your code.
|
||||||
|
'max-lines': ['warn', { max: 2000 }],
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-async-promise-executor': 2,
|
||||||
|
// RATIONALE: Deprecated language feature.
|
||||||
|
'no-caller': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-compare-neg-zero': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-cond-assign': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-constant-condition': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-control-regex': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-debugger': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-delete-var': 2,
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-duplicate-case': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-empty': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-empty-character-class': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-empty-pattern': 1,
|
||||||
|
// RATIONALE: Eval is a security concern and a performance concern.
|
||||||
|
'no-eval': 1,
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-ex-assign': 2,
|
||||||
|
// RATIONALE: System types are global and should not be tampered with in a scalable code base.
|
||||||
|
// If two different libraries (or two versions of the same library) both try to modify
|
||||||
|
// a type, only one of them can win. Polyfills are acceptable because they implement
|
||||||
|
// a standardized interoperable contract, but polyfills are generally coded in plain
|
||||||
|
// JavaScript.
|
||||||
|
'no-extend-native': 1,
|
||||||
|
// Disallow unnecessary labels
|
||||||
|
'no-extra-label': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-fallthrough': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-func-assign': 1,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'no-implied-eval': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-invalid-regexp': 2,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'no-label-var': 2,
|
||||||
|
// RATIONALE: Eliminates redundant code.
|
||||||
|
'no-lone-blocks': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-misleading-character-class': 2,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'no-multi-str': 2,
|
||||||
|
// RATIONALE: It's generally a bad practice to call "new Thing()" without assigning the result to
|
||||||
|
// a variable. Either it's part of an awkward expression like "(new Thing()).doSomething()",
|
||||||
|
// or else implies that the constructor is doing nontrivial computations, which is often
|
||||||
|
// a poor class design.
|
||||||
|
'no-new': 1,
|
||||||
|
// RATIONALE: Obsolete language feature that is deprecated.
|
||||||
|
'no-new-func': 2,
|
||||||
|
// RATIONALE: Obsolete language feature that is deprecated.
|
||||||
|
'no-new-object': 2,
|
||||||
|
// RATIONALE: Obsolete notation.
|
||||||
|
'no-new-wrappers': 1,
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-octal': 2,
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
'no-octal-escape': 2,
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-regex-spaces': 2,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'no-return-assign': 2,
|
||||||
|
// RATIONALE: Security risk.
|
||||||
|
'no-script-url': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-self-assign': 2,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'no-self-compare': 2,
|
||||||
|
// RATIONALE: This avoids statements such as "while (a = next(), a && a.length);" that use
|
||||||
|
// commas to create compound expressions. In general code is more readable if each
|
||||||
|
// step is split onto a separate line. This also makes it easier to set breakpoints
|
||||||
|
// in the debugger.
|
||||||
|
'no-sequences': 1,
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-shadow-restricted-names': 2,
|
||||||
|
// RATIONALE: Obsolete language feature that is deprecated.
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-sparse-arrays': 2,
|
||||||
|
// RATIONALE: Although in theory JavaScript allows any possible data type to be thrown as an exception,
|
||||||
|
// such flexibility adds pointless complexity, by requiring every catch block to test
|
||||||
|
// the type of the object that it receives. Whereas if catch blocks can always assume
|
||||||
|
// that their object implements the "Error" contract, then the code is simpler, and
|
||||||
|
// we generally get useful additional information like a call stack.
|
||||||
|
'no-throw-literal': 2,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'no-unmodified-loop-condition': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-unsafe-finally': 2,
|
||||||
|
// RATIONALE: Catches a common coding mistake.
|
||||||
|
'no-unused-expressions': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-unused-labels': 1,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-useless-catch': 1,
|
||||||
|
// RATIONALE: Avoids a potential performance problem.
|
||||||
|
'no-useless-concat': 1,
|
||||||
|
// RATIONALE: The "var" keyword is deprecated because of its confusing "hoisting" behavior.
|
||||||
|
// Always use "let" or "const" instead.
|
||||||
|
//
|
||||||
|
// STANDARDIZED BY: @typescript-eslint\eslint-plugin\dist\configs\recommended.json
|
||||||
|
'no-var': 2,
|
||||||
|
// RATIONALE: Generally not needed in modern code.
|
||||||
|
'no-void': 1,
|
||||||
|
// RATIONALE: Obsolete language feature that is deprecated.
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'no-with': 2,
|
||||||
|
// RATIONALE: Makes logic easier to understand, since constants always have a known value
|
||||||
|
// @typescript-eslint\eslint-plugin\dist\configs\eslint-recommended.js
|
||||||
|
'prefer-const': 1,
|
||||||
|
// RATIONALE: Catches a common coding mistake where "resolve" and "reject" are confused.
|
||||||
|
'promise/param-names': 2,
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'require-atomic-updates': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'require-yield': 1,
|
||||||
|
// "Use strict" is redundant when using the TypeScript compiler.
|
||||||
|
'strict': [
|
||||||
|
2,
|
||||||
|
'never'
|
||||||
|
],
|
||||||
|
// RATIONALE: Catches code that is likely to be incorrect
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
'use-isnan': 2,
|
||||||
|
// STANDARDIZED BY: eslint\conf\eslint-recommended.js
|
||||||
|
// Set to 1 (warning) or 2 (error) to enable.
|
||||||
|
// Rationale to disable: !!{}
|
||||||
|
'no-extra-boolean-cast': 0,
|
||||||
|
// ====================================================================
|
||||||
|
// @microsoft/eslint-plugin-spfx
|
||||||
|
// ====================================================================
|
||||||
|
'@microsoft/spfx/import-requires-chunk-name': 1,
|
||||||
|
'@microsoft/spfx/no-require-ensure': 2,
|
||||||
|
'@microsoft/spfx/pair-react-dom-render-unmount': 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
// For unit tests, we can be a little bit less strict. The settings below revise the
|
||||||
|
// defaults specified in the extended configurations, as well as above.
|
||||||
|
files: [
|
||||||
|
// Test files
|
||||||
|
'*.test.ts',
|
||||||
|
'*.test.tsx',
|
||||||
|
'*.spec.ts',
|
||||||
|
'*.spec.tsx',
|
||||||
|
|
||||||
|
// Facebook convention
|
||||||
|
'**/__mocks__/*.ts',
|
||||||
|
'**/__mocks__/*.tsx',
|
||||||
|
'**/__tests__/*.ts',
|
||||||
|
'**/__tests__/*.tsx',
|
||||||
|
|
||||||
|
// Microsoft convention
|
||||||
|
'**/test/*.ts',
|
||||||
|
'**/test/*.tsx'
|
||||||
|
],
|
||||||
|
rules: {
|
||||||
|
'no-new': 0,
|
||||||
|
'class-name': 0,
|
||||||
|
'export-name': 0,
|
||||||
|
forin: 0,
|
||||||
|
'label-position': 0,
|
||||||
|
'member-access': 2,
|
||||||
|
'no-arg': 0,
|
||||||
|
'no-console': 0,
|
||||||
|
'no-construct': 0,
|
||||||
|
'no-duplicate-variable': 2,
|
||||||
|
'no-eval': 0,
|
||||||
|
'no-function-expression': 2,
|
||||||
|
'no-internal-module': 2,
|
||||||
|
'no-shadowed-variable': 2,
|
||||||
|
'no-switch-case-fall-through': 2,
|
||||||
|
'no-unnecessary-semicolons': 2,
|
||||||
|
'no-unused-expression': 2,
|
||||||
|
'no-with-statement': 2,
|
||||||
|
semicolon: 2,
|
||||||
|
'trailing-comma': 0,
|
||||||
|
typedef: 0,
|
||||||
|
'typedef-whitespace': 0,
|
||||||
|
'use-named-parameter': 2,
|
||||||
|
'variable-name': 0,
|
||||||
|
whitespace: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
node_modules
|
||||||
|
|
||||||
|
# Build generated files
|
||||||
|
dist
|
||||||
|
lib
|
||||||
|
release
|
||||||
|
solution
|
||||||
|
temp
|
||||||
|
*.sppkg
|
||||||
|
.heft
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# OSX
|
||||||
|
.DS_Store
|
||||||
|
|
||||||
|
# Visual Studio files
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
.vs
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
|
||||||
|
# Resx Generated Code
|
||||||
|
*.resx.ts
|
||||||
|
|
||||||
|
# Styles Generated Code
|
||||||
|
*.scss.ts
|
||||||
|
*.scss.d.ts
|
|
@ -0,0 +1,16 @@
|
||||||
|
!dist
|
||||||
|
config
|
||||||
|
|
||||||
|
gulpfile.js
|
||||||
|
|
||||||
|
release
|
||||||
|
src
|
||||||
|
temp
|
||||||
|
|
||||||
|
tsconfig.json
|
||||||
|
tslint.json
|
||||||
|
|
||||||
|
*.log
|
||||||
|
|
||||||
|
.yo-rc.json
|
||||||
|
.vscode
|
|
@ -0,0 +1,16 @@
|
||||||
|
{
|
||||||
|
"@microsoft/generator-sharepoint": {
|
||||||
|
"plusBeta": false,
|
||||||
|
"isCreatingSolution": false,
|
||||||
|
"version": "1.15.2",
|
||||||
|
"libraryName": "react-flighttracker",
|
||||||
|
"libraryId": "9bc5376d-4151-495b-8249-ebcc27ddf392",
|
||||||
|
"environment": "spo",
|
||||||
|
"packageManager": "npm",
|
||||||
|
"solutionName": "react-flighttracker",
|
||||||
|
"solutionShortDescription": "react-flighttracker description",
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"componentType": "webpart"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
This WebPart allows to track all flights from a selected airport, date and information type.
|
||||||
|
The SPFx use external API (https://aerodatabox.p.rapidapi.com/flights/number/) to get data of flight, please see https://rapidapi.com/aedbx-aedbx/api/aerodatabox/ to get more information. There is some restritions on this API, the number of requests is limited (free version)
|
||||||
|
|
||||||
|
![SharePoint View](assets/FQzNLB4XwAIFMRh.jpg "SharePoint View")
|
||||||
|
![Teams View](assets/FQzO9YjWUAgFlrU.jpg "Teams View")
|
||||||
|
|
||||||
|
## Compatibility
|
||||||
|
|
||||||
|
![SPFx 1.15](https://img.shields.io/badge/SPFx-1.15-green.svg)
|
||||||
|
![Node.js v14 | v12](https://img.shields.io/badge/Node.js-v14%20%7C%20v12-green.svg)
|
||||||
|
![Compatible with SharePoint Online](https://img.shields.io/badge/SharePoint%20Online-Compatible-green.svg)
|
||||||
|
![Does not work with SharePoint 2019](https://img.shields.io/badge/SharePoint%20Server%202019-Incompatible-red.svg "SharePoint Server 2019 requires SPFx 1.4.1 or lower")
|
||||||
|
![Does not work with SharePoint 2016 (Feature Pack 2)](https://img.shields.io/badge/SharePoint%20Server%202016%20(Feature%20Pack%202)-Incompatible-red.svg "SharePoint Server 2016 Feature Pack 2 requires SPFx 1.1")
|
||||||
|
![Local Workbench Unsupported](https://img.shields.io/badge/Local%20Workbench-Unsupported-red.svg "Local workbench is no longer available as of SPFx 1.13 and above")
|
||||||
|
![Hosted Workbench Compatible](https://img.shields.io/badge/Hosted%20Workbench-Compatible-green.svg)
|
||||||
|
![Compatible with Remote Containers](https://img.shields.io/badge/Remote%20Containers-Compatible-green.svg)
|
||||||
|
|
||||||
|
|
||||||
|
## Applies to
|
||||||
|
|
||||||
|
* [SharePoint Framework](https://learn.microsoft.com/sharepoint/dev/spfx/sharepoint-framework-overview)
|
||||||
|
* [Microsoft 365 tenant](https://learn.microsoft.com/sharepoint/dev/spfx/set-up-your-development-environment)
|
||||||
|
|
||||||
|
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
|
||||||
|
|
||||||
|
|
||||||
|
## Applies to
|
||||||
|
|
||||||
|
- [SharePoint Framework](https://aka.ms/spfx)
|
||||||
|
- [Microsoft 365 tenant](https://learn.microsoft.com/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
|
||||||
|
> Get your own free development tenant by subscribing to [Microsoft 365 developer program](http://aka.ms/o365devprogram)
|
||||||
|
|
||||||
|
## Solution
|
||||||
|
|
||||||
|
Solution|Author(s)
|
||||||
|
--------|---------
|
||||||
|
react-fluentui-9 | [Nick Brown](https://github.com/techienickb) ([@techienickb](https://twitter.com/techienickb) / [Jisc](https://jisc.ac.uk))
|
||||||
|
|
||||||
|
## Version history
|
||||||
|
|
||||||
|
Version|Date|Comments
|
||||||
|
-------|----|--------
|
||||||
|
1.0|April 20, 2022|Initial release
|
||||||
|
|
||||||
|
- Clone this repository (or [download this solution as a .ZIP file](https://pnp.github.io/download-partial/?url=https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/react-fluentui-9) then unzip it)
|
||||||
|
- From your command-line, change your current directory to the directory containing this sample (`react-fluentui-9`, located under `samples`)
|
||||||
|
- in the command-line run:
|
||||||
|
- `npm install`
|
||||||
|
- `gulp serve`
|
||||||
|
|
||||||
|
> This sample can also be opened with [VS Code Remote Development](https://code.visualstudio.com/docs/remote/remote-overview). Visit <https://aka.ms/spfx-devcontainer> for further instructions.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
Very simple demo, the handling of the theme provider is interesting implementing it and handling the custom themes SharePoint can use.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Getting started with SharePoint Framework](https://learn.microsoft.com/sharepoint/dev/spfx/set-up-your-developer-tenant)
|
||||||
|
- [Building for Microsoft teams](https://learn.microsoft.com/sharepoint/dev/spfx/build-for-teams-overview)
|
||||||
|
- [Use Microsoft Graph in your solution](https://learn.microsoft.com/sharepoint/dev/spfx/web-parts/get-started/using-microsoft-graph-apis)
|
||||||
|
- [Publish SharePoint Framework applications to the Marketplace](https://learn.microsoft.com/sharepoint/dev/spfx/publish-to-marketplace-overview)
|
||||||
|
- [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) - Guidance, tooling, samples and open-source controls for your Microsoft 365 development
|
||||||
|
- [Fluent UI version 9](https://github.com/microsoft/fluentui/tree/master/packages/react-components) - Converged Fluent UI components
|
||||||
|
|
||||||
|
## Help
|
||||||
|
|
||||||
|
We do not support samples, but this community is always willing to help, and we want to improve these samples. We use GitHub to track issues, which makes it easy for community members to volunteer their time and help resolve issues.
|
||||||
|
|
||||||
|
If you're having issues building the solution, please run [spfx doctor](https://pnp.github.io/cli-microsoft365/cmd/spfx/spfx-doctor/) from within the solution folder to diagnose incompatibility issues with your environment.
|
||||||
|
|
||||||
|
You can try looking at [issues related to this sample](https://github.com/pnp/sp-dev-fx-webparts/issues?q=label%3A%22sample%3A%20react-fluentui-9%22) to see if anybody else is having the same issues.
|
||||||
|
|
||||||
|
You can also try looking at [discussions related to this sample](https://github.com/pnp/sp-dev-fx-webparts/discussions?discussions_q=react-fluentui-9) and see what the community is saying.
|
||||||
|
|
||||||
|
If you encounter any issues using this sample, [create a new issue](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Abug-suspected%2Csample%3A%20react-fluentui-9&template=bug-report.yml&sample=react-fluentui-9&authors=@techienickb&title=react-fluentui-9%20-%20).
|
||||||
|
|
||||||
|
For questions regarding this sample, [create a new question](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aquestion%2Csample%3A%20react-fluentui-9&template=question.yml&sample=react-fluentui-9&authors=@techienickb&title=react-fluentui-9%20-%20).
|
||||||
|
|
||||||
|
Finally, if you have an idea for improvement, [make a suggestion](https://github.com/pnp/sp-dev-fx-webparts/issues/new?assignees=&labels=Needs%3A+Triage+%3Amag%3A%2Ctype%3Aenhancement%2Csample%3A%20react-fluentui-9&template=suggestion.yml&sample=react-fluentui-9&authors=@techienickb&title=react-fluentui-9%20-%20).
|
||||||
|
|
||||||
|
## Disclaimer
|
||||||
|
|
||||||
|
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
|
||||||
|
|
||||||
|
<img src="https://pnptelemetry.azurewebsites.net/sp-dev-fx-webparts/samples/react-fluentui-9" />
|
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
|
||||||
|
"version": "2.0",
|
||||||
|
"bundles": {
|
||||||
|
"flight-tracker-web-part": {
|
||||||
|
"components": [
|
||||||
|
{
|
||||||
|
"entrypoint": "./lib/webparts/flightTracker/FlightTrackerWebPart.js",
|
||||||
|
"manifest": "./src/webparts/flightTracker/FlightTrackerWebPart.manifest.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"externals": {},
|
||||||
|
"localizedResources": {
|
||||||
|
"FlightTrackerWebPartStrings": "lib/webparts/flightTracker/loc/{locale}.js",
|
||||||
|
"ControlStrings": "node_modules/@pnp/spfx-controls-react/lib/loc/{locale}.js"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
|
||||||
|
"workingDir": "./release/assets/",
|
||||||
|
"account": "<!-- STORAGE ACCOUNT NAME -->",
|
||||||
|
"container": "react-flighttracker",
|
||||||
|
"accessKey": "<!-- ACCESS KEY -->"
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
|
||||||
|
"solution": {
|
||||||
|
"name": "react-flighttracker-client-side-solution",
|
||||||
|
"id": "9bc5376d-4151-495b-8249-ebcc27ddf392",
|
||||||
|
"version": "1.0.0.0",
|
||||||
|
"includeClientSideAssets": true,
|
||||||
|
"skipFeatureDeployment": true,
|
||||||
|
"isDomainIsolated": false,
|
||||||
|
"developer": {
|
||||||
|
"name": "",
|
||||||
|
"websiteUrl": "",
|
||||||
|
"privacyUrl": "",
|
||||||
|
"termsOfUseUrl": "",
|
||||||
|
"mpnId": "Undefined-1.15.2"
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"shortDescription": {
|
||||||
|
"default": "react-flighttracker description"
|
||||||
|
},
|
||||||
|
"longDescription": {
|
||||||
|
"default": "react-flighttracker description"
|
||||||
|
},
|
||||||
|
"screenshotPaths": [],
|
||||||
|
"videoUrl": "",
|
||||||
|
"categories": []
|
||||||
|
},
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"title": "react-flighttracker Feature",
|
||||||
|
"description": "The feature that activates elements of the react-flighttracker solution.",
|
||||||
|
"id": "22de90a6-9357-425b-921a-92f3b37d4a3b",
|
||||||
|
"version": "1.0.0.0"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"paths": {
|
||||||
|
"zippedPackage": "solution/react-flighttracker.sppkg"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/spfx-serve.schema.json",
|
||||||
|
"port": 4321,
|
||||||
|
"https": true,
|
||||||
|
"initialPage": "https://enter-your-SharePoint-site/_layouts/workbench.aspx"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
|
||||||
|
"cdnBasePath": "<!-- PATH TO CDN -->"
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://raw.githubusercontent.com/s-KaiNet/spfx-fast-serve/master/schema/config.latest.schema.json",
|
||||||
|
"cli": {
|
||||||
|
"isLibraryComponent": false
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* User webpack settings file. You can add your own settings here.
|
||||||
|
* Changes from this file will be merged into the base webpack configuration file.
|
||||||
|
* This file will not be overwritten by the subsequent spfx-fast-serve calls.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// you can add your project related webpack configuration here, it will be merged using webpack-merge module
|
||||||
|
// i.e. plugins: [new webpack.Plugin()]
|
||||||
|
const webpackConfig = {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// for even more fine-grained control, you can apply custom webpack settings using below function
|
||||||
|
const transformConfig = function (initialWebpackConfig) {
|
||||||
|
// transform the initial webpack config here, i.e.
|
||||||
|
// initialWebpackConfig.plugins.push(new webpack.Plugin()); etc.
|
||||||
|
|
||||||
|
return initialWebpackConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
webpackConfig,
|
||||||
|
transformConfig
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const build = require('@microsoft/sp-build-web');
|
||||||
|
|
||||||
|
build.addSuppression(`Warning - [sass] The local CSS class 'ms-Grid' is not camelCase and will not be type-safe.`);
|
||||||
|
|
||||||
|
var getTasks = build.rig.getTasks;
|
||||||
|
build.rig.getTasks = function () {
|
||||||
|
var result = getTasks.call(build.rig);
|
||||||
|
|
||||||
|
result.set('serve', result.get('serve-deprecated'));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* fast-serve */
|
||||||
|
const { addFastServe } = require("spfx-fast-serve-helpers");
|
||||||
|
addFastServe(build);
|
||||||
|
/* end of fast-serve */
|
||||||
|
|
||||||
|
build.initialize(require('gulp'));
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"name": "react-flighttracker",
|
||||||
|
"version": "0.0.1",
|
||||||
|
"private": true,
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "gulp bundle",
|
||||||
|
"clean": "gulp clean",
|
||||||
|
"test": "gulp test",
|
||||||
|
"serve": "gulp bundle --custom-serve --max_old_space_size=4096 && fast-serve"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@fluentui/react": "^8.100.0",
|
||||||
|
"@microsoft/sp-core-library": "1.15.2",
|
||||||
|
"@microsoft/sp-lodash-subset": "1.15.2",
|
||||||
|
"@microsoft/sp-office-ui-fabric-core": "1.15.2",
|
||||||
|
"@microsoft/sp-property-pane": "1.15.2",
|
||||||
|
"@microsoft/sp-webpart-base": "1.15.2",
|
||||||
|
"@pnp/spfx-controls-react": "^3.11.0",
|
||||||
|
"axios": "^0.27.2",
|
||||||
|
"date-fns": "^2.29.2",
|
||||||
|
"office-ui-fabric-react": "7.185.7",
|
||||||
|
"react": "16.13.1",
|
||||||
|
"react-dom": "16.13.1",
|
||||||
|
"recoil": "^0.7.5",
|
||||||
|
"tslib": "2.3.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@microsoft/rush-stack-compiler-4.5": "0.2.2",
|
||||||
|
"@rushstack/eslint-config": "2.5.1",
|
||||||
|
"@microsoft/eslint-plugin-spfx": "1.15.2",
|
||||||
|
"@microsoft/eslint-config-spfx": "1.15.2",
|
||||||
|
"@microsoft/sp-build-web": "1.15.2",
|
||||||
|
"@types/webpack-env": "~1.15.2",
|
||||||
|
"ajv": "^6.12.5",
|
||||||
|
"gulp": "4.0.2",
|
||||||
|
"typescript": "4.5.5",
|
||||||
|
"@types/react": "16.9.51",
|
||||||
|
"@types/react-dom": "16.9.8",
|
||||||
|
"eslint-plugin-react-hooks": "4.3.0",
|
||||||
|
"@microsoft/sp-module-interfaces": "1.15.2",
|
||||||
|
"spfx-fast-serve-helpers": "~1.15.0"
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 267 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 250 KiB |
After Width: | Height: | Size: 453 KiB |
After Width: | Height: | Size: 1.7 MiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,30 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { SelectAirportPicker } from '../SelectAirport/SelectAirportPicker';
|
||||||
|
import { SelectDate } from '../SelectDate/SelectDate';
|
||||||
|
import {
|
||||||
|
SelectInformationType,
|
||||||
|
} from '../SelectInformationType/SelectInformationType';
|
||||||
|
import {
|
||||||
|
useFlightAeroportOptionsStyles,
|
||||||
|
} from './useFlightAirportOptionsStyles';
|
||||||
|
|
||||||
|
export interface IFlightAeroportOptionsProps { }
|
||||||
|
|
||||||
|
export const FlightAirportOptions: React.FunctionComponent<IFlightAeroportOptionsProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightAeroportOptionsProps>
|
||||||
|
) => {
|
||||||
|
const { controlsStyles } = useFlightAeroportOptionsStyles();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className={controlsStyles.container}>
|
||||||
|
<div className={controlsStyles.containerGrid}>
|
||||||
|
<SelectAirportPicker />
|
||||||
|
<SelectDate />
|
||||||
|
|
||||||
|
<SelectInformationType />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './FlightAirportOptions';
|
||||||
|
export * from './useFlightAirportOptionsStyles';
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
import * as react from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IStackStyles,
|
||||||
|
mergeStyleSets,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
|
||||||
|
export const useFlightAeroportOptionsStyles = () => {
|
||||||
|
|
||||||
|
const [ globalStateApp ] = useRecoilState(globalState);
|
||||||
|
const { currentTheme } = globalStateApp;
|
||||||
|
|
||||||
|
const stackContainer : IStackStyles = react.useMemo(()=> {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
marginTop: 30,
|
||||||
|
width: "100%",
|
||||||
|
paddingTop: 20,
|
||||||
|
paddingBottom: 20,
|
||||||
|
paddingLeft: 20,
|
||||||
|
paddingRight: 20,
|
||||||
|
backgroundColor: currentTheme?.palette?.neutralLighterAlt,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},[currentTheme]);
|
||||||
|
|
||||||
|
const controlsStyles = react.useMemo(() => {
|
||||||
|
return mergeStyleSets({
|
||||||
|
containerGrid: {
|
||||||
|
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 300px), 1fr))",
|
||||||
|
columnGap: "10px",
|
||||||
|
rowGap: "0.5em",
|
||||||
|
|
||||||
|
},
|
||||||
|
container: {
|
||||||
|
paddingTop: 20,
|
||||||
|
paddingBottom: 20,
|
||||||
|
paddingLeft: 20,
|
||||||
|
paddingRight: 20,
|
||||||
|
marginTop: 10,
|
||||||
|
backgroundColor: currentTheme?.palette?.neutralLighterAlt,
|
||||||
|
|
||||||
|
},
|
||||||
|
header: {
|
||||||
|
display: "flex",
|
||||||
|
flexFlow: "row nowrap",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
width: "100%",
|
||||||
|
height: "50px",
|
||||||
|
padding: "10px",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
fontSize: "1.5rem",
|
||||||
|
fontWeight: "bold",
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
display: "flex",
|
||||||
|
flexFlow: "column nowrap",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
padding: "10px",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
},
|
||||||
|
footer: {
|
||||||
|
display: "flex",
|
||||||
|
flexFlow: "row nowrap",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
width: "100%",
|
||||||
|
height: "50px",
|
||||||
|
padding: "10px",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
|
||||||
|
return {stackContainer, controlsStyles}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
|
||||||
|
import {
|
||||||
|
FlightAirportOptions,
|
||||||
|
} from '../FlightAirportOptions/FlightAirportOptions';
|
||||||
|
|
||||||
|
export interface IFlightSelectorProps { }
|
||||||
|
|
||||||
|
export const FlightSelector: React.FunctionComponent<IFlightSelectorProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightSelectorProps>
|
||||||
|
) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack >
|
||||||
|
<FlightAirportOptions />
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './FlightSelector';
|
||||||
|
export * from './useFlightSelectorStyles';
|
|
@ -0,0 +1,16 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
import * as react from 'react';
|
||||||
|
|
||||||
|
import { IStackStyles } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
|
||||||
|
export const useFlightSelectorStyles = () => {
|
||||||
|
const stackContainer : IStackStyles = react.useMemo(()=> {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
paddingTop: 10,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},[]);
|
||||||
|
|
||||||
|
return {stackContainer}
|
||||||
|
};
|
|
@ -0,0 +1,46 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { Text } from 'office-ui-fabric-react';
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
|
||||||
|
import { EStatus } from '../../constants';
|
||||||
|
import { IFlightStatus } from '../../models/IFlightStatus';
|
||||||
|
import { useFlightStatusStyles } from './useFlightStatusStyles';
|
||||||
|
|
||||||
|
export interface IFlightStatusProps {
|
||||||
|
flightInfo: IFlightStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FlightStatus: React.FunctionComponent<IFlightStatusProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightStatusProps>
|
||||||
|
) => {
|
||||||
|
const { flightInfo } = props;
|
||||||
|
const { status, date } = flightInfo;
|
||||||
|
const { getFlightStatusStyles } = useFlightStatusStyles();
|
||||||
|
|
||||||
|
|
||||||
|
const statusDescription = React.useMemo((): string => {
|
||||||
|
switch (status) {
|
||||||
|
case EStatus.Unknown:
|
||||||
|
case EStatus.CanceledUncertain:
|
||||||
|
return "Not Available";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return status;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}, [status]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack horizontalAlign="start">
|
||||||
|
<Stack horizontalAlign="start" verticalAlign="center">
|
||||||
|
<Text variant="medium" styles={getFlightStatusStyles(status)}>
|
||||||
|
{statusDescription}
|
||||||
|
</Text>
|
||||||
|
<Text variant="small"> {date}</Text>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './FlightStatus';
|
||||||
|
export * from './useFlightStatusStyles';
|
|
@ -0,0 +1,35 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
FontSizes,
|
||||||
|
FontWeights,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { ITextStyles } from 'office-ui-fabric-react/lib/components/Text';
|
||||||
|
import { IImageStyles } from 'office-ui-fabric-react/lib/Image';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { useUtils } from '../../hooks/useUtils';
|
||||||
|
import { globalState } from '../../recoil/atoms/globalState';
|
||||||
|
|
||||||
|
export const useFlightStatusStyles = () => {
|
||||||
|
const [appState, setGlobalState] = useRecoilState(globalState);
|
||||||
|
const { currentTheme } = appState;
|
||||||
|
const { getFlightStatusColor } = useUtils();
|
||||||
|
const imageStyles: Partial<IImageStyles> = {
|
||||||
|
root: { border: "1px solid ", borderRadius: "50%", padding: 5 },
|
||||||
|
};
|
||||||
|
|
||||||
|
const getFlightStatusStyles = React.useCallback((status:string): ITextStyles => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
color: getFlightStatusColor(status),
|
||||||
|
fontWeight: FontWeights.bold,
|
||||||
|
FontSizes: FontSizes.mediumPlus,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [getFlightStatusColor]);
|
||||||
|
|
||||||
|
return { imageStyles,getFlightStatusStyles };
|
||||||
|
};
|
|
@ -0,0 +1,34 @@
|
||||||
|
@import '~office-ui-fabric-react/dist/sass/References.scss';
|
||||||
|
|
||||||
|
.flightTracker {
|
||||||
|
overflow: hidden;
|
||||||
|
padding: 1em;
|
||||||
|
color: "[theme:bodyText, default: #323130]";
|
||||||
|
color: var(--bodyText);
|
||||||
|
&.teams {
|
||||||
|
font-family: $ms-font-family-fallbacks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcome {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.welcomeImage {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 420px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.links {
|
||||||
|
a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: "[theme:link, default:#03787c]";
|
||||||
|
color: var(--link); // note: CSS Custom Properties support is limited to modern browsers only
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
color: "[theme:linkHovered, default: #014446]";
|
||||||
|
color: var(--linkHovered); // note: CSS Custom Properties support is limited to modern browsers only
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { RecoilRoot } from 'recoil';
|
||||||
|
|
||||||
|
import {
|
||||||
|
EnhancedThemeProvider,
|
||||||
|
} from '@pnp/spfx-controls-react/lib/EnhancedThemeProvider';
|
||||||
|
|
||||||
|
import { FlightTrackerControl } from './FlightTrackerControl';
|
||||||
|
import { IFlightTrackerProps } from './IFlightTrackerProps';
|
||||||
|
|
||||||
|
export const FlightTracker: React.FunctionComponent<IFlightTrackerProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightTrackerProps>
|
||||||
|
) => {
|
||||||
|
const { currentTheme } = props;
|
||||||
|
return (
|
||||||
|
<EnhancedThemeProvider context={props.context} theme={currentTheme}>
|
||||||
|
<section>
|
||||||
|
<RecoilRoot>
|
||||||
|
<FlightTrackerControl {...props} />
|
||||||
|
</RecoilRoot>
|
||||||
|
</section>
|
||||||
|
</EnhancedThemeProvider>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,40 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { Stack } from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { WebPartTitle } from '@pnp/spfx-controls-react/lib/WebPartTitle';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms/globalState';
|
||||||
|
import { FlightSelector } from '../FlightSelector/FlightSelector';
|
||||||
|
import { FlightTrackerList } from '../FlightTrackerList/FlightTrackerList';
|
||||||
|
import { IFlightTrackerProps } from './IFlightTrackerProps';
|
||||||
|
|
||||||
|
export const FlightTrackerControl: React.FunctionComponent<IFlightTrackerProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightTrackerProps>
|
||||||
|
) => {
|
||||||
|
const { isDarkTheme, hasTeamsContext, currentTheme, context, title, updateProperty, displayMode,numberItemsPerPage , webpartContainerWidth } = props;
|
||||||
|
const [appState, setGlobalState] = useRecoilState(globalState);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setGlobalState({
|
||||||
|
...appState,
|
||||||
|
isDarkTheme: isDarkTheme,
|
||||||
|
hasTeamsContext: hasTeamsContext,
|
||||||
|
currentTheme: currentTheme,
|
||||||
|
context: context,
|
||||||
|
numberItemsPerPage: numberItemsPerPage,
|
||||||
|
webpartContainerWidth: webpartContainerWidth,
|
||||||
|
});
|
||||||
|
}, [isDarkTheme, hasTeamsContext, currentTheme, context, setGlobalState, webpartContainerWidth]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<WebPartTitle displayMode={displayMode} title={title} updateProperty={updateProperty} themeVariant={currentTheme}/>
|
||||||
|
<Stack tokens={{ childrenGap: 10 }}>
|
||||||
|
<FlightSelector />
|
||||||
|
<FlightTrackerList />
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
||||||
|
import { DisplayMode } from '@microsoft/sp-core-library';
|
||||||
|
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||||
|
|
||||||
|
export interface IFlightTrackerProps {
|
||||||
|
title: string;
|
||||||
|
isDarkTheme: boolean;
|
||||||
|
hasTeamsContext: boolean;
|
||||||
|
currentTheme: IReadonlyTheme | undefined;
|
||||||
|
context: WebPartContext
|
||||||
|
numberItemsPerPage: number;
|
||||||
|
displayMode: DisplayMode;
|
||||||
|
updateProperty: (value: string) => void;
|
||||||
|
webpartContainerWidth: number;
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
export * from './FlightTracker.module.scss';
|
||||||
|
export * from './FlightTracker';
|
||||||
|
export * from './FlightTrackerControl';
|
||||||
|
export * from './IFlightTrackerProps';
|
|
@ -0,0 +1,169 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
addHours,
|
||||||
|
getHours,
|
||||||
|
getMinutes,
|
||||||
|
set,
|
||||||
|
} from 'date-fns';
|
||||||
|
import { MessageBarType } from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { isEmpty } from '@microsoft/sp-lodash-subset';
|
||||||
|
|
||||||
|
import { useAirlines } from '../../hooks/useAirlines';
|
||||||
|
import { useFlightSchedule } from '../../hooks/useFlightSchedules';
|
||||||
|
import {
|
||||||
|
useMappingFlightSchedules,
|
||||||
|
} from '../../hooks/useMappingFlightShedules';
|
||||||
|
import {
|
||||||
|
IFlights,
|
||||||
|
IFlightTrackerListItem,
|
||||||
|
IGlobalState,
|
||||||
|
} from '../../models';
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
import { airlineState } from '../../recoil/atoms/airlineState';
|
||||||
|
import { ShowList } from '../ShowList';
|
||||||
|
import { ShowMessage } from '../ShowMessage/ShowMessage';
|
||||||
|
import { ShowSpinner } from '../ShowSpinner';
|
||||||
|
|
||||||
|
const DEFAULT_ITEMS_TO_LOAD = 7;
|
||||||
|
|
||||||
|
export interface IFlightTrackerListProps {}
|
||||||
|
|
||||||
|
export const FlightTrackerList: React.FunctionComponent<IFlightTrackerListProps> = () => {
|
||||||
|
const [appState, setGlobalState] = useRecoilState(globalState);
|
||||||
|
const [airlineList, setAirlineList] = useRecoilState(airlineState);
|
||||||
|
const { mapFlightSchedules } = useMappingFlightSchedules();
|
||||||
|
const { selectedAirPort, selectedInformationType, selectedDate, numberItemsPerPage, selectedTime } = appState;
|
||||||
|
const [isLoadingItems, setIsLoadingItems] = React.useState<boolean>(true);
|
||||||
|
const [errorMessage, setErrorMessage] = React.useState<string>("");
|
||||||
|
const [listItems, setListItems] = React.useState<IFlightTrackerListItem[]>([]);
|
||||||
|
const [flights, setFlights] = React.useState<IFlights>(undefined);
|
||||||
|
const [errorFlightSchedules, setErrorFlightSchedules] = React.useState<Error>();
|
||||||
|
const [isLoadingFlightSchedules, setIsLoadingFlightSchedules] = React.useState<boolean>(false);
|
||||||
|
const [isRefreshing, setIsRefreshing] = React.useState<boolean>(false);
|
||||||
|
const { getFlightSchedule } = useFlightSchedule();
|
||||||
|
const { airlines, errorLoadingAirlines, loadingAirlines } = useAirlines();
|
||||||
|
const [hasMore, setHasMore] = React.useState<boolean>(true);
|
||||||
|
const pageIndex = React.useRef<number>(0);
|
||||||
|
const currentInformationType = React.useRef(selectedInformationType);
|
||||||
|
|
||||||
|
const checkTypeInformationToScroll = React.useCallback(() => {
|
||||||
|
if (selectedInformationType !== currentInformationType.current) {
|
||||||
|
pageIndex.current = 0;
|
||||||
|
currentInformationType.current = selectedInformationType;
|
||||||
|
}
|
||||||
|
}, [selectedInformationType]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (!isEmpty(airlines)) {
|
||||||
|
setAirlineList(airlines);
|
||||||
|
}
|
||||||
|
}, [airlines]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
if (airlineList) {
|
||||||
|
try {
|
||||||
|
setIsLoadingFlightSchedules(true);
|
||||||
|
const searchDate: Date = set(selectedDate, {
|
||||||
|
hours: getHours(selectedTime),
|
||||||
|
minutes: getMinutes(selectedTime),
|
||||||
|
seconds: 0,
|
||||||
|
milliseconds: 0,
|
||||||
|
});
|
||||||
|
const flightSchedule = await getFlightSchedule({
|
||||||
|
fromDate: searchDate.toISOString(),
|
||||||
|
toDate: addHours(searchDate, 12).toISOString(), // maximuum 12 hours interval is supported by the API
|
||||||
|
airportCode: selectedAirPort?.gps_code,
|
||||||
|
});
|
||||||
|
setFlights(flightSchedule);
|
||||||
|
setIsLoadingFlightSchedules(false);
|
||||||
|
} catch (error) {
|
||||||
|
setErrorFlightSchedules(error);
|
||||||
|
setIsLoadingFlightSchedules(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
}, [airlineList, selectedAirPort, selectedDate, selectedTime, selectedInformationType, isRefreshing]);
|
||||||
|
|
||||||
|
const loadItems = React.useCallback(
|
||||||
|
async (pageIndex: number): Promise<IFlightTrackerListItem[]> => {
|
||||||
|
const numberItemsToLoad = numberItemsPerPage ? numberItemsPerPage + 1 : DEFAULT_ITEMS_TO_LOAD;
|
||||||
|
const mappedFlightSchedules = await mapFlightSchedules(
|
||||||
|
selectedInformationType,
|
||||||
|
flights,
|
||||||
|
pageIndex,
|
||||||
|
numberItemsToLoad
|
||||||
|
);
|
||||||
|
return mappedFlightSchedules;
|
||||||
|
},
|
||||||
|
[flights, numberItemsPerPage, selectedInformationType]
|
||||||
|
);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
if (flights) {
|
||||||
|
setIsLoadingItems(true);
|
||||||
|
|
||||||
|
const mappedFlightSchedules = await loadItems(0);
|
||||||
|
setListItems(mappedFlightSchedules);
|
||||||
|
setIsLoadingItems(false);
|
||||||
|
setHasMore((prevHasMore) => (mappedFlightSchedules?.length > 0 ? true : false));
|
||||||
|
}
|
||||||
|
setIsRefreshing((prevState) => (prevState === true ? false : prevState));
|
||||||
|
})();
|
||||||
|
}, [flights]);
|
||||||
|
|
||||||
|
const onScroll = React.useCallback(async () => {
|
||||||
|
if (hasMore) {
|
||||||
|
checkTypeInformationToScroll();
|
||||||
|
pageIndex.current = pageIndex.current + 1;
|
||||||
|
const mappedFlightSchedules = (await loadItems(pageIndex.current)) ?? [];
|
||||||
|
setListItems((prevListItems) => [...prevListItems, ...mappedFlightSchedules]);
|
||||||
|
setHasMore((prevHasMore) => (mappedFlightSchedules?.length > 0 ? true : false));
|
||||||
|
}
|
||||||
|
}, [hasMore, loadItems]);
|
||||||
|
|
||||||
|
const showMessage = React.useMemo((): boolean => {
|
||||||
|
setIsLoadingItems(false);
|
||||||
|
setErrorMessage(errorFlightSchedules?.message);
|
||||||
|
return !!errorFlightSchedules;
|
||||||
|
}, [errorFlightSchedules, setErrorMessage]);
|
||||||
|
|
||||||
|
const showSpinner = React.useMemo((): boolean => {
|
||||||
|
return (isLoadingFlightSchedules || loadingAirlines || isLoadingItems) && !showMessage;
|
||||||
|
}, [isLoadingFlightSchedules, loadingAirlines, isLoadingItems, errorFlightSchedules]);
|
||||||
|
|
||||||
|
const onRefresh = React.useCallback(async () => {
|
||||||
|
pageIndex.current = 0;
|
||||||
|
const currentDateTime = new Date();
|
||||||
|
setGlobalState((prevState) => ({
|
||||||
|
...prevState,
|
||||||
|
selectedDate: currentDateTime,
|
||||||
|
selectedTime: currentDateTime,
|
||||||
|
} as IGlobalState));
|
||||||
|
setIsRefreshing(true);
|
||||||
|
}, [appState]);
|
||||||
|
|
||||||
|
if (!selectedAirPort || !selectedInformationType) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<ShowMessage isShow={showMessage} message={errorMessage} messageBarType={MessageBarType.error} />
|
||||||
|
<ShowSpinner isShow={showSpinner} />
|
||||||
|
<ShowList
|
||||||
|
showList={!showSpinner && !showMessage}
|
||||||
|
listItems={listItems}
|
||||||
|
onScroll={onScroll}
|
||||||
|
onRefresh={onRefresh}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,110 @@
|
||||||
|
/* eslint-disable react/self-closing-comp */
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import * as strings from 'FlightTrackerWebPartStrings';
|
||||||
|
import {
|
||||||
|
IImageProps,
|
||||||
|
Stack,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
|
||||||
|
import { EInformationType } from '../../constants/EInformationType';
|
||||||
|
import { IFlightTrackerListItem } from '../../models/IFlightTrackerListItem';
|
||||||
|
import { FlightStatus } from '../FlightStatus/FlightStatus';
|
||||||
|
import {
|
||||||
|
FlightTrackerListItemAttribute,
|
||||||
|
} from './FlightTrackerListItemAttribute';
|
||||||
|
import { RenderAttribute } from './RenderAttribute';
|
||||||
|
import { useFlightTrackerStyles } from './useFlightTrackerStyles';
|
||||||
|
|
||||||
|
export interface IFlightTrackerListItemProps {
|
||||||
|
flights: IFlightTrackerListItem;
|
||||||
|
flightInformationType: EInformationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FlightTrackerListItem: React.FunctionComponent<IFlightTrackerListItemProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightTrackerListItemProps>
|
||||||
|
) => {
|
||||||
|
const { flights, flightInformationType } = props;
|
||||||
|
const { itemContainer, controlStyles } = useFlightTrackerStyles();
|
||||||
|
|
||||||
|
const imageProps: IImageProps = React.useMemo(() => {
|
||||||
|
return { src: flights.flightCompanyImage, width: 22, height: 22 };
|
||||||
|
}, [flights.flightCompanyImage]);
|
||||||
|
const divRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div ref={divRef}>
|
||||||
|
<Stack styles={itemContainer}>
|
||||||
|
<div className={controlStyles.attributeContainerGrid}>
|
||||||
|
<RenderAttribute>
|
||||||
|
<FlightTrackerListItemAttribute
|
||||||
|
attribute={{
|
||||||
|
attributeName: strings.AirLineLabel,
|
||||||
|
attributeValue: flights.flightCompany,
|
||||||
|
iconProps: { imageProps: imageProps },
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</RenderAttribute>
|
||||||
|
|
||||||
|
<RenderAttribute>
|
||||||
|
<FlightTrackerListItemAttribute
|
||||||
|
attribute={{
|
||||||
|
attributeName: strings.FlightLabel,
|
||||||
|
attributeValue: flights.flightNumber,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</RenderAttribute>
|
||||||
|
|
||||||
|
<RenderAttribute>
|
||||||
|
<FlightTrackerListItemAttribute
|
||||||
|
attribute={{
|
||||||
|
attributeName: strings.StartTimeLabel,
|
||||||
|
attributeValue: flights.flightTime,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</RenderAttribute>
|
||||||
|
|
||||||
|
<RenderAttribute>
|
||||||
|
<FlightTrackerListItemAttribute
|
||||||
|
attribute={{
|
||||||
|
attributeName: strings.TerminalLabel,
|
||||||
|
attributeValue: flights.flightTerminal,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</RenderAttribute>
|
||||||
|
|
||||||
|
<RenderAttribute>
|
||||||
|
<FlightTrackerListItemAttribute
|
||||||
|
attribute={{
|
||||||
|
attributeName: flightInformationType === EInformationType.ARRIVALS ? "Origin " : "Destination",
|
||||||
|
attributeValue: flights.flightOrigin,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</RenderAttribute>
|
||||||
|
|
||||||
|
<RenderAttribute>
|
||||||
|
<FlightTrackerListItemAttribute
|
||||||
|
attribute={{
|
||||||
|
attributeName: "",
|
||||||
|
attributeValue: (
|
||||||
|
<Stack style={{ paddingTop: 4 }}>
|
||||||
|
<FlightStatus
|
||||||
|
flightInfo={{
|
||||||
|
flightId: flights.flightNumber,
|
||||||
|
status: flights.flightTimeStatusText,
|
||||||
|
date: flights.flightRealTime,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</RenderAttribute>
|
||||||
|
</div>
|
||||||
|
</Stack>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,63 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Icon,
|
||||||
|
Text,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { IAttribute } from '../../models';
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
import { useFlightTrackerStyles } from './useFlightTrackerStyles';
|
||||||
|
|
||||||
|
export interface IFlightTrackerListItemAttributeProps {
|
||||||
|
attribute: IAttribute;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const FlightTrackerListItemAttribute: React.FunctionComponent<IFlightTrackerListItemAttributeProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightTrackerListItemAttributeProps>
|
||||||
|
) => {
|
||||||
|
const { attribute } = props;
|
||||||
|
const [appState] = useRecoilState(globalState);
|
||||||
|
const { controlStyles } = useFlightTrackerStyles();
|
||||||
|
const { webpartContainerWidth } = appState;
|
||||||
|
const [renderAttribute, setRenderAttribute] = React.useState<JSX.Element | null>(null);
|
||||||
|
|
||||||
|
const renderSeparator = React.useMemo(() => {
|
||||||
|
|
||||||
|
if (webpartContainerWidth && webpartContainerWidth <= 454) {
|
||||||
|
return <div className={controlStyles.separator} />;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}, [controlStyles.separator, webpartContainerWidth]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
setRenderAttribute(null);
|
||||||
|
|
||||||
|
setRenderAttribute(
|
||||||
|
<Stack verticalAlign="center" tokens={{ childrenGap: 10 }}>
|
||||||
|
<Text variant="smallPlus">{attribute.attributeName}</Text>
|
||||||
|
<Stack horizontal verticalAlign="center" tokens={{ childrenGap: 10 }}>
|
||||||
|
{attribute?.iconProps ? <Icon {...attribute.iconProps} /> : null}
|
||||||
|
{React.isValidElement(attribute.attributeValue) ? (
|
||||||
|
attribute.attributeValue
|
||||||
|
) : (
|
||||||
|
<Text variant="mediumPlus" styles={{ root: { fontWeight: 600 } }}>
|
||||||
|
{attribute.attributeValue}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
{renderSeparator}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
|
||||||
|
}, [attribute, renderSeparator]);
|
||||||
|
|
||||||
|
if (!attribute) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <>{renderAttribute}</>;
|
||||||
|
};
|
|
@ -0,0 +1,26 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import * as strings from 'FlightTrackerWebPartStrings';
|
||||||
|
import { Icon } from 'office-ui-fabric-react';
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
import { Text } from 'office-ui-fabric-react/lib/Text';
|
||||||
|
|
||||||
|
import { useFlightTrackerStyles } from './useFlightTrackerStyles';
|
||||||
|
|
||||||
|
const image = require("../../assets/Departing-bro.png");
|
||||||
|
export interface IFlightTrackerNoDataProps {}
|
||||||
|
|
||||||
|
export const FlightTrackerNoData: React.FunctionComponent<IFlightTrackerNoDataProps> = (
|
||||||
|
props: React.PropsWithChildren<IFlightTrackerNoDataProps>
|
||||||
|
) => {
|
||||||
|
const { controlStyles } = useFlightTrackerStyles();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack horizontalAlign="center" verticalAlign="center" tokens={{ childrenGap: 10 }} >
|
||||||
|
<Text variant="large">{strings.NoDataAvailableForAirport}</Text>
|
||||||
|
<Icon imageProps={{src: image , width:'100%'}} className={controlStyles.noDataFoundStyles} />
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,17 @@
|
||||||
|
import * as React from "react";
|
||||||
|
import { Text } from "office-ui-fabric-react";
|
||||||
|
export interface IRenderAttributeProps {}
|
||||||
|
|
||||||
|
export const RenderAttribute: React.FunctionComponent<IRenderAttributeProps> = (
|
||||||
|
props: React.PropsWithChildren<IRenderAttributeProps>
|
||||||
|
) => {
|
||||||
|
const { children } = props;
|
||||||
|
const childrens = React.Children.toArray(children);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{childrens.map((child) => {
|
||||||
|
return React.isValidElement(child) ? child : <Text>{child}</Text>;
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,7 @@
|
||||||
|
export * from './FlightTrackerList';
|
||||||
|
export * from './FlightTrackerListItem';
|
||||||
|
export * from './FlightTrackerListItemAttribute';
|
||||||
|
export * from './FlightTrackerNoData';
|
||||||
|
export * from './RenderAttribute';
|
||||||
|
|
||||||
|
export * from './useFlightTrackerStyles';
|
|
@ -0,0 +1,125 @@
|
||||||
|
/* eslint-disable react/self-closing-comp */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { IColumn } from 'office-ui-fabric-react/lib/DetailsList';
|
||||||
|
|
||||||
|
import { IFlightStatus } from '../../models/IFlightStatus';
|
||||||
|
import { IFlightTrackerListItem } from '../../models/IFlightTrackerListItem';
|
||||||
|
import { FlightStatus } from '../FlightStatus/FlightStatus';
|
||||||
|
import { useFlightTrackerStyles } from './useFlightTrackerStyles';
|
||||||
|
|
||||||
|
export interface IFlightTrackerListColumns {
|
||||||
|
getListColumns: () => IColumn[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useFlightTrackerListColumns = ():IFlightTrackerListColumns => {
|
||||||
|
const { controlStyles } = useFlightTrackerStyles();
|
||||||
|
|
||||||
|
const getListColumns = React.useCallback((): IColumn[] => {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
key: "column1",
|
||||||
|
name: " flightCompanyImage",
|
||||||
|
className: controlStyles.fileIconCell,
|
||||||
|
iconClassName: controlStyles.fileIconHeaderIcon,
|
||||||
|
ariaLabel: "company image",
|
||||||
|
isIconOnly: true,
|
||||||
|
fieldName: "image",
|
||||||
|
minWidth: 70,
|
||||||
|
maxWidth: 70,
|
||||||
|
onRender: (item: IFlightTrackerListItem) => {
|
||||||
|
return (
|
||||||
|
<img src={item.flightCompanyImage} style={{width: 28, height: 28}} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "column2",
|
||||||
|
name: "Air line",
|
||||||
|
fieldName: "flightCompany",
|
||||||
|
minWidth: 210,
|
||||||
|
maxWidth: 210,
|
||||||
|
isRowHeader: true,
|
||||||
|
isResizable: true,
|
||||||
|
data: "string",
|
||||||
|
isPadded: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "column6",
|
||||||
|
|
||||||
|
name: "Flight",
|
||||||
|
fieldName: "flightNumber",
|
||||||
|
minWidth: 70,
|
||||||
|
maxWidth: 90,
|
||||||
|
isResizable: true,
|
||||||
|
isCollapsible: true,
|
||||||
|
data: "number",
|
||||||
|
onRender: (item: IFlightTrackerListItem) => {
|
||||||
|
return <span>{item.flightNumber}</span>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "column3",
|
||||||
|
name: "time",
|
||||||
|
fieldName: "flightTime",
|
||||||
|
minWidth: 70,
|
||||||
|
maxWidth: 90,
|
||||||
|
isResizable: true,
|
||||||
|
|
||||||
|
data: "number",
|
||||||
|
onRender: (item: IFlightTrackerListItem) => {
|
||||||
|
return <span>{item.flightTime}</span>;
|
||||||
|
},
|
||||||
|
isPadded: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "column4",
|
||||||
|
name: "Terminal",
|
||||||
|
fieldName: "flightTerminal",
|
||||||
|
minWidth: 70,
|
||||||
|
maxWidth: 90,
|
||||||
|
isResizable: true,
|
||||||
|
isCollapsible: true,
|
||||||
|
data: "string",
|
||||||
|
|
||||||
|
onRender: (item: IFlightTrackerListItem) => {
|
||||||
|
return <span>{item.flightTerminal}</span>;
|
||||||
|
},
|
||||||
|
isPadded: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "column5",
|
||||||
|
name: "Origem",
|
||||||
|
fieldName: "flightOrigin",
|
||||||
|
minWidth: 150,
|
||||||
|
maxWidth: 150,
|
||||||
|
isResizable: true,
|
||||||
|
isCollapsible: true,
|
||||||
|
data: "number",
|
||||||
|
onRender: (item: IFlightTrackerListItem) => {
|
||||||
|
return <span>{item.flightOrigin}</span>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
key: "column6",
|
||||||
|
name: "Status",
|
||||||
|
fieldName: "flightTimeStatus",
|
||||||
|
minWidth: 70,
|
||||||
|
maxWidth: 90,
|
||||||
|
isResizable: true,
|
||||||
|
isCollapsible: true,
|
||||||
|
data: "number",
|
||||||
|
onRender: (item: IFlightTrackerListItem) => {
|
||||||
|
const flightInfo:IFlightStatus = {
|
||||||
|
date: item.flightRealTime, status: item.flightTimeStatusText,
|
||||||
|
flightId: item.flightNumber
|
||||||
|
};
|
||||||
|
return <FlightStatus flightInfo={flightInfo}/>;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {getListColumns }
|
||||||
|
};
|
|
@ -0,0 +1,136 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
FontWeights,
|
||||||
|
IScrollablePaneStyles,
|
||||||
|
IStackStyles,
|
||||||
|
ITextStyles,
|
||||||
|
mergeStyles,
|
||||||
|
mergeStyleSets,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
|
||||||
|
export const useFlightTrackerStyles = () => {
|
||||||
|
const [globalStateApp] = useRecoilState(globalState);
|
||||||
|
const { currentTheme } = globalStateApp;
|
||||||
|
|
||||||
|
const listHeaderStyles: ITextStyles = React.useMemo(() => {
|
||||||
|
return { root: { fontWeight: FontWeights.semibold, color: currentTheme?.semanticColors?.bodyText } };
|
||||||
|
}, [currentTheme]);
|
||||||
|
const itemContainer: IStackStyles = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
maxWidth: "100%",
|
||||||
|
overflow: "auto",
|
||||||
|
paddingTop: 10,
|
||||||
|
paddingBottom: 10,
|
||||||
|
paddingLeft: 20,
|
||||||
|
paddingRight: 20,
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: currentTheme?.palette?.neutralQuaternaryAlt,
|
||||||
|
margin: 3,
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
// boxShadow: "0 5px 15px rgba(50, 50, 90, .1)",
|
||||||
|
":hover": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: currentTheme?.palette?.themePrimary,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const attributeContainer: IStackStyles = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
|
||||||
|
backgroundColor: currentTheme?.palette?.themeLighterAlt,
|
||||||
|
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const scollableContainerStyles: Partial<IScrollablePaneStyles> = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: { position: "relative", height: 87 * 6 ,
|
||||||
|
},
|
||||||
|
contentContainer: { "::-webkit-scrollbar-thumb": {
|
||||||
|
|
||||||
|
backgroundColor: currentTheme?.semanticColors.bodyFrameBackground , },
|
||||||
|
"::-webkit-scrollbar": {
|
||||||
|
height: 10,
|
||||||
|
width: 7,
|
||||||
|
|
||||||
|
},
|
||||||
|
"scrollbar-color": currentTheme?.semanticColors.bodyFrameBackground,
|
||||||
|
"scrollbar-width": "thin", },
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const stackContainerStyles: IStackStyles= React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root:{padding: 20, backgroundColor: currentTheme?.palette?.neutralLighterAlt}
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const noDataContainerStyles: IStackStyles= React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root:{paddingTop: 50, }
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const controlStyles = mergeStyleSets({
|
||||||
|
fileIconHeaderIcon: ({
|
||||||
|
padding: 0,
|
||||||
|
fontSize: "16px",
|
||||||
|
}),
|
||||||
|
fileIconCell: mergeStyles({
|
||||||
|
textAlign: "center",
|
||||||
|
selectors: {
|
||||||
|
"&:before": {
|
||||||
|
content: ".",
|
||||||
|
display: "inline-block",
|
||||||
|
verticalAlign: "middle",
|
||||||
|
height: "100%",
|
||||||
|
width: "0px",
|
||||||
|
visibility: "hidden",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
fileIconImg: mergeStyles({
|
||||||
|
verticalAlign: "middle",
|
||||||
|
maxHeight: "16px",
|
||||||
|
maxWidth: "16px",
|
||||||
|
}),
|
||||||
|
controlWrapper: mergeStyles({
|
||||||
|
display: "flex",
|
||||||
|
flexWrap: "wrap",
|
||||||
|
}),
|
||||||
|
|
||||||
|
selectionDetails: mergeStyles({
|
||||||
|
marginBottom: "20px",
|
||||||
|
}),
|
||||||
|
attributeContainerGrid: mergeStyles({
|
||||||
|
width: "100%",
|
||||||
|
display: "grid",
|
||||||
|
gridTemplateColumns: "repeat(auto-fit, minmax(min(100%, 160px), 1fr))",
|
||||||
|
columnGap: '10px',
|
||||||
|
rowGap: 10,
|
||||||
|
} ),
|
||||||
|
|
||||||
|
noDataFoundStyles: {
|
||||||
|
width: "300px", height: "300px",
|
||||||
|
},
|
||||||
|
separator: mergeStyles({
|
||||||
|
height: "1px",
|
||||||
|
backgroundColor: currentTheme?.palette?.neutralLight,
|
||||||
|
opacity: currentTheme.isInverted ? "0.2" : "1",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
return {attributeContainer,noDataContainerStyles, stackContainerStyles, scollableContainerStyles, itemContainer, controlStyles, listHeaderStyles };
|
||||||
|
};
|
|
@ -0,0 +1,38 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
|
||||||
|
import { IAirport } from '../../models/IAirport';
|
||||||
|
import { useSelectAirportStyles } from './useSelectAirportStyles';
|
||||||
|
|
||||||
|
export interface IAirportProps {
|
||||||
|
airport: IAirport;
|
||||||
|
onSelected?: (airport: IAirport) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Airport: React.FunctionComponent<IAirportProps> = (props: React.PropsWithChildren<IAirportProps>) => {
|
||||||
|
const { airport, onSelected } = props;
|
||||||
|
const city = React.useMemo(() => airport?.municipality ? `${airport?.municipality},` : "", [airport]);
|
||||||
|
const { IATACodeStyle, airportContainerStyles, airportItemStyles, controlStyles, airportNameStyles } = useSelectAirportStyles();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack
|
||||||
|
styles={airportItemStyles}
|
||||||
|
onClick={(ev) => {
|
||||||
|
if (onSelected) {onSelected(airport); }
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Stack styles={airportContainerStyles}>
|
||||||
|
<Stack horizontal verticalAlign="center" horizontalAlign="start" tokens={{ childrenGap: 10 }}>
|
||||||
|
<Text styles={IATACodeStyle}>{airport.iata_code}</Text>
|
||||||
|
<Text variant="medium" styles={airportNameStyles}>{city} {airport.name}</Text>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
<div className={controlStyles.separator} />
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,166 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IBasePickerSuggestionsProps,
|
||||||
|
ICalloutContentStyleProps,
|
||||||
|
IInputProps,
|
||||||
|
IPickerItemProps,
|
||||||
|
ISuggestionItemProps,
|
||||||
|
ITag,
|
||||||
|
Label,
|
||||||
|
TagPicker,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { useAirports } from '../../hooks/useAirports';
|
||||||
|
import { IAirport } from '../../models/IAirport';
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
import { Airport } from './Airport';
|
||||||
|
import { SelectedAirport } from './SelectedAirport';
|
||||||
|
import { useSelectAirportStyles } from './useSelectAirportStyles';
|
||||||
|
|
||||||
|
export interface ITagExtended extends ITag {
|
||||||
|
airportData: IAirport;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SelectAirportPicker: React.FunctionComponent = () => {
|
||||||
|
const divRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
const [appState, setAppState] = useRecoilState(globalState);
|
||||||
|
const { searchAirportsByText } = useAirports();
|
||||||
|
const [selectedAirport, setSelectedAirports] = React.useState<ITag[]>([]);
|
||||||
|
const { controlStyles, selecteAirportPickerStyles } = useSelectAirportStyles();
|
||||||
|
|
||||||
|
const inputProps: IInputProps = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
placeholder: "Select an airport",
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const pickerSuggestionsProps: IBasePickerSuggestionsProps = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
suggestionsHeaderText: "Suggested AirPorts",
|
||||||
|
noResultsFoundText: "No AirPort found",
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const listContainsTagList = React.useCallback((tag: ITag, tagList?: ITag[]) => {
|
||||||
|
if (!tagList || !tagList.length || tagList.length === 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return tagList.some((compareTag) => compareTag.key === tag.key);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const loadMenuItems = React.useCallback(
|
||||||
|
async (text: string) => {
|
||||||
|
const airports = await searchAirportsByText(text);
|
||||||
|
const newPickerItems: ITag[] = [];
|
||||||
|
|
||||||
|
for (const airport of airports) {
|
||||||
|
const city = airport?.municipality ? `${airport?.municipality},` : "";
|
||||||
|
const item: ITagExtended = {
|
||||||
|
key: airport?.iata_code,
|
||||||
|
name: `${city} ${airport?.name}`,
|
||||||
|
airportData: airport,
|
||||||
|
};
|
||||||
|
newPickerItems.push(item);
|
||||||
|
}
|
||||||
|
return newPickerItems;
|
||||||
|
},
|
||||||
|
[searchAirportsByText]
|
||||||
|
);
|
||||||
|
|
||||||
|
const getTextFromItem = React.useCallback((item: ITag) => {
|
||||||
|
return item.name;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onItemSelected = React.useCallback((item: ITag): ITag | null => {
|
||||||
|
setSelectedAirports([item]);
|
||||||
|
return item;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const filterSuggestedTags = React.useCallback(
|
||||||
|
async (filterText: string, tagList: ITag[]): Promise<ITag[]> => {
|
||||||
|
if (filterText.length < 2) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const pickerItems = await loadMenuItems(filterText);
|
||||||
|
return filterText ? pickerItems.filter((tag) => !listContainsTagList(tag, tagList)) : [];
|
||||||
|
},
|
||||||
|
[loadMenuItems]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onRenderSuggestionsItem = React.useCallback(
|
||||||
|
(props:ITagExtended, itemProps: ISuggestionItemProps<ITagExtended>) => {
|
||||||
|
const { airportData } = props;
|
||||||
|
return (
|
||||||
|
<div className={controlStyles.pickerItemStyles}>
|
||||||
|
<Airport
|
||||||
|
airport={airportData}
|
||||||
|
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[appState]
|
||||||
|
);
|
||||||
|
const onRenderItem = React.useCallback(
|
||||||
|
(props: IPickerItemProps<ITag>) => {
|
||||||
|
const airport = {} as IAirport;
|
||||||
|
airport.iata_code = props.item.key as string;
|
||||||
|
airport.name = props.item.name;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={{ width: "100%" }}>
|
||||||
|
<SelectedAirport
|
||||||
|
airport={airport}
|
||||||
|
onRemove={(airport) => {
|
||||||
|
setSelectedAirports([]);
|
||||||
|
setAppState({ ...appState, selectedAirPort: undefined });
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[appState]
|
||||||
|
);
|
||||||
|
|
||||||
|
const pickerCalloutPropsStyles = (props: ICalloutContentStyleProps) => {
|
||||||
|
return { root: { width: divRef?.current?.offsetWidth } };
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPickerChange = React.useCallback((items: ITag[]) => {
|
||||||
|
setAppState({ ...appState, selectedAirPort: (items[0] as ITagExtended)?.airportData });
|
||||||
|
}, [appState]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<div ref={divRef} className={controlStyles.searchContainerStyles}>
|
||||||
|
<Label>Airport</Label>
|
||||||
|
<TagPicker
|
||||||
|
|
||||||
|
selectedItems={selectedAirport}
|
||||||
|
styles={selecteAirportPickerStyles}
|
||||||
|
resolveDelay={500}
|
||||||
|
pickerCalloutProps={{ styles: pickerCalloutPropsStyles }}
|
||||||
|
onRenderItem={onRenderItem}
|
||||||
|
onRenderSuggestionsItem={onRenderSuggestionsItem}
|
||||||
|
onResolveSuggestions={filterSuggestedTags}
|
||||||
|
getTextFromItem={getTextFromItem}
|
||||||
|
pickerSuggestionsProps={pickerSuggestionsProps}
|
||||||
|
onItemSelected={onItemSelected}
|
||||||
|
onChange={onPickerChange}
|
||||||
|
itemLimit={1}
|
||||||
|
inputProps={{
|
||||||
|
...inputProps,
|
||||||
|
id: "picker1",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,51 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import * as strings from 'FlightTrackerWebPartStrings';
|
||||||
|
import {
|
||||||
|
IconButton,
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
|
||||||
|
import { IAirport } from '../../models/IAirport';
|
||||||
|
import { useSelectAirportStyles } from './useSelectAirportStyles';
|
||||||
|
|
||||||
|
export interface IAirportProps {
|
||||||
|
airport: IAirport;
|
||||||
|
onRemove?: (airport: IAirport) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SelectedAirport: React.FunctionComponent<IAirportProps> = (
|
||||||
|
props: React.PropsWithChildren<IAirportProps>
|
||||||
|
) => {
|
||||||
|
const { airport, onRemove } = props;
|
||||||
|
|
||||||
|
const {
|
||||||
|
selectedAirPortIATACodeStyle,
|
||||||
|
selectedAirportContainerStyles,
|
||||||
|
selectedAirportItemStyles,
|
||||||
|
|
||||||
|
airportNameStyles,
|
||||||
|
} = useSelectAirportStyles();
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack styles={selectedAirportItemStyles}>
|
||||||
|
<Stack styles={selectedAirportContainerStyles}>
|
||||||
|
<Stack horizontal verticalAlign="center" horizontalAlign="start" tokens={{ childrenGap: 10 }}>
|
||||||
|
<Text styles={selectedAirPortIATACodeStyle}>{airport.iata_code}</Text>
|
||||||
|
<Text variant="medium" block nowrap styles={airportNameStyles} title={airport.name}>
|
||||||
|
{airport.name}
|
||||||
|
</Text>
|
||||||
|
<IconButton
|
||||||
|
iconProps={{ iconName: "Cancel" }}
|
||||||
|
title={strings.Remove}
|
||||||
|
onClick={(ev) => {
|
||||||
|
onRemove(airport);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from './Airport';
|
||||||
|
export * from './SelectAirportPicker';
|
||||||
|
export * from './useSelectAirportStyles';
|
|
@ -0,0 +1,230 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
import * as react from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IBasePickerStyles,
|
||||||
|
IContextualMenuStyles,
|
||||||
|
IStackStyles,
|
||||||
|
ITextFieldStyles,
|
||||||
|
ITextStyles,
|
||||||
|
mergeStyles,
|
||||||
|
mergeStyleSets,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
|
||||||
|
export const useSelectAirportStyles = () => {
|
||||||
|
const [appState] = useRecoilState(globalState);
|
||||||
|
|
||||||
|
const { currentTheme, selectedAirPort } = appState;
|
||||||
|
|
||||||
|
const contextMenuStyles: Partial<IContextualMenuStyles> = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
width: "100%",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const textFieldSelectAirPortStyles: Partial<ITextFieldStyles> = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
prefix: {
|
||||||
|
width: selectedAirPort?.iata_code ? 55 : 0,
|
||||||
|
paddingLeft: selectedAirPort?.iata_code ? 10 : 0,
|
||||||
|
paddingRight: selectedAirPort?.iata_code ? 10 : 0,
|
||||||
|
backgroundColor: selectedAirPort?.iata_code
|
||||||
|
? currentTheme?.palette?.themePrimary
|
||||||
|
: currentTheme?.semanticColors.inputBackground,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme, selectedAirPort]);
|
||||||
|
|
||||||
|
const IATACodePrefixStyle: ITextStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
padding: 7,
|
||||||
|
transform: "uppercase",
|
||||||
|
fontWeight: "bold",
|
||||||
|
color: currentTheme?.palette?.white,
|
||||||
|
minWidth: 55,
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const IATACodeStyle: ITextStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
backgroundColor: currentTheme?.palette?.themePrimary,
|
||||||
|
padding: 7,
|
||||||
|
transform: "uppercase",
|
||||||
|
fontWeight: "bold",
|
||||||
|
color: currentTheme?.palette?.white,
|
||||||
|
minWidth: 55,
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const selectedAirPortIATACodeStyle: ITextStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
backgroundColor: currentTheme?.palette?.themePrimary,
|
||||||
|
padding: 2,
|
||||||
|
transform: "uppercase",
|
||||||
|
fontWeight: "bold",
|
||||||
|
color: currentTheme?.palette?.white,
|
||||||
|
minWidth: 55,
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const airportContainerStyles: IStackStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
paddingTop: 5,
|
||||||
|
paddingLeft: 10,
|
||||||
|
paddingRight: 10,
|
||||||
|
paddingBottom: 10,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const selectedAirportContainerStyles: IStackStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
paddingLeft: 10,
|
||||||
|
paddingRight: 10,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const airportNameStyles: IStackStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
textAlign: "left",
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const airportItemStyles: IStackStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
cursor: "pointer",
|
||||||
|
":hover": {
|
||||||
|
backgroundColor: currentTheme?.palette?.neutralLighterAlt,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const selectedAirportItemStyles: IStackStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const selecteAirportPickerStyles: Partial<IBasePickerStyles> = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
width: " 100%",
|
||||||
|
borderRadius: 0,
|
||||||
|
marginTop: 0,
|
||||||
|
},
|
||||||
|
|
||||||
|
input: {
|
||||||
|
width: "100%",
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
"::placeholder": {
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
text: {
|
||||||
|
|
||||||
|
borderStyle: "solid",
|
||||||
|
width: "100%",
|
||||||
|
borderWidth: 1,
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
borderRadius: 0,
|
||||||
|
// borderColor: "rgb(225 223 221)" ,
|
||||||
|
borderColor: `${currentTheme?.palette?.neutralQuaternaryAlt} !important`,
|
||||||
|
":focus": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important`,
|
||||||
|
},
|
||||||
|
":hover": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important`,
|
||||||
|
},
|
||||||
|
":after": {
|
||||||
|
borderWidth: 0,
|
||||||
|
borderRadius: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme?.palette, currentTheme?.semanticColors]);
|
||||||
|
|
||||||
|
const controlStyles = react.useMemo(() => {
|
||||||
|
return mergeStyleSets({
|
||||||
|
container: {
|
||||||
|
display: "flex",
|
||||||
|
flexFlow: "column nowrap",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
width: "100%",
|
||||||
|
height: "100%",
|
||||||
|
backgroundColor: "white",
|
||||||
|
padding: "10px",
|
||||||
|
boxSizing: "border-box",
|
||||||
|
},
|
||||||
|
separator: mergeStyles({
|
||||||
|
marginTop: 2,
|
||||||
|
marginBottom: 2,
|
||||||
|
borderBottomWidth: 1,
|
||||||
|
borderBottomColor: currentTheme?.palette?.neutralLighter,
|
||||||
|
borderBottomStyle: "solid",
|
||||||
|
}),
|
||||||
|
airportItemStyles: mergeStyles({
|
||||||
|
cursor: "pointer",
|
||||||
|
":hover": {
|
||||||
|
backgroundColor: currentTheme?.palette?.neutralLighterAlt,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
searchContainerStyles: mergeStyles({
|
||||||
|
|
||||||
|
width: "100%",
|
||||||
|
}),
|
||||||
|
pickerItemStyles: mergeStyles({
|
||||||
|
width: "100%",
|
||||||
|
}),
|
||||||
|
placeHolderStyles: mergeStyles({
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
selectedAirportContainerStyles,
|
||||||
|
selectedAirportItemStyles,
|
||||||
|
textFieldSelectAirPortStyles,
|
||||||
|
IATACodePrefixStyle,
|
||||||
|
controlStyles,
|
||||||
|
IATACodeStyle,
|
||||||
|
airportContainerStyles,
|
||||||
|
airportItemStyles,
|
||||||
|
airportNameStyles,
|
||||||
|
contextMenuStyles,
|
||||||
|
selectedAirPortIATACodeStyle,
|
||||||
|
selecteAirportPickerStyles,
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,61 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import * as strings from 'FlightTrackerWebPartStrings';
|
||||||
|
import {
|
||||||
|
DatePicker,
|
||||||
|
IDatePicker,
|
||||||
|
Label,
|
||||||
|
Stack,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { DayPickerStrings } from '../../constants';
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
import { SelectTime } from '../SelectTime/SelectTime';
|
||||||
|
import { useSelctedDateStyles } from './useSelectDateStyles';
|
||||||
|
|
||||||
|
export interface ISelectDateProps {}
|
||||||
|
|
||||||
|
export const SelectDate: React.FunctionComponent<ISelectDateProps> = (
|
||||||
|
props: React.PropsWithChildren<ISelectDateProps>
|
||||||
|
) => {
|
||||||
|
const { selectedDateStyle, textFieldStyles, labelDateStyles, labelTimeStyles } = useSelctedDateStyles();
|
||||||
|
const [appState, setAppState] = useRecoilState(globalState);
|
||||||
|
const { selectedDate, selectedTime } = appState;
|
||||||
|
|
||||||
|
const onSelectDate = React.useCallback(
|
||||||
|
(date: Date | null | undefined) => {
|
||||||
|
setAppState({
|
||||||
|
...appState,
|
||||||
|
selectedDate: date,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[appState, setAppState, selectedTime]
|
||||||
|
);
|
||||||
|
|
||||||
|
const datePickerRef = React.useRef<IDatePicker>(null);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack>
|
||||||
|
<Stack horizontal horizontalAlign="space-between">
|
||||||
|
<Label styles={labelDateStyles}>{strings.DateLabel}</Label>
|
||||||
|
<Label styles={labelTimeStyles}>{strings.TimeLabel}</Label>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<Stack horizontal tokens={{ childrenGap: 10 }}>
|
||||||
|
<DatePicker
|
||||||
|
componentRef={datePickerRef}
|
||||||
|
allowTextInput
|
||||||
|
ariaLabel={strings.SelectDate}
|
||||||
|
value={selectedDate}
|
||||||
|
onSelectDate={onSelectDate}
|
||||||
|
strings={DayPickerStrings}
|
||||||
|
styles={selectedDateStyle}
|
||||||
|
textField={{ styles: textFieldStyles }}
|
||||||
|
/>
|
||||||
|
<SelectTime />
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './SelectDate';
|
||||||
|
export * from './useSelectDateStyles';
|
|
@ -0,0 +1,88 @@
|
||||||
|
import * as react from 'react';
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
import {
|
||||||
|
IDatePickerStyles,
|
||||||
|
ILabelStyles,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
|
||||||
|
export const useSelctedDateStyles= () => {
|
||||||
|
const [appState] = useRecoilState(globalState);
|
||||||
|
|
||||||
|
const { currentTheme } = appState;
|
||||||
|
|
||||||
|
const labelDateStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root:{
|
||||||
|
width: '75%',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const labelTimeStyles:ILabelStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root:{
|
||||||
|
width: '25%',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const textFieldStyles = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
field: {
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const selectedDateStyle: Partial<IDatePickerStyles> = react.useMemo(() => {
|
||||||
|
return {
|
||||||
|
root:{
|
||||||
|
width: "100%",
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
".ms-TextField-fieldGroup":{
|
||||||
|
borderWidth: `0px !important`,
|
||||||
|
backgroundColor: currentTheme?.semanticColors.bodyBackground ,
|
||||||
|
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fieldGroup:{
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
|
||||||
|
} ,
|
||||||
|
|
||||||
|
textField: {
|
||||||
|
borderStyle: "solid",
|
||||||
|
width: "100%",
|
||||||
|
borderWidth: 1,
|
||||||
|
backgroundColor: currentTheme?.palette?.white ,
|
||||||
|
borderRadius: 0,
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
borderColor: `${currentTheme?.palette?.neutralQuaternaryAlt} !important` ,
|
||||||
|
":focus": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important` ,
|
||||||
|
},
|
||||||
|
":hover": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important` ,
|
||||||
|
},
|
||||||
|
":after": {
|
||||||
|
borderWidth: 0,
|
||||||
|
borderRadius: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
|
||||||
|
return {textFieldStyles, selectedDateStyle, labelDateStyles, labelTimeStyles};
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import * as strings from 'FlightTrackerWebPartStrings';
|
||||||
|
import {
|
||||||
|
Dropdown,
|
||||||
|
DropdownMenuItemType,
|
||||||
|
IDropdownOption,
|
||||||
|
IDropdownProps,
|
||||||
|
} from 'office-ui-fabric-react/lib/Dropdown';
|
||||||
|
import { FontIcon } from 'office-ui-fabric-react/lib/Icon';
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { EInformationType } from '../../constants/EInformationType';
|
||||||
|
import { EInformationTypesIcons } from '../../constants/EInformationTypesIcons';
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
import { useSelectInformationStyles } from './useSelectInformationStyles';
|
||||||
|
|
||||||
|
export interface ISelectInformationTypeProps {}
|
||||||
|
|
||||||
|
export const SelectInformationType: React.FunctionComponent<ISelectInformationTypeProps> = (
|
||||||
|
props: React.PropsWithChildren<ISelectInformationTypeProps>
|
||||||
|
) => {
|
||||||
|
const [appState, setAppState] = useRecoilState(globalState);
|
||||||
|
const { dropdownStyles, controlStyles } = useSelectInformationStyles();
|
||||||
|
const options: IDropdownOption[] = React.useMemo(() => {
|
||||||
|
return [
|
||||||
|
{ key: "Header", text: "Options", itemType: DropdownMenuItemType.Header },
|
||||||
|
{ key: "Departures", text: "Departures", data: { icon: EInformationTypesIcons.DEPARTURES } },
|
||||||
|
{ key: "divider_2", text: "-", itemType: DropdownMenuItemType.Divider },
|
||||||
|
{ key: "Arrivals", text: "Arrivals", data: { icon: EInformationTypesIcons.ARRIVALS } },
|
||||||
|
];
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getImages = React.useCallback((image: string): string => {
|
||||||
|
switch (image) {
|
||||||
|
case EInformationTypesIcons.DEPARTURES:
|
||||||
|
return "departuresSVG";
|
||||||
|
case EInformationTypesIcons.ARRIVALS:
|
||||||
|
return "arrivalsSVG";
|
||||||
|
default:
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onRenderOption = React.useCallback(
|
||||||
|
(option: IDropdownOption): JSX.Element => {
|
||||||
|
return (
|
||||||
|
<Stack horizontal horizontalAlign="start" verticalAlign="center" tokens={{ childrenGap: 10 }}>
|
||||||
|
{option.data && option.data.icon && (
|
||||||
|
<FontIcon iconName={getImages(option.data.icon)} className={controlStyles.iconStyles} />
|
||||||
|
)}
|
||||||
|
<span>{option.text}</span>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[getImages, controlStyles.iconStyles]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onRenderTitle = React.useCallback(
|
||||||
|
(options: IDropdownOption[]): JSX.Element => {
|
||||||
|
const option = options[0];
|
||||||
|
return (
|
||||||
|
<Stack horizontal horizontalAlign="start" verticalAlign="center" tokens={{ childrenGap: 10 }}>
|
||||||
|
{option.data && option.data.icon && ( <FontIcon iconName={getImages(option.data.icon)} className={controlStyles.iconStyles} />)}
|
||||||
|
<span>{option.text}</span>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[getImages, controlStyles.iconStyles]
|
||||||
|
);
|
||||||
|
|
||||||
|
const onRenderPlaceholder = React.useCallback((props: IDropdownProps): JSX.Element => {
|
||||||
|
return (
|
||||||
|
<Stack horizontal horizontalAlign="start" verticalAlign="center" tokens={{ childrenGap: 10 }}>
|
||||||
|
<span>{props.placeholder}</span>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dropdown
|
||||||
|
placeholder={strings.SelectInformationType}
|
||||||
|
label={strings.InformationTypeLabel}
|
||||||
|
onRenderPlaceholder={onRenderPlaceholder}
|
||||||
|
onRenderTitle={onRenderTitle}
|
||||||
|
onRenderOption={onRenderOption}
|
||||||
|
styles={dropdownStyles}
|
||||||
|
options={options}
|
||||||
|
onChange={(event, option) =>
|
||||||
|
setAppState({ ...appState, selectedInformationType: option.key as EInformationType })
|
||||||
|
}
|
||||||
|
selectedKey={appState.selectedInformationType}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './SelectInformationType';
|
||||||
|
export * from './useSelectInformationStyles';
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IIconStyles,
|
||||||
|
mergeStyles,
|
||||||
|
mergeStyleSets,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { IDropdownStyles } from 'office-ui-fabric-react/lib/Dropdown';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||||
|
export const useSelectInformationStyles = () => {
|
||||||
|
const [appState] = useRecoilState(globalState);
|
||||||
|
const { currentTheme } = appState;
|
||||||
|
const iconStyles: IIconStyles = React.useMemo(() => {
|
||||||
|
return { root: { width: "20px", height: "20px", fill: currentTheme?.semanticColors?.bodyText } };
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const dropdownStyles: Partial<IDropdownStyles> = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
caretDownWrapper: {
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
":hover": { color: currentTheme?.semanticColors?.bodyText },
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
borderWidth: 0,
|
||||||
|
borderStyle: undefined,
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
},
|
||||||
|
dropdown: {
|
||||||
|
minWidth: 200,
|
||||||
|
width: "100%",
|
||||||
|
borderStyle: "solid",
|
||||||
|
|
||||||
|
borderWidth: 1,
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
borderRadius: 0,
|
||||||
|
borderColor: `${currentTheme?.palette?.neutralQuaternaryAlt} !important`,
|
||||||
|
":focus": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important`,
|
||||||
|
},
|
||||||
|
":hover": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important`,
|
||||||
|
'.ms-Dropdown-caretDown': {
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
":after": {
|
||||||
|
borderWidth: 0,
|
||||||
|
borderRadius: 0,
|
||||||
|
},
|
||||||
|
":focus:after": {
|
||||||
|
borderWidth: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const controlStyles = React.useMemo(() => {
|
||||||
|
return mergeStyleSets({
|
||||||
|
iconStyles: mergeStyles({
|
||||||
|
width: "20px",
|
||||||
|
height: "20px",
|
||||||
|
fill: `${currentTheme?.semanticColors?.bodyText} !important`,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
return { controlStyles, iconStyles, dropdownStyles };
|
||||||
|
};
|
|
@ -0,0 +1,105 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import set from 'date-fns/set';
|
||||||
|
import * as strings from 'FlightTrackerWebPartStrings';
|
||||||
|
import {
|
||||||
|
Dropdown,
|
||||||
|
IDropdownOption,
|
||||||
|
} from 'office-ui-fabric-react/lib/Dropdown';
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
import { Text } from 'office-ui-fabric-react/lib/Text';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
import { useSelectTimeStyles } from './useSelectTimeStyles';
|
||||||
|
|
||||||
|
interface IDropdownOptionExtended extends IDropdownOption {
|
||||||
|
date: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISelectInformationTypeProps {}
|
||||||
|
|
||||||
|
export const SelectTime: React.FunctionComponent<ISelectInformationTypeProps> = (
|
||||||
|
props: React.PropsWithChildren<ISelectInformationTypeProps>
|
||||||
|
) => {
|
||||||
|
const [appState, setAppState] = useRecoilState(globalState);
|
||||||
|
const { dropdownStyles } = useSelectTimeStyles();
|
||||||
|
const now = new Date();
|
||||||
|
const [selectedOption, setSelectedOption] = React.useState<IDropdownOptionExtended | undefined>(undefined);
|
||||||
|
|
||||||
|
const checkTime = React.useCallback((time: Date): Date => {
|
||||||
|
const minutesOfTime = format(time, "mm");
|
||||||
|
if (+minutesOfTime > 0 && +minutesOfTime < 16) {
|
||||||
|
return set(time, { minutes: 0 });
|
||||||
|
} else if (+minutesOfTime > 15 && +minutesOfTime < 31) {
|
||||||
|
return set(time, { minutes: 15 });
|
||||||
|
} else if (+minutesOfTime > 30 && +minutesOfTime < 46) {
|
||||||
|
return set(time, { minutes: 30 });
|
||||||
|
} else {
|
||||||
|
return set(time, { minutes: 45 });
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const options: IDropdownOptionExtended[] = React.useMemo(() => {
|
||||||
|
const options: IDropdownOptionExtended[] = [];
|
||||||
|
for (let i = 0; i < 24; i++) {
|
||||||
|
const dateHour = set(new Date(now), { hours: i, minutes: 0, seconds: 0, milliseconds: 0 });
|
||||||
|
const dateQuarter = set(new Date(now), { hours: i, minutes: 15, seconds: 0, milliseconds: 0 });
|
||||||
|
const dateHalf = set(new Date(now), { hours: i, minutes: 30, seconds: 0, milliseconds: 0 });
|
||||||
|
const date45= set(new Date(now), { hours: i, minutes: 45, seconds: 0, milliseconds: 0 });
|
||||||
|
options.push({
|
||||||
|
key: format(dateHour, "H:mm"),
|
||||||
|
text: format(dateHour, "H:mm"),
|
||||||
|
date: dateHour,
|
||||||
|
});
|
||||||
|
options.push({
|
||||||
|
key: format(dateQuarter, "H:mm"),
|
||||||
|
text: format(dateQuarter, "H:mm"),
|
||||||
|
date: dateQuarter,
|
||||||
|
});
|
||||||
|
options.push({
|
||||||
|
key: format(dateHalf, "H:mm"),
|
||||||
|
text: format(dateHalf, "H:mm"),
|
||||||
|
date: dateHalf,
|
||||||
|
});
|
||||||
|
options.push({
|
||||||
|
key: format(date45, "H:mm"),
|
||||||
|
text: format(date45, "H:mm"),
|
||||||
|
date: date45,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onRenderTitle = React.useCallback((options: IDropdownOptionExtended[]): JSX.Element => {
|
||||||
|
const option = options[0];
|
||||||
|
return (
|
||||||
|
<Stack horizontal horizontalAlign="start" verticalAlign="center" tokens={{ childrenGap: 10 }}>
|
||||||
|
<Text>{format(option.date, "H:mm")}</Text>
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Dropdown
|
||||||
|
placeholder={strings.SelectInformationType}
|
||||||
|
styles={dropdownStyles}
|
||||||
|
options={options}
|
||||||
|
onRenderTitle={onRenderTitle}
|
||||||
|
onChange={(event, option) => {
|
||||||
|
const optionExtended = option as IDropdownOptionExtended;
|
||||||
|
setSelectedOption(optionExtended);
|
||||||
|
setAppState((prevState) => ({
|
||||||
|
...prevState,
|
||||||
|
selectedTime: optionExtended?.date,
|
||||||
|
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
selectedKey={selectedOption ? selectedOption.key : format(checkTime(now), "H:mm")}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,76 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
mergeStyles,
|
||||||
|
mergeStyleSets,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { IDropdownStyles } from 'office-ui-fabric-react/lib/Dropdown';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||||
|
export const useSelectTimeStyles = () => {
|
||||||
|
const [appState] = useRecoilState(globalState);
|
||||||
|
const { currentTheme } = appState;
|
||||||
|
|
||||||
|
|
||||||
|
const dropdownStyles: Partial<IDropdownStyles> = React.useMemo(() => {
|
||||||
|
return {
|
||||||
|
caretDownWrapper: {
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
":hover": { color: currentTheme?.semanticColors?.bodyText },
|
||||||
|
},
|
||||||
|
title: {
|
||||||
|
borderWidth: 0,
|
||||||
|
borderStyle: undefined,
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
},
|
||||||
|
dropdown: {
|
||||||
|
minWidth: 95,
|
||||||
|
width: '100%',
|
||||||
|
borderStyle: "solid",
|
||||||
|
|
||||||
|
borderWidth: 1,
|
||||||
|
backgroundColor: currentTheme?.palette?.white,
|
||||||
|
borderRadius: 0,
|
||||||
|
borderColor: `${currentTheme?.palette?.neutralQuaternaryAlt} !important`,
|
||||||
|
":focus": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important`,
|
||||||
|
},
|
||||||
|
":hover": {
|
||||||
|
borderStyle: "solid",
|
||||||
|
borderWidth: 1,
|
||||||
|
borderColor: `${currentTheme?.palette?.themePrimary} !important`,
|
||||||
|
'.ms-Dropdown-caretDown': {
|
||||||
|
color: currentTheme?.semanticColors?.bodyText,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
":after": {
|
||||||
|
borderWidth: 0,
|
||||||
|
borderRadius: 0,
|
||||||
|
},
|
||||||
|
":focus:after": {
|
||||||
|
borderWidth: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
const controlStyles = React.useMemo(() => {
|
||||||
|
return mergeStyleSets({
|
||||||
|
iconStyles: mergeStyles({
|
||||||
|
width: "20px",
|
||||||
|
height: "20px",
|
||||||
|
fill: `${currentTheme?.semanticColors?.bodyText} !important`,
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}, [currentTheme]);
|
||||||
|
|
||||||
|
return { controlStyles, dropdownStyles };
|
||||||
|
};
|
|
@ -0,0 +1,116 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
IconButton,
|
||||||
|
ScrollablePane,
|
||||||
|
ScrollbarVisibility,
|
||||||
|
Text,
|
||||||
|
} from 'office-ui-fabric-react';
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { IFlightTrackerListItem } from '../../models';
|
||||||
|
import { globalState } from '../../recoil/atoms';
|
||||||
|
import {
|
||||||
|
FlightTrackerListItem,
|
||||||
|
} from '../FlightTrackerList/FlightTrackerListItem';
|
||||||
|
import { FlightTrackerNoData } from '../FlightTrackerList/FlightTrackerNoData';
|
||||||
|
import {
|
||||||
|
useFlightTrackerStyles,
|
||||||
|
} from '../FlightTrackerList/useFlightTrackerStyles';
|
||||||
|
|
||||||
|
export interface IShowListProps {
|
||||||
|
listItems: IFlightTrackerListItem[];
|
||||||
|
showList: boolean;
|
||||||
|
onScroll: () => Promise<void>;
|
||||||
|
onRefresh: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ShowList: React.FunctionComponent<IShowListProps> = (props: React.PropsWithChildren<IShowListProps>) => {
|
||||||
|
const { listItems, showList, onScroll, onRefresh } = props;
|
||||||
|
const {
|
||||||
|
noDataContainerStyles,
|
||||||
|
listHeaderStyles,
|
||||||
|
scollableContainerStyles,
|
||||||
|
stackContainerStyles,
|
||||||
|
} = useFlightTrackerStyles();
|
||||||
|
|
||||||
|
const [appState] = useRecoilState(globalState);
|
||||||
|
const { selectedAirPort, selectedInformationType, } = appState;
|
||||||
|
const scrollablePaneRef: any = React.createRef<HTMLDivElement>();
|
||||||
|
const [isScrolling, setIsScrolling] = React.useState<boolean>(false);
|
||||||
|
|
||||||
|
const listHeader = React.useMemo(() => {
|
||||||
|
if (selectedAirPort?.municipality) {
|
||||||
|
return `${selectedAirPort?.municipality}, ${selectedAirPort?.name} - ${selectedInformationType}`;
|
||||||
|
} else {
|
||||||
|
return `${selectedAirPort?.name} - ${selectedInformationType}`;
|
||||||
|
}
|
||||||
|
}, [selectedAirPort, selectedInformationType]);
|
||||||
|
|
||||||
|
const getScrollPosition = React.useCallback((divContainerRef: any) => {
|
||||||
|
const { scrollTop, scrollHeight, clientHeight } = divContainerRef;
|
||||||
|
const percentNow = (scrollTop / (scrollHeight - clientHeight)) * 100;
|
||||||
|
return percentNow;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const onScrollList = React.useCallback(async () => {
|
||||||
|
if (isScrolling) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setIsScrolling(true);
|
||||||
|
const scrollPosition = getScrollPosition(scrollablePaneRef.current.contentContainer);
|
||||||
|
if (scrollPosition > 90) {
|
||||||
|
await onScroll();
|
||||||
|
}
|
||||||
|
setIsScrolling(false);
|
||||||
|
}, [onScroll, isScrolling, getScrollPosition, scrollablePaneRef]);
|
||||||
|
|
||||||
|
if (!showList) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Stack tokens={{ childrenGap: 25 }} styles={stackContainerStyles}>
|
||||||
|
<Stack verticalAlign="center" horizontal horizontalAlign="space-between">
|
||||||
|
<Text styles={listHeaderStyles} variant="large">
|
||||||
|
{listHeader}
|
||||||
|
</Text>
|
||||||
|
<Stack style={{ paddingRight: 20 }}>
|
||||||
|
<IconButton
|
||||||
|
iconProps={{ iconName: "Refresh" }}
|
||||||
|
title="Refresh"
|
||||||
|
ariaLabel="Refresh"
|
||||||
|
onClick={async (ev) => {
|
||||||
|
ev.preventDefault();
|
||||||
|
await onRefresh();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
|
||||||
|
<ScrollablePane
|
||||||
|
scrollbarVisibility={ScrollbarVisibility.auto}
|
||||||
|
styles={scollableContainerStyles}
|
||||||
|
onScroll={onScrollList}
|
||||||
|
componentRef={scrollablePaneRef}
|
||||||
|
>
|
||||||
|
{listItems && listItems.length > 0 ? (
|
||||||
|
listItems.map((item, index) => {
|
||||||
|
return (
|
||||||
|
<FlightTrackerListItem key={index} flights={item} flightInformationType={selectedInformationType} />
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<Stack horizontalAlign="center" verticalAlign="center" styles={noDataContainerStyles}>
|
||||||
|
<FlightTrackerNoData />
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
</ScrollablePane>
|
||||||
|
</Stack>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './ShowList';
|
|
@ -0,0 +1,28 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/components/Stack';
|
||||||
|
import {
|
||||||
|
MessageBar,
|
||||||
|
MessageBarType,
|
||||||
|
} from 'office-ui-fabric-react/lib/MessageBar';
|
||||||
|
|
||||||
|
export interface IShowMessageProps {
|
||||||
|
message: string;
|
||||||
|
messageBarType: MessageBarType;
|
||||||
|
isShow: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ShowMessage: React.FunctionComponent<IShowMessageProps> = (
|
||||||
|
props: React.PropsWithChildren<IShowMessageProps>
|
||||||
|
) => {
|
||||||
|
const { message, messageBarType, isShow } = props;
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isShow ? (
|
||||||
|
<Stack horizontal horizontalAlign="center">
|
||||||
|
<MessageBar messageBarType={messageBarType}>{message}</MessageBar>
|
||||||
|
</Stack>
|
||||||
|
) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './ShowMessage';
|
|
@ -0,0 +1,28 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
Spinner,
|
||||||
|
SpinnerLabelPosition,
|
||||||
|
SpinnerSize,
|
||||||
|
} from 'office-ui-fabric-react/lib/Spinner';
|
||||||
|
import { Stack } from 'office-ui-fabric-react/lib/Stack';
|
||||||
|
|
||||||
|
export interface IShowSpinnerProps {
|
||||||
|
size?: SpinnerSize;
|
||||||
|
label?: string;
|
||||||
|
labelPosition?: SpinnerLabelPosition;
|
||||||
|
isShow: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ShowSpinner: React.FunctionComponent<IShowSpinnerProps> = (props: React.PropsWithChildren<IShowSpinnerProps>) => {
|
||||||
|
const { size, label, labelPosition , isShow} = props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{isShow ? (
|
||||||
|
<Stack horizontal horizontalAlign="center" verticalAlign="center" style={{ height: '100%' }}>
|
||||||
|
<Spinner size={size ?? SpinnerSize.medium} label={label ?? ''} labelPosition={labelPosition ?? undefined} />
|
||||||
|
</Stack>) : null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './ShowSpinner';
|
|
@ -0,0 +1,4 @@
|
||||||
|
export enum EInformationType {
|
||||||
|
"DEPARTURES" = "Departures",
|
||||||
|
"ARRIVALS" = "Arrivals",
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
export enum EInformationTypesIcons {
|
||||||
|
"DEPARTURES" = "Departures",
|
||||||
|
"ARRIVALS" = "Arrivals",
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
export enum EStatus {
|
||||||
|
Unknown = "Unknown",
|
||||||
|
Expected = "Expected",
|
||||||
|
EnRoute = "EnRoute",
|
||||||
|
CheckIn = "CheckIn",
|
||||||
|
Boarding = "Boarding",
|
||||||
|
GateClosed = "GateClosed",
|
||||||
|
Departed = "Departed",
|
||||||
|
Delayed = "Delayed",
|
||||||
|
Approaching= "Approaching",
|
||||||
|
Arrived = "Arrived",
|
||||||
|
Canceled = "Canceled",
|
||||||
|
Diverted = "Diverted",
|
||||||
|
CanceledUncertain = "CanceledUncertain",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
import { IDatePickerStrings } from 'office-ui-fabric-react/lib/DatePicker';
|
||||||
|
|
||||||
|
export const DayPickerStrings: IDatePickerStrings = {
|
||||||
|
months: [
|
||||||
|
'January',
|
||||||
|
'February',
|
||||||
|
'March',
|
||||||
|
'April',
|
||||||
|
'May',
|
||||||
|
'June',
|
||||||
|
'July',
|
||||||
|
'August',
|
||||||
|
'September',
|
||||||
|
'October',
|
||||||
|
'November',
|
||||||
|
'December',
|
||||||
|
],
|
||||||
|
|
||||||
|
shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
|
||||||
|
|
||||||
|
days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
|
||||||
|
|
||||||
|
shortDays: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
|
||||||
|
|
||||||
|
goToToday: 'Go to today',
|
||||||
|
prevMonthAriaLabel: 'Go to previous month',
|
||||||
|
nextMonthAriaLabel: 'Go to next month',
|
||||||
|
prevYearAriaLabel: 'Go to previous year',
|
||||||
|
nextYearAriaLabel: 'Go to next year',
|
||||||
|
closeButtonAriaLabel: 'Close date picker',
|
||||||
|
monthPickerHeaderAriaLabel: '{0}, select to change the year',
|
||||||
|
yearPickerHeaderAriaLabel: '{0}, select to change the month',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const RAPID_API_KEY_AERODATABOX = "a96bf6dd14mshaba3c61477da062p1a89f2jsn5190b7082e8e";
|
||||||
|
export const RAPID_API_HOST_AERODATABOX = "aerodatabox.p.rapidapi.com";
|
||||||
|
export const RAPID_API_KEY_COUNTRY_FLAGS = "a96bf6dd14mshaba3c61477da062p1a89f2jsn5190b7082e8e";
|
||||||
|
export const RAPID_API_HOST_COUNTRY_FLAGS = "country-flags.p.rapidapi.com";
|
||||||
|
export const RAPID_API_KEY_FLIGHT_RADAR = "a96bf6dd14mshaba3c61477da062p1a89f2jsn5190b7082e8e";
|
||||||
|
export const RAPID_API_HOST_FLIGHT_RADAR = "flight-radar1.p.rapidapi.com";
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './EStatus';
|
||||||
|
export * from './constants';
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './registerSVGIcons';
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
/* eslint-disable no-unused-expressions */
|
||||||
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
|
import { IAirlines } from '../models/IAirlines';
|
||||||
|
import { useLocalStorage } from './useLocalStorage';
|
||||||
|
|
||||||
|
const airlinesData = require("../mockData/airlines.json");
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
export const useAirlines = () => {
|
||||||
|
const [error, setError] = useState<Error>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [airlines, setAirlines] = useState<IAirlines >({} as IAirlines);
|
||||||
|
|
||||||
|
const [airlinesLocalStorage, setAirLinesLocalStorage] = useLocalStorage("__airlines__", []);
|
||||||
|
|
||||||
|
const fetchAirlines = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
|
||||||
|
setAirLinesLocalStorage(airlinesData);
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log("[useAirLines] error", error);
|
||||||
|
}
|
||||||
|
setLoading(false);
|
||||||
|
setError(error);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
setLoading(true);
|
||||||
|
if (!airlinesLocalStorage?.rows?.length ) {
|
||||||
|
await fetchAirlines();
|
||||||
|
setAirlines(airlinesData);
|
||||||
|
setError(undefined);
|
||||||
|
} else {
|
||||||
|
setAirlines(airlinesLocalStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
return {
|
||||||
|
airlines,
|
||||||
|
errorLoadingAirlines: error,
|
||||||
|
loadingAirlines: loading,
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,37 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||||
|
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
import { includes } from 'lodash';
|
||||||
|
|
||||||
|
import { IAirport } from '../models/IAirport';
|
||||||
|
|
||||||
|
const airports = require("../mockData/airports.json").airports;
|
||||||
|
|
||||||
|
interface IUseAirports {
|
||||||
|
searchAirportsByText: (text: string) => Promise<IAirport[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useAirports = ():IUseAirports => {
|
||||||
|
|
||||||
|
|
||||||
|
const searchAirportsByText = useCallback(async (text: string): Promise<IAirport[]> => {
|
||||||
|
if (!text) return [];
|
||||||
|
const airportsFound: IAirport[] = [];
|
||||||
|
|
||||||
|
for (const airport of airports) {
|
||||||
|
if (!airport.iata_code) continue;
|
||||||
|
if (
|
||||||
|
includes(airport?.municipality?.toLowerCase(), text.toLowerCase()) ||
|
||||||
|
includes(airport?.name?.toLowerCase(), text.toLowerCase())
|
||||||
|
) {
|
||||||
|
airportsFound.push(airport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return airportsFound;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
searchAirportsByText,
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,45 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable no-unused-expressions */
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import {
|
||||||
|
RAPID_API_HOST_COUNTRY_FLAGS,
|
||||||
|
RAPID_API_KEY_COUNTRY_FLAGS,
|
||||||
|
} from '../constants';
|
||||||
|
|
||||||
|
export interface ICountryFlags {
|
||||||
|
countryFlags: any;
|
||||||
|
error:Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useContryFlags = () => {
|
||||||
|
|
||||||
|
const getCountryFlag = useCallback(async (country: string): Promise<ICountryFlags> => {
|
||||||
|
if (!country) return undefined;
|
||||||
|
const axiosOptions = {
|
||||||
|
method: "GET",
|
||||||
|
url: `https://country-flags.p.rapidapi.com/png/${country}`,
|
||||||
|
headers: {
|
||||||
|
"X-RapidAPI-Key": RAPID_API_KEY_COUNTRY_FLAGS,
|
||||||
|
"X-RapidAPI-Host": RAPID_API_HOST_COUNTRY_FLAGS,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await axios.request(axiosOptions);
|
||||||
|
|
||||||
|
return {countryFlags: response.data, error: null};
|
||||||
|
} catch (error) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log("[useContryFlags-getCountryFlag] error", error);
|
||||||
|
}
|
||||||
|
return { countryFlags: undefined, error: error };
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return {
|
||||||
|
getCountryFlag,
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useState,
|
||||||
|
} from 'react';
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import {
|
||||||
|
RAPID_API_HOST_FLIGHT_RADAR,
|
||||||
|
RAPID_API_KEY_FLIGHT_RADAR,
|
||||||
|
} from '../constants';
|
||||||
|
import { IFlightInfo } from '../models/IFlightInfo';
|
||||||
|
|
||||||
|
export const useFlightInfo = (flightNumber?: string) =>{
|
||||||
|
const [flightInfo, setFlightInfo] = useState<IFlightInfo[]>([]);
|
||||||
|
const [error, setError] = useState<Error>(null);
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
const getFlightInfo = useCallback(async (flightNumber:string) => {
|
||||||
|
setLoading(true);
|
||||||
|
const axiosOptions = {
|
||||||
|
method: 'GET',
|
||||||
|
url: 'https://flight-radar1.p.rapidapi.com/flights/search',
|
||||||
|
params: {query: `${flightNumber}`, limit: '1'},
|
||||||
|
headers: {
|
||||||
|
'X-RapidAPI-Key': RAPID_API_KEY_FLIGHT_RADAR,
|
||||||
|
'X-RapidAPI-Host': RAPID_API_HOST_FLIGHT_RADAR
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = await axios.request(axiosOptions);
|
||||||
|
const flightInfo:IFlightInfo[] = response?.data?.results as IFlightInfo[];
|
||||||
|
return flightInfo;
|
||||||
|
} catch (error) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log("[useFlightSchedule-getFlightInfo] error", error);
|
||||||
|
}
|
||||||
|
setError(error);
|
||||||
|
}finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
(async ()=> {
|
||||||
|
setFlightInfo(await getFlightInfo(flightNumber));
|
||||||
|
})();
|
||||||
|
}, [flightNumber]);
|
||||||
|
|
||||||
|
|
||||||
|
return { flightInfo, errorFlightInfo:error, loadingFlightInfo:loading };
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,62 @@
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
/* eslint-disable @typescript-eslint/no-floating-promises */
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import {
|
||||||
|
RAPID_API_HOST_AERODATABOX,
|
||||||
|
RAPID_API_KEY_AERODATABOX,
|
||||||
|
} from '../constants';
|
||||||
|
import { IFlights } from '../models';
|
||||||
|
import { IFlightSchedulesInputParm } from '../models/IFlightSchedulesParm';
|
||||||
|
|
||||||
|
const ENDPOINT = "https://aerodatabox.p.rapidapi.com/flights/airports/icao/";
|
||||||
|
|
||||||
|
export interface IUseFlightSchedules {
|
||||||
|
|
||||||
|
getFlightSchedule: (flightSchedulesParm: IFlightSchedulesInputParm) => Promise<IFlights>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useFlightSchedule = ():IUseFlightSchedules => {
|
||||||
|
|
||||||
|
const getFlightSchedule = useCallback(async (options: IFlightSchedulesInputParm):Promise<IFlights> => {
|
||||||
|
const { fromDate, toDate, airportCode } = options || ({} as IFlightSchedulesInputParm);
|
||||||
|
if (!fromDate || !toDate || !airportCode) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const axiosOptions = {
|
||||||
|
method: "GET",
|
||||||
|
url: `${ENDPOINT}${airportCode}/${fromDate}/${toDate}`,
|
||||||
|
params: {
|
||||||
|
withLeg: "true",
|
||||||
|
direction: 'Both',
|
||||||
|
withCancelled: "true",
|
||||||
|
withCodeshared: "true",
|
||||||
|
withCargo: "false",
|
||||||
|
withPrivate: "false",
|
||||||
|
withLocation: "true",
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
"X-RapidAPI-Key": `${RAPID_API_KEY_AERODATABOX}`,
|
||||||
|
"X-RapidAPI-Host": `${RAPID_API_HOST_AERODATABOX}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await axios.request(axiosOptions);
|
||||||
|
return response?.data as IFlights || undefined;
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log("[useFlightSchedule] error", error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
getFlightSchedule,
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
interface IStorage {
|
||||||
|
value: unknown;
|
||||||
|
expires?: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
const DEFAULT_EXPIRED_IN_SECONDS = 60 * 60 * 1000; // 1 hour
|
||||||
|
|
||||||
|
const getStorageValue = (key:string, defaultValue:unknown):any => {
|
||||||
|
const storage:IStorage = JSON.parse(sessionStorage.getItem(key) || '{}');
|
||||||
|
// getting stored value
|
||||||
|
const { value, expires } = storage || {} as IStorage;
|
||||||
|
if (expires > new Date() ) {
|
||||||
|
return value || defaultValue;
|
||||||
|
}
|
||||||
|
return undefined ;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useLocalStorage = (key:string, defaultValue:unknown, expiredIn?: number):any => {
|
||||||
|
const [value, setStorageValue] = React.useState(() => {
|
||||||
|
return getStorageValue(key, defaultValue);
|
||||||
|
});
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
// save value
|
||||||
|
const expiredInValue = expiredIn ? new Date(new Date().getTime() + expiredIn * 1000) : DEFAULT_EXPIRED_IN_SECONDS;
|
||||||
|
|
||||||
|
sessionStorage.setItem(key, JSON.stringify({ value, expires:expiredInValue }));
|
||||||
|
|
||||||
|
}, [key, value, expiredIn]);
|
||||||
|
|
||||||
|
return [value, setStorageValue];
|
||||||
|
};
|
|
@ -0,0 +1,115 @@
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
import { sortBy } from 'lodash';
|
||||||
|
|
||||||
|
import { EInformationType } from '../constants/EInformationType';
|
||||||
|
import {
|
||||||
|
Arrivals,
|
||||||
|
Departures,
|
||||||
|
IFlights,
|
||||||
|
} from '../models/IFlights';
|
||||||
|
import { IFlightTrackerListItem } from '../models/IFlightTrackerListItem';
|
||||||
|
import { useUtils } from './useUtils';
|
||||||
|
|
||||||
|
const getPageIndex = (page: number, numberItemsPerPage: number): number => {
|
||||||
|
return page * numberItemsPerPage;
|
||||||
|
};
|
||||||
|
export interface IUseMappingFlightShedules {
|
||||||
|
|
||||||
|
|
||||||
|
mapFlightSchedules: (
|
||||||
|
flightInformationType: EInformationType,
|
||||||
|
flightSchedules: IFlights,
|
||||||
|
page: number,
|
||||||
|
numberItemsPerPage: number
|
||||||
|
) => Promise<IFlightTrackerListItem[]>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useMappingFlightSchedules = (): IUseMappingFlightShedules => {
|
||||||
|
const { getAirlineLogo, getTimeFromDate } = useUtils();
|
||||||
|
|
||||||
|
const getMappedFlightScheduleDeparture = useCallback(async (flightSchedule: Departures): Promise<
|
||||||
|
IFlightTrackerListItem
|
||||||
|
> => {
|
||||||
|
const logo = await getAirlineLogo(flightSchedule.airline.name);
|
||||||
|
const mappedFlightSchedule = {
|
||||||
|
flightCompanyImage: logo ?? "",
|
||||||
|
flightNumber: flightSchedule.number,
|
||||||
|
flightStatus: flightSchedule.status,
|
||||||
|
flightTime: getTimeFromDate(flightSchedule.departure.scheduledTimeLocal),
|
||||||
|
flightRealTime: getTimeFromDate(flightSchedule.departure.actualTimeLocal),
|
||||||
|
flightTimeStatusText: flightSchedule.status,
|
||||||
|
flightTerminal: flightSchedule.departure.terminal,
|
||||||
|
FlightGate: flightSchedule.departure.gate,
|
||||||
|
flightOrigin: flightSchedule.arrival.airport.name,
|
||||||
|
flightCompany: flightSchedule.airline.name,
|
||||||
|
};
|
||||||
|
return mappedFlightSchedule;
|
||||||
|
}, [getAirlineLogo]);
|
||||||
|
|
||||||
|
const getMappedFlightScheduleArrival = useCallback(async (flightSchedule: Arrivals): Promise<
|
||||||
|
IFlightTrackerListItem
|
||||||
|
> => {
|
||||||
|
const logo = await getAirlineLogo(flightSchedule.airline.name);
|
||||||
|
const mappedFlightSchedule = {
|
||||||
|
flightCompanyImage: logo ?? "",
|
||||||
|
flightNumber: flightSchedule.number,
|
||||||
|
flightStatus: flightSchedule.status,
|
||||||
|
flightTime: getTimeFromDate(flightSchedule.arrival.scheduledTimeLocal),
|
||||||
|
flightRealTime: getTimeFromDate(flightSchedule.arrival.actualTimeLocal),
|
||||||
|
flightTimeStatusText: flightSchedule.status,
|
||||||
|
flightTerminal: flightSchedule?.departure?.terminal ?? "",
|
||||||
|
FlightGate: flightSchedule?.departure?.gate ?? "",
|
||||||
|
flightOrigin: flightSchedule?.departure?.airport?.name,
|
||||||
|
flightCompany: flightSchedule?.airline?.name,
|
||||||
|
};
|
||||||
|
return mappedFlightSchedule;
|
||||||
|
}, [getAirlineLogo]);
|
||||||
|
|
||||||
|
|
||||||
|
const getMappedFlightSchedules = useCallback(
|
||||||
|
async (
|
||||||
|
flightSchedules: IFlights,
|
||||||
|
page: number,
|
||||||
|
numberItemsPerPage: number,
|
||||||
|
flightInformationType: EInformationType
|
||||||
|
): Promise<IFlightTrackerListItem[]> => {
|
||||||
|
if (!flightSchedules) return undefined;
|
||||||
|
const mappedFlightSchedules: IFlightTrackerListItem[] = [];
|
||||||
|
const flightsInfoToMap =
|
||||||
|
flightInformationType === EInformationType.DEPARTURES
|
||||||
|
? sortBy((flightSchedules.departures as Departures[]), ["departure.scheduledTimeLocal"])
|
||||||
|
: sortBy((flightSchedules.arrivals as Arrivals[]) , ["arrival.scheduledTimeLocal"]);
|
||||||
|
const pageIndex = getPageIndex(page, numberItemsPerPage);
|
||||||
|
const items = flightsInfoToMap.slice(pageIndex, pageIndex + numberItemsPerPage);
|
||||||
|
console.log('items', items);
|
||||||
|
for (const flightSchedule of items) {
|
||||||
|
const mappedInfo =
|
||||||
|
flightInformationType === EInformationType.DEPARTURES
|
||||||
|
? await getMappedFlightScheduleDeparture(flightSchedule)
|
||||||
|
: await getMappedFlightScheduleArrival(flightSchedule);
|
||||||
|
mappedFlightSchedules.push(mappedInfo);
|
||||||
|
}
|
||||||
|
return mappedFlightSchedules;
|
||||||
|
},
|
||||||
|
[getAirlineLogo]
|
||||||
|
);
|
||||||
|
|
||||||
|
const mapFlightSchedules = useCallback(
|
||||||
|
async (
|
||||||
|
flightInformationType: EInformationType,
|
||||||
|
flightSchedules: IFlights,
|
||||||
|
page: number,
|
||||||
|
numberItemsPerPage: number
|
||||||
|
): Promise<IFlightTrackerListItem[]> => {
|
||||||
|
let mappedFlights: IFlightTrackerListItem[] = [];
|
||||||
|
mappedFlights = await getMappedFlightSchedules(flightSchedules, page, numberItemsPerPage, flightInformationType);
|
||||||
|
return mappedFlights;
|
||||||
|
},
|
||||||
|
[getMappedFlightSchedules]
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
mapFlightSchedules,
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,114 @@
|
||||||
|
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
format,
|
||||||
|
isSameDay,
|
||||||
|
parseISO,
|
||||||
|
} from 'date-fns';
|
||||||
|
import { useRecoilState } from 'recoil';
|
||||||
|
|
||||||
|
import { IAirline } from '../models/IAirlines';
|
||||||
|
import { airlineState } from '../recoil/atoms/airlineState';
|
||||||
|
import { globalState } from '../recoil/atoms/globalState';
|
||||||
|
|
||||||
|
const PHOTO_AIRLINE_URL = "https://r-xx.bstatic.com/data/airlines_logo/";
|
||||||
|
|
||||||
|
export const useUtils = () => {
|
||||||
|
const [appState] = useRecoilState(globalState);
|
||||||
|
|
||||||
|
const [airlinesList] = useRecoilState(airlineState);
|
||||||
|
const { currentTheme } = appState;
|
||||||
|
|
||||||
|
const statusColors = new Map<string, string>([
|
||||||
|
["Unknown", currentTheme?.semanticColors?.bodyText],
|
||||||
|
["Expected", currentTheme?.semanticColors?.bodyText],
|
||||||
|
["EnRoute", currentTheme?.semanticColors?.bodyText],
|
||||||
|
["CheckIn", currentTheme?.palette?.themePrimary],
|
||||||
|
["Boarding", currentTheme?.palette?.themePrimary],
|
||||||
|
["GateClosed", currentTheme?.semanticColors?.bodyText],
|
||||||
|
["Departed", currentTheme?.palette?.themePrimary],
|
||||||
|
["Delayed", currentTheme?.palette?.yellowDark],
|
||||||
|
["Approaching", currentTheme?.semanticColors?.bodyText],
|
||||||
|
["Arrived", currentTheme?.palette?.themePrimary],
|
||||||
|
["Canceled", currentTheme?.semanticColors?.errorText],
|
||||||
|
["Diverted", currentTheme?.semanticColors?.errorText],
|
||||||
|
["CanceledUncertain", currentTheme?.semanticColors?.bodyText],
|
||||||
|
]);
|
||||||
|
|
||||||
|
const getFlightStatusColor = React.useCallback(
|
||||||
|
(status: string): string => {
|
||||||
|
return statusColors.get(status) || currentTheme?.semanticColors?.bodyText;
|
||||||
|
},
|
||||||
|
[currentTheme, statusColors]
|
||||||
|
);
|
||||||
|
|
||||||
|
const getTimeFromDate = React.useCallback((date: string): string => {
|
||||||
|
const { selectedDate } = appState;
|
||||||
|
try {
|
||||||
|
if (date) {
|
||||||
|
if (isSameDay(parseISO(date), selectedDate)) {
|
||||||
|
return format(parseISO(date), "p");
|
||||||
|
} else {
|
||||||
|
return format(parseISO(date), "dd MMM, p");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log(["getTimeFromDate"], error);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const getAirlineByName = React.useCallback(
|
||||||
|
async (name: string): Promise<IAirline> => {
|
||||||
|
try {
|
||||||
|
if (name && airlinesList && airlinesList?.rows?.length > 0) {
|
||||||
|
const airline = airlinesList.rows.find((airline: IAirline) =>
|
||||||
|
airline.Name.toLowerCase().includes(name.toLowerCase())
|
||||||
|
);
|
||||||
|
let photo = "";
|
||||||
|
if (airline?.Code) {
|
||||||
|
photo = `${PHOTO_AIRLINE_URL}${airline.Code}.png`;
|
||||||
|
}
|
||||||
|
return { ...airline, Photo: photo };
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log(["getAirlineByName"], error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[airlinesList]
|
||||||
|
);
|
||||||
|
|
||||||
|
const getAirlineLogo = React.useCallback(
|
||||||
|
async (airlineName: string): Promise<string> => {
|
||||||
|
try {
|
||||||
|
if (airlineName) {
|
||||||
|
const airline = await getAirlineByName(airlineName);
|
||||||
|
|
||||||
|
if (airline) {
|
||||||
|
return airline.Photo ?? undefined;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
if (DEBUG) {
|
||||||
|
console.log(["getAirlineLogo"], error);
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[airlinesList]
|
||||||
|
);
|
||||||
|
|
||||||
|
return { getFlightStatusColor, getTimeFromDate, getAirlineLogo, getAirlineByName };
|
||||||
|
};
|
|
@ -0,0 +1 @@
|
||||||
|
// A file is required to be in the root of the /src directory by the TypeScript compiler
|
|
@ -0,0 +1,11 @@
|
||||||
|
export interface IAirlines {
|
||||||
|
version: number;
|
||||||
|
rows:IAirline[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IAirline {
|
||||||
|
Name: string;
|
||||||
|
Code: string;
|
||||||
|
ICAO: string;
|
||||||
|
Photo?: string;
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
export interface IAirport {
|
||||||
|
id: string;
|
||||||
|
ident: string;
|
||||||
|
type: string;
|
||||||
|
name: string;
|
||||||
|
latitude_deg: string;
|
||||||
|
longitude_deg: string;
|
||||||
|
continent: string;
|
||||||
|
iso_country: string;
|
||||||
|
iso_region: string;
|
||||||
|
municipality: string;
|
||||||
|
scheduled_service: string;
|
||||||
|
gps_code: string;
|
||||||
|
iata_code: string;
|
||||||
|
local_code: string;
|
||||||
|
wikipedia_link: string;
|
||||||
|
keywords: string;
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import * as React from 'react';
|
||||||
|
|
||||||
|
import { IIconProps } from 'office-ui-fabric-react';
|
||||||
|
|
||||||
|
export interface IAttribute{
|
||||||
|
attributeName: string;
|
||||||
|
attributeValue: string | React.ReactNode;
|
||||||
|
iconProps?: IIconProps
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
export interface IFlightInfo {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
detail: Detail;
|
||||||
|
type: string;
|
||||||
|
match: string;
|
||||||
|
name?: string;
|
||||||
|
|
||||||
|
}
|
||||||
|
interface Detail {
|
||||||
|
iata?: string;
|
||||||
|
logo: string;
|
||||||
|
callsign?: string;
|
||||||
|
flight?: string;
|
||||||
|
operator?: string;
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
export interface IFlightSchedulesInputParm {
|
||||||
|
fromDate: string;
|
||||||
|
toDate: string;
|
||||||
|
airportCode: string;
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
export interface IFlightStatus {
|
||||||
|
flightId: string;
|
||||||
|
status: string;
|
||||||
|
date: string;
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
export interface IFlightTrackerListItem {
|
||||||
|
flightCompanyImage: string;
|
||||||
|
flightNumber: string;
|
||||||
|
flightStatus: string;
|
||||||
|
flightTime: string;
|
||||||
|
flightRealTime: string;
|
||||||
|
flightTimeStatusText: string;
|
||||||
|
flightTerminal: string;
|
||||||
|
FlightGate: string;
|
||||||
|
flightOrigin: string;
|
||||||
|
flightCompany: string;
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
export interface IFlights {
|
||||||
|
departures: Departures[];
|
||||||
|
arrivals: Arrivals[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Arrivals {
|
||||||
|
departure: Departure;
|
||||||
|
arrival: Arrival;
|
||||||
|
number: string;
|
||||||
|
status: string;
|
||||||
|
codeshareStatus: string;
|
||||||
|
isCargo: boolean;
|
||||||
|
aircraft?: Aircraft;
|
||||||
|
airline: Airline;
|
||||||
|
callSign?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export interface Departures{
|
||||||
|
departure: Departure;
|
||||||
|
arrival: Arrival;
|
||||||
|
number: string;
|
||||||
|
status: string;
|
||||||
|
codeshareStatus: string;
|
||||||
|
isCargo: boolean;
|
||||||
|
airline: Airline;
|
||||||
|
aircraft?: Aircraft;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Aircraft {
|
||||||
|
model: string;
|
||||||
|
reg?: string;
|
||||||
|
modeS?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Airline {
|
||||||
|
name: string;
|
||||||
|
logo?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Arrival {
|
||||||
|
airport: Airport;
|
||||||
|
quality: string[];
|
||||||
|
scheduledTimeLocal?: string;
|
||||||
|
scheduledTimeUtc?: string;
|
||||||
|
actualTimeLocal?: string;
|
||||||
|
runwayTimeLocal?: string;
|
||||||
|
actualTimeUtc?: string;
|
||||||
|
runwayTimeUtc?: string;
|
||||||
|
terminal?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Airport {
|
||||||
|
name: string;
|
||||||
|
icao?: string;
|
||||||
|
iata?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Departure {
|
||||||
|
airport: Airport;
|
||||||
|
scheduledTimeLocal: string;
|
||||||
|
actualTimeLocal: string;
|
||||||
|
scheduledTimeUtc: string;
|
||||||
|
actualTimeUtc: string;
|
||||||
|
quality: string[];
|
||||||
|
terminal?: string;
|
||||||
|
checkInDesk?: string;
|
||||||
|
gate?: string;
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
import { IReadonlyTheme } from '@microsoft/sp-component-base';
|
||||||
|
import { WebPartContext } from '@microsoft/sp-webpart-base';
|
||||||
|
|
||||||
|
import { EInformationType } from '../constants/EInformationType';
|
||||||
|
import { IAirport } from './IAirport';
|
||||||
|
|
||||||
|
export interface IGlobalState {
|
||||||
|
isDarkTheme: boolean;
|
||||||
|
hasTeamsContext: boolean;
|
||||||
|
context: WebPartContext;
|
||||||
|
currentTheme: IReadonlyTheme | undefined;
|
||||||
|
selectedAirPort:IAirport;
|
||||||
|
selectedDate:Date;
|
||||||
|
selectedTime:Date;
|
||||||
|
selectedInformationType: EInformationType;
|
||||||
|
numberItemsPerPage: number;
|
||||||
|
currentPage: number;
|
||||||
|
isScrolling: boolean;
|
||||||
|
hasMore: boolean;
|
||||||
|
webpartContainerWidth: number;
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
export interface ISearchAirports {
|
||||||
|
airportsByCities: IAirportsByCity[];
|
||||||
|
cities: ICity[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ICity {
|
||||||
|
GMT: string;
|
||||||
|
codeIataCity: string;
|
||||||
|
codeIso2Country: string;
|
||||||
|
latitudeCity: number;
|
||||||
|
longitudeCity: number;
|
||||||
|
nameCity: string;
|
||||||
|
timezone: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IAirportsByCity {
|
||||||
|
GMT: string;
|
||||||
|
codeIataAirport: string;
|
||||||
|
codeIataCity: string;
|
||||||
|
codeIcaoAirport: string;
|
||||||
|
codeIso2Country: string;
|
||||||
|
latitudeAirport: number;
|
||||||
|
longitudeAirport: number;
|
||||||
|
nameAirport: string;
|
||||||
|
nameCountry: string;
|
||||||
|
phone: string;
|
||||||
|
timezone: string;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
export * from './IAirlines';
|
||||||
|
export * from './IAirport';
|
||||||
|
export * from './IAttribute';
|
||||||
|
export * from './IFlightInfo';
|
||||||
|
export * from './IFlightSchedulesParm';
|
||||||
|
export * from './IFlightStatus';
|
||||||
|
export * from './IFlightTrackerListItem';
|
||||||
|
export * from './IFlights';
|
||||||
|
export * from './IGlobalState';
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { atom } from 'recoil';
|
||||||
|
|
||||||
|
import { IAirlines } from '../../models/IAirlines';
|
||||||
|
|
||||||
|
export const airlineState = atom<IAirlines>({
|
||||||
|
key: "airlinesState",
|
||||||
|
default: {} as IAirlines,
|
||||||
|
});
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { atom } from 'recoil';
|
||||||
|
|
||||||
|
import { IFlights } from '../../models/IFlights';
|
||||||
|
|
||||||
|
export const flightsState = atom<IFlights>({
|
||||||
|
key: "flightsListState",
|
||||||
|
default: {departures: [], arrivals: []},
|
||||||
|
});
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { atom } from 'recoil';
|
||||||
|
|
||||||
|
import { EInformationType } from '../../constants/EInformationType';
|
||||||
|
import { IGlobalState } from '../../models/IGlobalState';
|
||||||
|
|
||||||
|
export const globalState = atom<IGlobalState>({
|
||||||
|
key: "globaltState",
|
||||||
|
default: {
|
||||||
|
isDarkTheme: false,
|
||||||
|
hasTeamsContext: false,
|
||||||
|
context: undefined,
|
||||||
|
currentTheme: undefined,
|
||||||
|
selectedAirPort: undefined,
|
||||||
|
selectedDate: new Date(),
|
||||||
|
selectedTime: new Date(),
|
||||||
|
selectedInformationType: EInformationType.DEPARTURES,
|
||||||
|
numberItemsPerPage: 7,
|
||||||
|
currentPage: 0,
|
||||||
|
isScrolling: false,
|
||||||
|
hasMore: true,
|
||||||
|
webpartContainerWidth: 0
|
||||||
|
},
|
||||||
|
});
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './flightsState';
|
||||||
|
export * from './globalState';
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"themePrimary": "#6264a7",
|
||||||
|
"themeLighterAlt": "#f7f7fb",
|
||||||
|
"themeLighter": "#e1e1f1",
|
||||||
|
"themeLight": "#c8c9e4",
|
||||||
|
"themeTertiary": "#989ac9",
|
||||||
|
"themeSecondary": "#7173b0",
|
||||||
|
"themeDarkAlt": "#585a95",
|
||||||
|
"themeDark": "#4a4c7e",
|
||||||
|
"themeDarker": "#37385d",
|
||||||
|
"neutralLighterAlt": "#0b0b0b",
|
||||||
|
"neutralLighter": "#151515",
|
||||||
|
"neutralLight": "#252525",
|
||||||
|
"neutralQuaternaryAlt": "#2f2f2f",
|
||||||
|
"neutralQuaternary": "#373737",
|
||||||
|
"neutralTertiaryAlt": "#595959",
|
||||||
|
"neutralTertiary": "#c8c8c8",
|
||||||
|
"neutralSecondary": "#d0d0d0",
|
||||||
|
"neutralPrimaryAlt": "#dadada",
|
||||||
|
"neutralPrimary": "#ffffff",
|
||||||
|
"neutralDark": "#f4f4f4",
|
||||||
|
"black": "#f8f8f8",
|
||||||
|
"white": "#000000"
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"themePrimary": "#7f85f5",
|
||||||
|
"themeLighterAlt": "#05050a",
|
||||||
|
"themeLighter": "#141527",
|
||||||
|
"themeLight": "#262849",
|
||||||
|
"themeTertiary": "#4c5093",
|
||||||
|
"themeSecondary": "#7075d7",
|
||||||
|
"themeDarkAlt": "#8c91f6",
|
||||||
|
"themeDark": "#9da2f7",
|
||||||
|
"themeDarker": "#b6baf9",
|
||||||
|
"neutralLighterAlt": "#282828",
|
||||||
|
"neutralLighter": "#313131",
|
||||||
|
"neutralLight": "#3f3f3f",
|
||||||
|
"neutralQuaternaryAlt": "#484848",
|
||||||
|
"neutralQuaternary": "#4f4f4f",
|
||||||
|
"neutralTertiaryAlt": "#6d6d6d",
|
||||||
|
"neutralTertiary": "#c8c8c8",
|
||||||
|
"neutralSecondary": "#d0d0d0",
|
||||||
|
"neutralPrimaryAlt": "#dadada",
|
||||||
|
"neutralPrimary": "#ffff",
|
||||||
|
"neutralDark": "#f4f4f4",
|
||||||
|
"black": "#ffffff",
|
||||||
|
"white": "#1f1f1f"
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"themePrimary": "#6264a7",
|
||||||
|
"themeLighterAlt": "#f7f7fb",
|
||||||
|
"themeLighter": "#e1e1f1",
|
||||||
|
"themeLight": "#c8c9e4",
|
||||||
|
"themeTertiary": "#989ac9",
|
||||||
|
"themeSecondary": "#7173b0",
|
||||||
|
"themeDarkAlt": "#585a95",
|
||||||
|
"themeDark": "#4a4c7e",
|
||||||
|
"themeDarker": "#37385d",
|
||||||
|
"neutralLighterAlt": "#ecebe9",
|
||||||
|
"neutralLighter": "#e8e7e6",
|
||||||
|
"neutralLight": "#dedddc",
|
||||||
|
"neutralQuaternaryAlt": "#cfcecd",
|
||||||
|
"neutralQuaternary": "#c6c5c4",
|
||||||
|
"neutralTertiaryAlt": "#bebdbc",
|
||||||
|
"neutralTertiary": "#b5b4b2",
|
||||||
|
"neutralSecondary": "#9d9c9a",
|
||||||
|
"neutralPrimaryAlt": "#868482",
|
||||||
|
"neutralPrimary": "#252423",
|
||||||
|
"neutralDark": "#565453",
|
||||||
|
"black": "#3e3d3b",
|
||||||
|
"white": "#f3f2f1"
|
||||||
|
}
|