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

Add puzzle tag selector and merge puzzle + hunt tags. #755

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 10 additions & 2 deletions hunts/src/EditPuzzleTagsModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ import { useDispatch, useSelector } from "react-redux";
import Modal from "react-bootstrap/Modal";
import Button from "react-bootstrap/Button";
import Form from "react-bootstrap/Form";
import { addPuzzleTag } from "./puzzlesSlice";
import { addPuzzleTag, selectPuzzleTags } from "./puzzlesSlice";
import { selectHuntTags } from "./huntSlice";
import { DEFAULT_TAG_COLOR, SELECTABLE_TAG_COLORS } from "./constants";
import { hideModal } from "./modalSlice";
import TagPill from "./TagPill";
import EditableTagList from "./EditableTagList";

function EditPuzzleTagsModal({ puzzleId, puzzleName }) {
const allTags = useSelector(selectHuntTags);
const huntTags = useSelector(selectHuntTags);
const puzzleTags = useSelector(selectPuzzleTags);
// Use a map to concat huntTags and puzzleTags and then dedupe.
const tagMap = new Map();
for (const tag of huntTags.concat(puzzleTags)) {
tagMap.set(tag.name, tag);
}
const allTags = Array.from(tagMap.values());

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can dedupe by id instead of name (though since atm tags can't be renamed it's all the same, but I think id is still better)

const [newTagName, setNewTagName] = React.useState("");
const [newTagColor, setNewTagColor] = React.useState(DEFAULT_TAG_COLOR);
const dispatch = useDispatch();
Expand Down
14 changes: 14 additions & 0 deletions hunts/src/puzzlesSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,20 @@ export const selectNumMetasUnsolved = createSelector(
}
);

export const selectPuzzleTags = createSelector(
[puzzlesSelectors.selectAll],
(puzzles) => {
// Use a map to dedupe puzzle tags by name.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

const tagMap = new Map();
for (const puzzle of puzzles) {
for (const tag of puzzle.tags) {
tagMap.set(tag.name, tag);
}
}
return Array.from(tagMap.values());
}
);

export const { selectById: selectPuzzleById } = puzzlesSelectors;
export const { reducers } = puzzlesSlice.actions;

Expand Down
Loading