Skip to content

Commit

Permalink
move tagging to the tags column, move meta-structuring to the name co…
Browse files Browse the repository at this point in the history
…lumn
  • Loading branch information
npinsker committed Jan 15, 2025
1 parent 2a84a9b commit e5ff4b9
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 32 deletions.
21 changes: 19 additions & 2 deletions hunts/src/EditPuzzleModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { FormEvent } from "react";
import { Button, Form, Modal } from "react-bootstrap";
import { useDispatch } from "react-redux";
import { updatePuzzle } from "./puzzlesSlice";
import { useDispatch, useSelector } from "react-redux";
import { selectHuntTags } from "./huntSlice";
import { selectPuzzleTags, updatePuzzle } from "./puzzlesSlice";
import { hideModal } from "./modalSlice";
import EditableTagList from "./EditableTagList";

import type { Dispatch } from "./store";
import type { HuntId, PuzzleId } from "./types";
Expand All @@ -29,6 +31,16 @@ function EditPuzzleModal({
const [newIsMeta, setNewIsMeta] = React.useState(isMeta);
const [createChannels, setCreateChannels] = React.useState(hasChannels);
const dispatch = useDispatch<Dispatch>();

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

const onSubmit = (e: FormEvent) => {
e.preventDefault();
dispatch(
Expand Down Expand Up @@ -80,6 +92,11 @@ function EditPuzzleModal({
checked={newIsMeta}
onChange={(e: ChangeEvent) => setNewIsMeta(e.target.checked)}
/>
<h5 style={{ textAlign: "center" }}>Parent Metas</h5>
<EditableTagList
puzzleId={puzzleId}
tags={allTags.filter((tag) => tag.is_meta && tag.name != name)}
/>
<Form.Check
type="checkbox"
label="Create discord channels"
Expand Down
6 changes: 0 additions & 6 deletions hunts/src/EditPuzzleTagsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ function EditPuzzleTagsModal({
<Modal.Title>Edit Tags for {puzzleName}</Modal.Title>
</Modal.Header>
<Modal.Body>
<h5 style={{ textAlign: "center" }}>Metas</h5>
<EditableTagList
puzzleId={puzzleId}
tags={allTags.filter((tag) => tag.is_meta)}
/>
<br />
<h5 style={{ textAlign: "center" }}>Locations</h5>
<EditableTagList
puzzleId={puzzleId}
Expand Down
17 changes: 1 addition & 16 deletions hunts/src/NameCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { Badge, Popover, OverlayTrigger } from "react-bootstrap";
import { useSelector, useDispatch } from "react-redux";
import { faTrashAlt } from "@fortawesome/free-regular-svg-icons";
import { faWrench, faTag } from "@fortawesome/free-solid-svg-icons";
import { faWrench } from "@fortawesome/free-solid-svg-icons";
import { showModal } from "./modalSlice";
import ClickableIcon from "./ClickableIcon";
import { toggleCollapsed } from "./collapsedPuzzlesSlice";
Expand Down Expand Up @@ -172,21 +172,6 @@ export default function NameCell({
)
}
/>{" "}
<ClickableIcon
icon={faTag}
onClick={() =>
dispatch(
showModal({
type: "EDIT_TAGS",
props: {
huntId,
puzzleId: row.values.id,
puzzleName: row.values.name,
},
})
)
}
/>{" "}
<ClickableIcon
icon={faTrashAlt}
onClick={() =>
Expand Down
36 changes: 28 additions & 8 deletions hunts/src/TagCell.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,51 @@
import React from "react";
import { useDispatch, useSelector } from "react-redux";
import { showModal } from "./modalSlice";
import { faTag } from "@fortawesome/free-solid-svg-icons";
import { toggleFilterTag } from "./filterSlice";
import TagPill from "./TagPill";
import ClickableIcon from "./ClickableIcon";

import type { Puzzle, Row } from "./types";
import type { RootState } from "./store";
import type { Hunt, Puzzle, Row } from "./types";

function TagCell({ row }: { row: Row<Puzzle> }) {
const dispatch = useDispatch();
const { id: huntId } = useSelector<RootState, Hunt>((state) => state.hunt);
const puzzleId = row.original.id;

const shouldShowMetaTags =
row.original.tags.filter((t) => t.is_meta).length > 1;
row.original.tags.filter((t) => t.is_meta).length > 1;
const tagsToShow = shouldShowMetaTags
? row.original.tags
: row.original.tags.filter((t) => !t.is_meta);
? row.original.tags
: row.original.tags.filter((t) => !t.is_meta);

return (
<>
{tagsToShow.map(({ name, color, id }) => (
<TagPill
name={name}
color={color}
key={name}
onClick={() => dispatch(toggleFilterTag({ name, color, id }))}
name={name}
color={color}
key={name}
onClick={() => dispatch(toggleFilterTag({ name, color, id }))}
/>
))}{" "}

<ClickableIcon
icon={faTag}
onClick={() =>
dispatch(
showModal({
type: "EDIT_TAGS",
props: {
huntId,
puzzleId: row.values.id,
puzzleName: row.values.name,
},
})
)
}
/>{" "}
</>
);
}
Expand Down

0 comments on commit e5ff4b9

Please sign in to comment.