Skip to content

Commit

Permalink
add config / constant file for names
Browse files Browse the repository at this point in the history
Signed-off-by: GRBurst <[email protected]>
  • Loading branch information
GRBurst committed May 24, 2024
1 parent 0c7d0b6 commit 8985e08
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/CustomFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { SearchProps } from "antd/es/input/Search"

import { TagFilter, TagFilterSimple } from "../models/TagFilter"
import { replaceTagCaptureGroup } from '../utils/hn'
import { AppConfig } from '../utils/config'

interface CustomTagFilterProps {
onTagAdd: (key: string, tag: TagFilter) => void
Expand All @@ -18,7 +19,7 @@ const CustomTagFilter = ({ onTagAdd }: CustomTagFilterProps) => {
if (tagName !== undefined && tagName != "") {
const newFlags = (tagPatternFlags !== undefined && tagPatternFlags != "") ? tagPattern : "gmi"
const newTag = (tagPattern !== undefined && tagPattern != "") ? TagFilter({ name: tagName, pattern: RegExp(tagPattern, newFlags) }) : TagFilterSimple(tagName)
onTagAdd("Custom", replaceTagCaptureGroup(newTag))
onTagAdd(AppConfig.tagFilters.custom.sectionName, replaceTagCaptureGroup(newTag))
setTagName("")
setTagPattern("")
}
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/FilterableJobList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Item } from "../models/Item";
import { TagFilter, TagFilters, tagFilterToString } from "../models/TagFilter";
import { filterByRegexAny, flatFilters, itemFilter } from "../utils/hn";
import { TagFilterBar } from "./TagFilterBar";
import { AppConfig } from "../utils/config";

const getHighlightedText = (
text: string | undefined,
Expand Down Expand Up @@ -183,13 +184,11 @@ const FilterableJobList = ({
}
onTagAdd={(key: string, tag: TagFilter) => {
addFilters(key, tag, allTagFilters, setAllTagFilters)
//TODO: put name at central place
localStorage.setItem(
"CustomFilters",
JSON.stringify(Array.from(allTagFilters.get("Custom") ?? []).map(f => tagFilterToString(f)))
AppConfig.tagFilters.custom.localStorageKey,
JSON.stringify(Array.from(allTagFilters.get(AppConfig.tagFilters.custom.sectionName) ?? []).map(f => tagFilterToString(f)))
)
}
}
}}
onSearch={(needle: string | undefined) => setSearchFilter(needle)}
/>
<ItemList
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/components/HnJobs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { GithubIcon } from "./Icons";
import { TagFilter, tagFilterFromString } from "../models/TagFilter";

import { locations, technologies, misc } from "../utils/predefined";
import { AppConfig } from "../utils/config";

const FilterableLocalList = lazy(() => import("./FilterableLocalList"));
const FilterableSqliteList = lazy(() => import("./FilterableSqliteList"));
Expand Down Expand Up @@ -60,11 +61,11 @@ const HnJobs = () => {
});

// Add custom filters from local storage
const customFilters = localStorage.getItem("CustomFilters")
const customFilters = localStorage.getItem(AppConfig.tagFilters.custom.localStorageKey)
if (customFilters) {
const restoredFilters = JSON.parse(customFilters).map((f: string) => tagFilterFromString(f))
console.log("Restoring custom filters: ", restoredFilters)
predefinedFilterTags.set("Custom", HSet.fromIterable(restoredFilters));
predefinedFilterTags.set(AppConfig.tagFilters.custom.sectionName, HSet.fromIterable(restoredFilters));
}

}, []);
Expand Down
15 changes: 8 additions & 7 deletions frontend/src/components/TagFilterBar.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { CSSProperties, Fragment, ReactNode } from 'react'
import { Collapse, Flex, Button } from "antd"
import { CSSProperties, Fragment, ReactNode } from 'react';
import { Collapse, Flex, Button } from "antd";
import type { CollapseProps } from 'antd';


import { CustomFilters } from './CustomFilters'
import { HashSet as HSet } from "effect"
import { TagFilter as TagF, TagFilters } from "../models/TagFilter"
import { CustomFilters } from './CustomFilters';
import { HashSet as HSet } from "effect";
import { TagFilter as TagF, TagFilters } from "../models/TagFilter";
import { AppConfig } from '../utils/config';

interface TagProps {
tagFilter: TagF
Expand Down Expand Up @@ -75,8 +76,8 @@ function TagFilterBar({ allTags, activeTags, onActive, onInactive, onTagAdd, onS

const collapsableCustomFilter: CollapseProps['items'] = [
{
key: "custom",
label: <h3 className="filter">Custom Filters</h3>,
key: AppConfig.tagFilters.custom.sectionName,
label: <h3 className="filter">{AppConfig.tagFilters.custom.name}</h3>,
children: <CustomFilters onTagAdd={onTagAdd} onSearch={onSearch} />,
style: panelStyle
}
Expand Down

0 comments on commit 8985e08

Please sign in to comment.