-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add keyword block * Only block on community/home/all feeds * Add test suite
- Loading branch information
Showing
11 changed files
with
229 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { | ||
IonItemOption, | ||
IonItemOptions, | ||
IonItemSliding, | ||
IonLabel, | ||
IonList, | ||
useIonAlert, | ||
} from "@ionic/react"; | ||
import { InsetIonItem } from "../../../pages/profile/ProfileFeedItemsPage"; | ||
import { useAppDispatch, useAppSelector } from "../../../store"; | ||
import { ListHeader } from "../shared/formatting"; | ||
import { updateFilteredKeywords } from "../settingsSlice"; | ||
import { uniq, without } from "lodash"; | ||
|
||
export default function FilteredKeywords() { | ||
const [presentAlert] = useIonAlert(); | ||
const dispatch = useAppDispatch(); | ||
const filteredKeywords = useAppSelector( | ||
(state) => state.settings.blocks.keywords, | ||
); | ||
|
||
async function remove(keyword: string) { | ||
dispatch(updateFilteredKeywords(without(filteredKeywords, keyword))); | ||
} | ||
|
||
async function add() { | ||
presentAlert({ | ||
message: "Add Filtered Keyword", | ||
buttons: [ | ||
{ | ||
text: "OK", | ||
handler: ({ keyword }) => { | ||
if (!keyword.trim()) return; | ||
|
||
dispatch( | ||
updateFilteredKeywords( | ||
uniq([...filteredKeywords, keyword.trim()]), | ||
), | ||
); | ||
}, | ||
}, | ||
"Cancel", | ||
], | ||
inputs: [ | ||
{ | ||
placeholder: "Keyword", | ||
name: "keyword", | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<ListHeader> | ||
<IonLabel>Filtered Keywords</IonLabel> | ||
</ListHeader> | ||
<IonList inset> | ||
{filteredKeywords.map((keyword) => ( | ||
<IonItemSliding key={keyword}> | ||
<IonItemOptions side="end" onIonSwipe={() => remove(keyword)}> | ||
<IonItemOption | ||
color="danger" | ||
expandable | ||
onClick={() => remove(keyword)} | ||
> | ||
Unfilter | ||
</IonItemOption> | ||
</IonItemOptions> | ||
<InsetIonItem> | ||
<IonLabel>{keyword}</IonLabel> | ||
</InsetIonItem> | ||
</IonItemSliding> | ||
))} | ||
|
||
<InsetIonItem onClick={add}> | ||
<IonLabel color="primary">Add Keyword</IonLabel> | ||
</InsetIonItem> | ||
</IonList> | ||
</> | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { keywordFoundInSentence } from "./lemmy"; | ||
|
||
describe("keywordFoundInSentence", () => { | ||
it("false when empty", () => { | ||
expect(keywordFoundInSentence("", "")).toBe(false); | ||
}); | ||
|
||
it("false with keyword in empty string", () => { | ||
expect(keywordFoundInSentence("keyword", "")).toBe(false); | ||
}); | ||
|
||
it("false with keyword in sentence", () => { | ||
expect(keywordFoundInSentence("keyword", "Hello, this is Voyager!")).toBe( | ||
false, | ||
); | ||
}); | ||
|
||
it("true with keyword in middle", () => { | ||
expect(keywordFoundInSentence("this", "Hello, this is Voyager!")).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it("false with partial keyword in middle", () => { | ||
expect(keywordFoundInSentence("thi", "Hello, this is Voyager!")).toBe( | ||
false, | ||
); | ||
}); | ||
|
||
it("true with multi word keyword", () => { | ||
expect(keywordFoundInSentence("this is", "Hello, this is Voyager!")).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it("true with keyword without comma", () => { | ||
expect(keywordFoundInSentence("Hello", "Hello, this is Voyager!")).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it("true with multi keyword with comma", () => { | ||
expect( | ||
keywordFoundInSentence("Hello, this", "Hello, this is Voyager!"), | ||
).toBe(true); | ||
}); | ||
|
||
it("true at beginning", () => { | ||
expect(keywordFoundInSentence("Hello", "Hello, this is Voyager!")).toBe( | ||
true, | ||
); | ||
}); | ||
|
||
it("true case insensitive", () => { | ||
expect(keywordFoundInSentence("voyageR", "Hello, this is Voyager!")).toBe( | ||
true, | ||
); | ||
}); | ||
}); |
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
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