Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.10.1 bugfixes and tooltips #637

Merged
merged 13 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions client/Library/FilterCache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _ = require("lodash");
import { Listable } from "../../common/Listable";
import { Listing, ListingOrigin } from "./Listing";

Expand Down Expand Up @@ -70,13 +71,29 @@ export class FilterCache<T extends Listing<Listable>> {

private filterCache: Record<string, T[]> = {};

public UpdateIfItemsChanged(newItems) {
if (newItems.length != this.initialLength) {
public UpdateIfItemsChanged(newItems: T[]) {
if (
newItems.length != this.initialLength ||
this.itemsHaveUpdatedMeta(newItems)
) {
this.filterCache = {};
this.initializeItems(newItems);
}
}

private itemsHaveUpdatedMeta(newItems: T[]) {
for (let i = 0; i < newItems.length; i++) {
const newItem = newItems[i];
const currentItem = this.allItems[i];
if (!currentItem) {
return true;
}
if (_.isEqual(newItem.Meta(), currentItem.Meta())) {
return true;
}
}
}

public GetFilteredEntries = (filter: string) => {
if (this.filterCache[filter]) {
return this.filterCache[filter];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export class StatBlockLibraryReferencePane extends React.Component<
};

private editStatBlock = (l: Listing<StatBlock>) => {
l.Meta.subscribe(_ => this.forceUpdate());
this.props.librariesCommander.EditStatBlock(l, this.props.library);
};

Expand Down
6 changes: 3 additions & 3 deletions client/StatBlockEditor/StatBlockEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ export class StatBlockEditor extends React.Component<

const buttons = (
<>
<Button onClick={this.close} fontAwesomeIcon="times" />
<Button onClick={this.close} fontAwesomeIcon="times" tooltip="Close Editor" />
{this.props.onDelete && (
<Button onClick={this.delete} fontAwesomeIcon="trash" />
<Button onClick={this.delete} fontAwesomeIcon="trash" tooltip="Delete StatBlock" />
)}
<SubmitButton fontAwesomeIcon="save" />
<SubmitButton fontAwesomeIcon="save" tooltip="Save Changes" />
</>
);

Expand Down
30 changes: 23 additions & 7 deletions client/TextEnricher/TextEnricher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ export class TextEnricher {
Omit<NormalComponents, keyof SpecialComponents> & SpecialComponents
> = {
p: ({ children }) => {
if (isString(children)) {
return <p>{replacer(children)}</p>;
}
if (children.length == 1 && isString(children[0])) {
return <p>{replacer(children[0])}</p>;
}
return <p>{children}</p>;
return <p>{this.applyReplacer(replacer, children)}</p>;
},
li: ({ children }) => {
return <li>{this.applyReplacer(replacer, children)}</li>;
},
strong: ({ children }) => {
return <strong>{this.applyReplacer(replacer, children)}</strong>;
},
em: ({ children }) => {
return <em>{this.applyReplacer(replacer, children)}</em>;
}
};

Expand All @@ -85,6 +88,19 @@ export class TextEnricher {
);
};

private applyReplacer(
replacer: any,
children: React.ReactNode & React.ReactNode[]
) {
if (isString(children)) {
return replacer(children);
}
if (children.length == 1 && isString(children[0])) {
return replacer(children[0]);
}
return children;
}

private buildReactReplacer(
originalText: string,
updateTextSource?: (newText: string) => void
Expand Down
135 changes: 34 additions & 101 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "improved-initiative",
"version": "3.10.0",
"version": "3.10.1",
"description": "Combat tracker for Dungeons and Dragons (D&D) 5th Edition",
"license": "MIT",
"repository": {
Expand Down Expand Up @@ -83,11 +83,11 @@
"browser-filesaver": "^1.1.1",
"color": "^3.2.1",
"connect-redis": "^7.1.0",
"express": "^4.18.2",
"express": "^4.19.2",
"express-session": "^1.17.3",
"express-socket.io-session": "^1.3.5",
"ioredis": "^5.3.2",
"ip": "^1.1.8",
"ip": "^1.1.9",
"json-url": "^2.6.0",
"knockout": "^3.5.1",
"localforage": "^1.10.0",
Expand Down
Loading