@rpg-engine/long-bow 0.5.53 → 0.5.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpg-engine/long-bow",
3
- "version": "0.5.53",
3
+ "version": "0.5.55",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useMemo, useState } from 'react';
2
2
  import styled from 'styled-components';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
 
@@ -21,37 +21,29 @@ export const Dropdown: React.FC<IDropdownProps> = ({
21
21
  }) => {
22
22
  const dropdownId = uuidv4();
23
23
 
24
- const [selectedValue, setSelectedValue] = useState<string>('');
24
+ const firstOption = useMemo(() => options[0], [options]);
25
+ const [selectedValue, setSelectedValue] = useState<string>(
26
+ firstOption ? firstOption.value : ''
27
+ );
25
28
  const [selectedOption, setSelectedOption] = useState<string | JSX.Element>(
26
- ''
29
+ firstOption ? firstOption.option : ''
27
30
  );
28
31
  const [opened, setOpened] = useState<boolean>(false);
29
32
 
30
33
  useEffect(() => {
31
- const firstOption = options[0];
32
-
33
- if (firstOption) {
34
- let change = !selectedValue;
35
- if (!change) {
36
- change = options.filter(o => o.value === selectedValue).length < 1;
37
- }
34
+ const optionValues = new Set(options.map(option => option.value));
38
35
 
39
- /**
40
- * make a selection if there is no selected value already present
41
- * or if there is a selected value but its not in new options
42
- */
43
- if (change) {
44
- setSelectedValue(firstOption.value);
45
- setSelectedOption(firstOption.option);
46
- }
36
+ if (!selectedValue || !optionValues.has(selectedValue)) {
37
+ setSelectedValue(firstOption.value);
38
+ setSelectedOption(firstOption.option);
47
39
  }
48
- }, [options]);
40
+ }, [firstOption, options, selectedValue]);
49
41
 
50
42
  useEffect(() => {
51
43
  if (selectedValue) {
52
44
  onChange(selectedValue);
53
45
  }
54
- }, [selectedValue]);
46
+ }, [selectedValue, onChange]);
55
47
 
56
48
  return (
57
49
  <Container onMouseLeave={() => setOpened(false)} width={width}>
@@ -64,20 +56,18 @@ export const Dropdown: React.FC<IDropdownProps> = ({
64
56
  </DropdownSelect>
65
57
 
66
58
  <DropdownOptions className="rpgui-dropdown-imp" opened={opened}>
67
- {options.map(option => {
68
- return (
69
- <li
70
- key={option.id}
71
- onPointerUp={() => {
72
- setSelectedValue(option.value);
73
- setSelectedOption(option.option);
74
- setOpened(false);
75
- }}
76
- >
77
- {option.option}
78
- </li>
79
- );
80
- })}
59
+ {options.map(option => (
60
+ <li
61
+ key={option.id}
62
+ onPointerUp={() => {
63
+ setSelectedValue(option.value);
64
+ setSelectedOption(option.option);
65
+ setOpened(false);
66
+ }}
67
+ >
68
+ {option.option}
69
+ </li>
70
+ ))}
81
71
  </DropdownOptions>
82
72
  </Container>
83
73
  );
@@ -126,6 +126,10 @@ export const SkillsContainer: React.FC<ISkillContainerProps> = ({
126
126
  //@ts-ignore
127
127
  const skillDetails = (skill[key] as unknown) as ISkillDetails;
128
128
 
129
+ if (!skillDetails) {
130
+ continue;
131
+ }
132
+
129
133
  output.push(
130
134
  <SkillProgressBar
131
135
  key={key}