Skip to content

Commit 09187e0

Browse files
committed
Use a better example transform
1 parent f07f5ba commit 09187e0

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

src/components/FeedDataProvider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
FeedTransformContext,
66
FeedTransformDispatchContext,
77
RuleWithoutMetadata,
8-
initialFeedData as initialFeedTransform,
8+
exampleTransform as initialFeedTransform,
99
useStoredFeedTransform,
1010
} from "@app/hooks/feedTransform"
1111
import collections from "@app/utils/collections"

src/hooks/feedTransform.ts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createContext, useContext, useEffect } from "react"
22

33
import useLocalStorage from "@app/hooks/localStorage"
4-
import { DefaultFactories, LocalStorageKeys } from "@app/utils/defaults"
4+
import { LocalStorageKeys } from "@app/utils/defaults"
55
import migrate from "@app/utils/migration"
66
import { FeedTransform, Rule } from "@app/utils/rules"
77

@@ -22,32 +22,67 @@ export type FeedAction =
2222
| { type: "shiftDown"; ruleId: RuleId }
2323
| { type: "clear" }
2424

25-
export const initialFeedData: FeedTransform = {
25+
export const exampleTransform: FeedTransform = {
2626
version: 1,
2727
feed_url: "https://www.rssboard.org/files/sample-rss-2.xml",
2828
rules: [
29-
DefaultFactories.rule(),
30-
DefaultFactories.rule(),
3129
{
32-
rid: "3",
33-
name: "Rule 3",
30+
rid: "3fd34096-3ad8-410f-8080-972c5045b713",
31+
name: "Remove NASA + Space Station Articles",
32+
condition: {
33+
all_of: [
34+
{
35+
args: {
36+
pattern: "NASA",
37+
},
38+
name: "contains",
39+
xpath: "title",
40+
},
41+
{
42+
args: {
43+
pattern: "Space Station",
44+
},
45+
name: "contains",
46+
xpath: "title",
47+
},
48+
],
49+
},
50+
mutations: [
51+
{
52+
args: {},
53+
name: "remove",
54+
},
55+
],
3456
xpath: "//channel/item",
35-
condition: DefaultFactories.condition(),
57+
},
58+
{
59+
rid: "71850834-5d40-4cf8-8e9b-3c598082b19e",
60+
name: "Change NASA to ROSCOM",
61+
condition: {
62+
args: {
63+
pattern: "NASA",
64+
},
65+
name: "contains",
66+
xpath: "title",
67+
},
3668
mutations: [
37-
DefaultFactories.mutation(),
3869
{
39-
name: "changeTag",
4070
args: {
41-
tag: "test",
71+
pattern: "NASA",
72+
replacement: "ROSCOM",
73+
trim: false,
4274
},
75+
name: "replace",
76+
xpath: "title",
4377
},
4478
],
79+
xpath: "//channel/item",
4580
},
4681
],
4782
}
4883

4984
export const FeedTransformContext = createContext<FeedTransform>({
50-
...initialFeedData,
85+
...exampleTransform,
5186
})
5287
export const FeedTransformDispatchContext = createContext<
5388
React.Dispatch<FeedAction>

src/utils/migration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { initialFeedData } from "@app/hooks/feedTransform"
1+
import { exampleTransform } from "@app/hooks/feedTransform"
22
import { FeedTransform, Rule } from "@app/utils/rules"
33

44
type RuleWithoutMetadata = {
@@ -19,7 +19,7 @@ export default function migrate(
1919
): FeedTransform {
2020
// Move unversioned feed transforms up to V1
2121
if (!("version" in feedTransform)) {
22-
feedTransform = initialFeedData
22+
feedTransform = exampleTransform
2323
}
2424

2525
if ("version" in feedTransform && feedTransform["version"] >= 1) {

0 commit comments

Comments
 (0)