Skip to content

Commit

Permalink
fix: FPFSS tag and platform edits
Browse files Browse the repository at this point in the history
  • Loading branch information
colin969 committed Mar 15, 2024
1 parent aa32842 commit 4582a8d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
73 changes: 53 additions & 20 deletions src/renderer/components/RightBrowseSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,11 @@ export class RightBrowseSidebar extends React.Component<RightBrowseSidebarProps,
if (tag) {
const game = this.props.currentGameInfo?.game;
// Ignore dupe tags
if (game && !game.tags.includes(tag.name)) {
this.props.onEditGame({ tags: [...game.tags, tag.name] });
if (game && !game.tags.map(t => t.toLowerCase()).includes(tag.name.toLowerCase())) {
if (!game.detailedTags) {
game.detailedTags = [];
}
this.props.onEditGame({ tags: [...game.tags, tag.name], detailedTags: [...game.detailedTags, tag]});
console.log('ADDED TAG ' + tag.id);
}
}
Expand All @@ -1270,9 +1273,12 @@ export class RightBrowseSidebar extends React.Component<RightBrowseSidebarProps,
if (platform) {
const game = this.props.currentGameInfo?.game;
// Ignore dupe tags
if (game && !game.platforms.includes(platform.name)) {
if (game && !game.platforms.map(t => t.toLowerCase()).includes(platform.name.toLowerCase())) {
if (!game.detailedPlatforms) {
game.detailedPlatforms = [];
}
const primary = game.platforms.length === 0 ? platform.name : game.primaryPlatform;
this.props.onEditGame({ platforms: [...game.platforms, platform.name], primaryPlatform: primary });
this.props.onEditGame({ platforms: [...game.platforms, platform.name], primaryPlatform: primary, detailedPlatforms: [...game.detailedPlatforms, platform] });
console.log('ADDED PLATFORM ' + platform.id);
}
}
Expand All @@ -1296,26 +1302,33 @@ export class RightBrowseSidebar extends React.Component<RightBrowseSidebarProps,
onAddTagByString = (text: string): void => {
if (text !== '') {
if (this.props.fpfssEditMode) {
const newTagText = text.trim();
const game = this.props.currentGameInfo?.game;
if (game) {
if (game && !game.tags.map(t => t.toLowerCase()).includes(newTagText.toLowerCase())) {
if (!game.detailedTags) {
game.detailedTags = [];
}
const tag: Tag = {
id: -1,
name: text,
aliases: [text],
name: newTagText,
aliases: [newTagText],
description: '',
dateModified: (new Date()).toISOString(),
category: 'default'
};
this.props.onEditGame({ tags: [...game.tags, tag.name]});
this.props.onEditGame({ tags: [...game.tags, tag.name], detailedTags: [...game.detailedTags, tag]});
}
} else {
window.Shared.back.request(BackIn.GET_OR_CREATE_TAG, text)
.then((tag) => {
if (tag) {
const game = this.props.currentGameInfo?.game;
// Ignore dupe tags
if (game && !game.tags.includes(tag.name)) {
this.props.onEditGame({ tags: [...game.tags, tag.name] });
if (game && !game.tags.map(t => t.toLowerCase()).includes(tag.name.toLowerCase())) {
if (!game.detailedTags) {
game.detailedTags = [];
}
this.props.onEditGame({ tags: [...game.tags, tag.name], detailedTags: [...game.detailedTags, tag]});
}
}
});
Expand All @@ -1332,26 +1345,34 @@ export class RightBrowseSidebar extends React.Component<RightBrowseSidebarProps,
onAddPlatformByString = (text: string): void => {
if (text !== '') {
if (this.props.fpfssEditMode) {
const newPlatformText = text.trim();
const game = this.props.currentGameInfo?.game;
if (game) {
if (game && !game.platforms.map(t => t.toLowerCase()).includes(newPlatformText.toLowerCase())) {
if (!game.detailedPlatforms) {
game.detailedPlatforms = [];
}
const platform: Platform = {
id: -1,
name: text,
aliases: [text],
name: newPlatformText,
aliases: [newPlatformText],
description: '',
dateModified: (new Date()).toISOString()
};
const primary = game.platforms.length === 0 ? platform.name : game.primaryPlatform;
this.props.onEditGame({ platforms: [...game.platforms, platform.name], primaryPlatform: primary });
this.props.onEditGame({ platforms: [...game.platforms, platform.name], primaryPlatform: primary, detailedPlatforms: [...game.detailedPlatforms, platform] });
}
} else {
window.Shared.back.request(BackIn.GET_OR_CREATE_PLATFORM, text)
.then((platform) => {
if (platform) {
const game = this.props.currentGameInfo?.game;
// Ignore dupe platforms
if (game && !game.platforms.includes(platform.name)) {
this.props.onEditGame({ platforms: [...game.platforms, platform.name] });
if (game && !game.platforms.map(t => t.toLowerCase()).includes(platform.name.toLowerCase())) {
if (!game.detailedPlatforms) {
game.detailedPlatforms = [];
}
const primary = game.platforms.length === 0 ? platform.name : game.primaryPlatform;
this.props.onEditGame({ platforms: [...game.platforms, platform.name], primaryPlatform: primary, detailedPlatforms: [...game.detailedPlatforms, platform] });
}
}
});
Expand All @@ -1365,18 +1386,30 @@ export class RightBrowseSidebar extends React.Component<RightBrowseSidebarProps,
onRemoveTag = (tag: Tag, index: number): void => {
const game = this.props.currentGameInfo?.game;
if (game) {
if (!game.detailedTags) {
game.detailedTags = [];
}
const newDetailedTags = deepCopy(game.detailedTags);
const newTags = deepCopy(game.tags);
newTags.splice(index, 1);
this.props.onEditGame({ tags: newTags });
const tagsIndex = newTags.findIndex(t => t.toLowerCase() === newDetailedTags[index].name.toLowerCase());
newTags.splice(tagsIndex, 1);
newDetailedTags.splice(index, 1);
this.props.onEditGame({ tags: newTags, detailedTags: newDetailedTags });
}
};

onRemovePlatform = (platform: Platform, index: number): void => {
const game = this.props.currentGameInfo?.game;
if (game) {
if (!game.detailedPlatforms) {
game.detailedPlatforms = [];
}
const newDetailedPlatforms = deepCopy(game.detailedPlatforms);
const newPlatforms = deepCopy(game.platforms);
newPlatforms.splice(index, 1);
this.props.onEditGame({ platforms: newPlatforms });
const platIndex = newPlatforms.findIndex(p => p.toLowerCase() === newDetailedPlatforms[index].name.toLowerCase());
newPlatforms.splice(platIndex, 1);
newDetailedPlatforms.splice(index, 1);
this.props.onEditGame({ platforms: newPlatforms, detailedPlatforms: newDetailedPlatforms });
}
};

Expand Down
4 changes: 2 additions & 2 deletions src/shared/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ export function mapLocalToFpfssGame(game: Game): FpfssGame {
id: t.id,
name: t.name,
description: t.description,
date_modified: t.dateModified,
date_modified: (new Date(t.dateModified)).toISOString(),
category: t.category || 'default',
};
}) || [],
Expand All @@ -661,7 +661,7 @@ export function mapLocalToFpfssGame(game: Game): FpfssGame {
id: p.id,
name: p.name,
description: p.description,
date_modified: p.dateModified,
date_modified: (new Date(p.dateModified)).toISOString(),
};
}) || [],
add_apps: game.addApps?.map<FpfssAddApp>(a => {
Expand Down

0 comments on commit 4582a8d

Please sign in to comment.