mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-22 08:58:11 +00:00
fix regex and fixed substrings
This commit is contained in:
@@ -13,7 +13,7 @@ const TagInput = ({ label, unique = true, values = [], placeholder = "", onChang
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
//console.log(label, values, placeholder);
|
//console.log(label, values, placeholder);
|
||||||
// Keep in sync if parent updates values
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const incoming = values || [];
|
const incoming = values || [];
|
||||||
const current = tagList.map((t) => t.value);
|
const current = tagList.map((t) => t.value);
|
||||||
@@ -31,25 +31,34 @@ const TagInput = ({ label, unique = true, values = [], placeholder = "", onChang
|
|||||||
}
|
}
|
||||||
}, [values]);
|
}, [values]);
|
||||||
|
|
||||||
// Emit changes upward
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onChange?.({
|
onChange?.({
|
||||||
target: { value: tagList.map((t) => t.value) },
|
target: { value: tagList.map((t) => t.value) },
|
||||||
});
|
});
|
||||||
}, [tagList]);
|
}, [tagList]);
|
||||||
|
|
||||||
// Canonical duplicate groups
|
|
||||||
const duplicateGroups = [
|
const duplicateGroups = [
|
||||||
|
["5e 2024", "5.5e", "5e'24", "5.24", "5e24", "5.5"],
|
||||||
|
["5e", "5th Edition"],
|
||||||
|
["Dungeons & Dragons", "Dungeons and Dragons", "Dungeons n dragons"],
|
||||||
["D&D", "DnD", "dnd", "Dnd", "dnD", "d&d", "d&D", "D&d"],
|
["D&D", "DnD", "dnd", "Dnd", "dnD", "d&d", "d&D", "D&d"],
|
||||||
["P2e", "p2e", "P2E", "Pathfinder 2e"],
|
["P2e", "p2e", "P2E", "Pathfinder 2e"],
|
||||||
|
["meta:", "Meta:", "META:"],
|
||||||
|
["group:", "Group:", "GROUP:"],
|
||||||
|
["type:", "Type:", "TYPE:"],
|
||||||
|
["system:", "System:", "SYSTEM:"],
|
||||||
];
|
];
|
||||||
|
|
||||||
const normalizeValue = (input) => {
|
const normalizeValue = (input) => {
|
||||||
const group = duplicateGroups.find((grp) => grp.some((tag) => tag.toLowerCase() === input.toLowerCase()));
|
const lowerInput = input.toLowerCase();
|
||||||
|
const group = duplicateGroups.find((grp) => grp.some((tag) => tag && lowerInput.includes(tag.toLowerCase())));
|
||||||
return group ? group[0] : input;
|
return group ? group[0] : input;
|
||||||
};
|
};
|
||||||
|
|
||||||
const regexPattern = /^[-A-Za-z0-9&_.()]+$/;
|
const regexPattern =
|
||||||
|
label === "tags"
|
||||||
|
? /^[-A-Za-z0-9&_.()]+$/ // only allowed chars for tags
|
||||||
|
: /^.*$/; // allow all characters otherwise
|
||||||
|
|
||||||
const submitTag = (newValue, index = null) => {
|
const submitTag = (newValue, index = null) => {
|
||||||
const trimmed = newValue?.trim();
|
const trimmed = newValue?.trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user