Skip to content

Commit

Permalink
Optional text field to add deck description
Browse files Browse the repository at this point in the history
  • Loading branch information
h16nning committed Feb 6, 2024
1 parent 5137d0f commit 86d9f5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/components/deck/DeckView.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from "react";
import { ActionIcon, Button, Group, Stack, Title } from "@mantine/core";
import { ActionIcon, Button, Group, Stack, Title, Text } from "@mantine/core";
import SubDeckSection from "./SubDeckSection";
import { IconChevronLeft, IconPlus } from "@tabler/icons-react";
import DeckMenu from "./DeckMenu";
Expand Down Expand Up @@ -77,7 +77,11 @@ function DeckView() {
</Group>

{deck && deck.description && (
<div dangerouslySetInnerHTML={{ __html: deck.description }} />
<Text
fz="sm"
c="dimmed"
dangerouslySetInnerHTML={{ __html: deck.description }}

Check warning on line 83 in src/components/deck/DeckView.tsx

View workflow job for this annotation

GitHub Actions / lint

Avoid passing content using the dangerouslySetInnerHTML prop.
></Text>
)}
<Stack gap="xs" align="end">
<Button
Expand Down
11 changes: 10 additions & 1 deletion src/components/deck/NewDeckModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ function NewDeckModal({ opened, setOpened, superDeck }: NewDeckModalProps) {
const navigate = useNavigate();

const [nameValue, setNameValue] = useState<string>("");
const [descriptionValue, setDescriptionValue] = useState<string>("");
const [addingDeck, setAddingDeck] = useState<boolean>(false);
const [status, setStatus] = useState<string | null>(null);

async function tryAddDeck() {
setAddingDeck(true);
try {
const id = await newDeck(nameValue, superDeck);
const id = await newDeck(nameValue, superDeck, descriptionValue);
setNameValue("");
setOpened(false);
navigate("/deck/" + id);
Expand All @@ -27,6 +28,7 @@ function NewDeckModal({ opened, setOpened, superDeck }: NewDeckModalProps) {
}
setAddingDeck(false);
setNameValue("");
setDescriptionValue("");
}

return (
Expand All @@ -44,6 +46,13 @@ function NewDeckModal({ opened, setOpened, superDeck }: NewDeckModalProps) {
value={nameValue}
onChange={(e) => setNameValue(e.currentTarget.value)}
/>
<TextInput
placeholder="Optional"
data-autofocus
label="Description"
value={descriptionValue}
onChange={(e) => setDescriptionValue(e.currentTarget.value)}
/>
{status ? <Text>{status}</Text> : <></>}
<Group justify="flex-end">
<Button
Expand Down
3 changes: 1 addition & 2 deletions src/logic/CardTypeImplementations/ClozeCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ function ClozeCardComponent({
`<span class="cloze-field"/>`
);
}
//Use replacer function to strip all cloze tags from {{cn::Text}} to Text regardless of occlusion number using replacer function
finalText = finalText.replace(/\{\{c\d::((?!\{\{|}}).)*\}\}/g, (match) =>
match.slice(6, -2)
);
return (
<Text
dangerouslySetInnerHTML={{ __html: finalText }}

Check warning on line 81 in src/logic/CardTypeImplementations/ClozeCard.tsx

View workflow job for this annotation

GitHub Actions / lint

Avoid passing content using the dangerouslySetInnerHTML prop.
className={classes.clozeCard}
></Text>
/>
);
}

Expand Down

0 comments on commit 86d9f5e

Please sign in to comment.