-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from FSou1/feat/options-rework
feat(options): user-defined keywords and styles
- Loading branch information
Showing
30 changed files
with
698 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,35 @@ | ||
import { useEffect, useState } from "react"; | ||
import { get } from "@services/storage/storageService"; | ||
import { | ||
SETTINGS_KEYWORDS, | ||
OBSERVABLE_DEBOUNCE_TIME_MS, | ||
} from "@services/constants"; | ||
import { OBSERVABLE_DEBOUNCE_TIME_MS } from "@services/constants"; | ||
import { getRules } from "@src/services/storage/optionsService"; | ||
import { IKeywordRule } from "@src/pages/options/components/KeywordRule"; | ||
import Highlighter from "./Highlighter"; | ||
|
||
export default function App() { | ||
const [keywords, setKeywords] = useState(""); | ||
const [rules, setRules] = useState([]); | ||
|
||
const map = (rule: IKeywordRule) => { | ||
return { | ||
className: rule.id, | ||
keywords: rule.keywords, | ||
styles: rule.cssStyles, | ||
}; | ||
}; | ||
|
||
useEffect(() => { | ||
get(SETTINGS_KEYWORDS).then((result) => { | ||
const keywords = result?.[SETTINGS_KEYWORDS] || null; | ||
if (keywords) { | ||
setKeywords(keywords); | ||
} | ||
getRules().then((rules) => { | ||
setRules(rules.map(map)); | ||
}); | ||
}, []); | ||
|
||
if (!keywords) { | ||
return; | ||
} | ||
|
||
return ( | ||
<Highlighter | ||
keywords={keywords} | ||
debounceTimeMs={OBSERVABLE_DEBOUNCE_TIME_MS} | ||
/> | ||
<> | ||
{rules.map((rule) => ( | ||
<Highlighter | ||
keywords={rule.keywords} | ||
highlightedClassName={rule.className} | ||
debounceTimeMs={OBSERVABLE_DEBOUNCE_TIME_MS} | ||
/> | ||
))} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.