Skip to content

Commit

Permalink
Merge pull request #489 from scottbenton/fix/location-crash
Browse files Browse the repository at this point in the history
fix(error): Adding a lot of optional chaining to fix an error
  • Loading branch information
scottbenton authored Jun 28, 2024
2 parents 5e64261 + 368883a commit ea1fae3
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Locations are now nestable.
- Added types to locations, which determine a default icon for each location type, as well as allowing for specific fields to show up for specific types.
- Maps can be painted with background colors
- Maps can now have images uploaded to use as backgrounds to the maps.

### Changes

Expand Down
Binary file added public/assets/ironsworn/CampaignPage.webp
Binary file not shown.
Binary file modified public/assets/ironsworn/CharacterSheet.webp
Binary file not shown.
Binary file added public/assets/ironsworn/GMTools.webp
Binary file not shown.
Binary file added public/assets/ironsworn/World.webp
Binary file not shown.
Binary file added public/assets/starforged/CampaignPage.webp
Binary file not shown.
Binary file modified public/assets/starforged/CharacterSheet.webp
Binary file not shown.
Binary file added public/assets/starforged/GMTools.webp
Binary file not shown.
Binary file added public/assets/starforged/World.webp
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function AddMoveLocationChooserDialog(
const filteredLocationIds = Object.keys(locations).filter((locationId) => {
const location = locations[locationId];
return (
(showAll ? true : location.parentLocationId === currentLocationId) &&
(showAll ? true : location?.parentLocationId === currentLocationId) &&
location.name.toLowerCase().includes(search.toLowerCase()) &&
locationId !== currentLocationId
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/features/worlds/Locations/LocationsSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function LocationsSidebar(props: LocationsSidebarProps) {
const locationParentMap: Record<string, string[]> = {};

locationIds.forEach((locationId) => {
const parentId = locations[locationId].parentLocationId ?? "root";
const parentId = locations[locationId]?.parentLocationId ?? "root";
if (!locationParentMap[parentId]) {
locationParentMap[parentId] = [];
}
Expand Down Expand Up @@ -62,7 +62,7 @@ function getCurrentLocationAncestors(
): string[] {
const currentLocationAncestors: string[] = [];
let currentLocation = locations[locationId];
while (currentLocation.parentLocationId) {
while (currentLocation?.parentLocationId) {
currentLocationAncestors.push(currentLocation.parentLocationId);
currentLocation = locations[currentLocation.parentLocationId];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function MoveLocationDialog(props: MoveLocationDialogProps) {
.sort((a, b) => {
// Sort by parent location first. If no parent location exists, sort it to the top.
// If the parent locations are the same, sort by name.
const aParent = locationMap[a].parentLocationId;
const bParent = locationMap[b].parentLocationId;
const aParent = locationMap[a]?.parentLocationId;
const bParent = locationMap[b]?.parentLocationId;
if (aParent && bParent) {
if (aParent < bParent) {
return -1;
Expand Down
2 changes: 1 addition & 1 deletion src/components/features/worlds/Locations/SubLocations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function SubLocations(props: SubLocationsProps) {
);

const filteredLocationIds = Object.keys(locations)
.filter((id) => locations[id].parentLocationId === locationId)
.filter((id) => locations[id]?.parentLocationId === locationId)
.sort((a, b) => locations[a].name.localeCompare(locations[b].name));

const handleCreateLocation = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useFilterLocations(
() =>
sortedLocationIds.filter(
(locationId) =>
!locations[locationId].parentLocationId &&
!locations[locationId]?.parentLocationId &&
(locations[locationId].name
.toLowerCase()
.includes(debouncedSearch.toLowerCase()) ||
Expand Down
19 changes: 10 additions & 9 deletions src/pages/Home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ExampleSupplySection } from "./ExampleSupplySection";
import { ExampleTrackSection } from "./ExampleTrackSection";
import { Licensing } from "./Licensing";
import { getPublicAssetPath } from "functions/getPublicAssetPath";
import { useNewMaps } from "hooks/featureFlags/useNewMaps";

export function HomePage() {
const isLoggedIn = useStore((store) => !!store.auth.user);
Expand All @@ -25,6 +26,8 @@ export function HomePage() {
[GAME_SYSTEMS.STARFORGED]: "Starforged",
});

const showNewLocationScreenshots = useNewMaps();

return (
<>
<PageHeader>
Expand Down Expand Up @@ -148,7 +151,7 @@ export function HomePage() {
<Box
border={(theme) => `1px solid ${theme.palette.divider}`}
component={"img"}
src={getPublicAssetPath("CampaignView.webp")}
src={getPublicAssetPath("CampaignPage.webp")}
alt={`Screenshot of a campaign in ${appName}`}
width={"100%"}
borderRadius={(theme) => `${theme.shape.borderRadius}px`}
Expand Down Expand Up @@ -183,10 +186,8 @@ export function HomePage() {
<Box
border={(theme) => `1px solid ${theme.palette.divider}`}
component={"img"}
src={getPublicAssetPath("GMScreen.webp")}
alt={
"Screenshot of a campaign in Iron Fellowship titled Land of Ten Thousand Gods with four characters added."
}
src={getPublicAssetPath("GMTools.webp")}
alt={`Screenshot of the Guide tools in a campaign in ${appName}, including moves, oracles, tracks, notes, and more.`}
width={"100%"}
borderRadius={(theme) => `${theme.shape.borderRadius}px`}
/>
Expand Down Expand Up @@ -220,10 +221,10 @@ export function HomePage() {
<Box
border={(theme) => `1px solid ${theme.palette.divider}`}
component={"img"}
src={getPublicAssetPath("WorldSheet.webp")}
alt={
"Screenshot of a campaign in Iron Fellowship titled Land of Ten Thousand Gods with four characters added."
}
src={getPublicAssetPath(
showNewLocationScreenshots ? "World.webp" : "WorldSheet.webp"
)}
alt={`Screenshot of a world map in ${appName}.`}
width={"100%"}
borderRadius={(theme) => `${theme.shape.borderRadius}px`}
/>
Expand Down

0 comments on commit ea1fae3

Please sign in to comment.