Skip to content

Commit

Permalink
Edit meaning box to have a bookmark button
Browse files Browse the repository at this point in the history
  • Loading branch information
hockyy committed Jul 24, 2024
1 parent d2f3985 commit 522af02
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"pinyin-pro": "^3.23.1",
"react-awesome-button": "6.1.0",
"react-colorful": "^5.6.1",
"react-icons": "^5.2.1",
"react-smooth-collapse": "^2.1.2",
"react-svg": "^16.1.34",
"react-video-seek-slider": "^6.0.6",
Expand Down
46 changes: 43 additions & 3 deletions renderer/components/Meaning/MeaningBox.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import React, {useCallback, useEffect, useMemo, useState} from "react";
import {ipcRenderer, shell} from "electron";
import {HanziSentence, KanjiSentence} from "../Subtitle/Sentence";
import {defaultMeaningBoxStyling} from "../../utils/CJKStyling";
import {defaultLearningColorStyling, defaultMeaningBoxStyling} from "../../utils/CJKStyling";
import {joinString} from "../../utils/utils";
import {AwesomeButton} from "react-awesome-button";
import {isKanji, toHiragana} from 'wanakana'
import KanjiVGDisplay from "./KanjiVGDisplay";
import WanikaniRadicalDisplay from "./WanikaniRadicalDisplay";
import {videoConstants} from "../../utils/constants";
import MakeMeAHanziDisplay from "./MakeMeAHanziDisplay";
import {FaStar} from 'react-icons/fa';

const OutlinedStar = ({color, size, outlineColor = 'black', outlineWidth = 1}) => {
const id = `star-outline-${color.replace('#', '')}`;

return (
<svg width={size} height={size}>
<defs>
<filter id={id}>
<feMorphology in="SourceAlpha" result="expanded" operator="dilate"
radius={outlineWidth}/>
<feFlood floodColor={outlineColor}/>
<feComposite in2="expanded" operator="in"/>
<feComposite in="SourceGraphic"/>
</filter>
</defs>
<g filter={`url(#${id})`}>
<FaStar color={color} size={size}/>
</g>
</svg>
);
};


const initialContentState = {
id: "",
Expand All @@ -17,21 +40,28 @@ const initialContentState = {
};
const initialCharacterContentState = {literal: null};

const getStarColor = (learningState) => {
return defaultLearningColorStyling.learningColor[learningState].color;
};
const MeaningBox = ({
meaning,
setMeaning,
tokenizeMiteiru,
subtitleStyling = defaultMeaningBoxStyling,
customComponent = null,
lang
lang,
changeLearningState = null,
getLearningState = null
}) => {
const [meaningContent, setMeaningContent] = useState(initialContentState);
const [meaningCharacter, setMeaningCharacter] = useState(initialCharacterContentState);
const [otherMeanings, setOtherMeanings] = useState([]);
const [meaningIndex, setMeaningIndex] = useState(0);
const [tags, setTags] = useState({});
const [romajiedData, setRomajiedData] = useState([]);

const handleStarClick = useCallback(() => {
changeLearningState(meaning);
}, [changeLearningState, meaning]);
useEffect(() => {
if (meaning === '') {
setMeaningContent(initialContentState);
Expand Down Expand Up @@ -140,6 +170,16 @@ const MeaningBox = ({
setMeaning={setMeaning}
subtitleStyling={subtitleStyling}/>
))}
{getLearningState && changeLearningState &&
<button onClick={handleStarClick} className="ml-4">
<OutlinedStar
color={getStarColor(getLearningState(meaning))}
size={24}
outlineColor="black"
outlineWidth={1}
/>
</button>
}
</div>
<AwesomeButton type="primary" disabled={meaningIndex === otherMeanings.length - 1}
onPress={handleNext}>
Expand Down
1 change: 1 addition & 0 deletions renderer/pages/learn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'react-awesome-button/dist/styles.css';
import {videoConstants} from "../utils/constants";
import useLearningState from "../hooks/useLearningState";
import useTranslationLinks from "../hooks/useTranslationLinks";
import 'react-awesome-button/dist/styles.css';

function Learn() {

Expand Down
7 changes: 4 additions & 3 deletions renderer/pages/video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function Video() {
const {
showVocabSidebar,
setShowVocabSidebar,
toggleVocabSidebar
} = useVocabSidebar();

const {
Expand Down Expand Up @@ -89,7 +88,8 @@ function Video() {
changeLearningState,
setFrequencyPrimary,
learningPercentage,
setLearningPercentage
setLearningPercentage,
getLearningState,
} = useLearningState(lang);
const {
meaning,
Expand Down Expand Up @@ -147,7 +147,8 @@ function Video() {
<div>
<Toast info={toastInfo}/>
<MeaningBox meaning={meaning} setMeaning={setMeaning} tokenizeMiteiru={tokenizeMiteiru}
lang={lang}/>
lang={lang} changeLearningState={changeLearningState}
getLearningState={getLearningState}/>
<VideoJS options={{
techOrder: ["html5", "youtube"],
sources: [videoSrc],
Expand Down

0 comments on commit 522af02

Please sign in to comment.