Skip to content

Commit

Permalink
Use a better example transform
Browse files Browse the repository at this point in the history
  • Loading branch information
glossawy committed Apr 11, 2024
1 parent f07f5ba commit 09187e0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/components/FeedDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FeedTransformContext,
FeedTransformDispatchContext,
RuleWithoutMetadata,
initialFeedData as initialFeedTransform,
exampleTransform as initialFeedTransform,
useStoredFeedTransform,
} from "@app/hooks/feedTransform"
import collections from "@app/utils/collections"
Expand Down
57 changes: 46 additions & 11 deletions src/hooks/feedTransform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext, useContext, useEffect } from "react"

import useLocalStorage from "@app/hooks/localStorage"
import { DefaultFactories, LocalStorageKeys } from "@app/utils/defaults"
import { LocalStorageKeys } from "@app/utils/defaults"
import migrate from "@app/utils/migration"
import { FeedTransform, Rule } from "@app/utils/rules"

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

export const initialFeedData: FeedTransform = {
export const exampleTransform: FeedTransform = {
version: 1,
feed_url: "https://www.rssboard.org/files/sample-rss-2.xml",
rules: [
DefaultFactories.rule(),
DefaultFactories.rule(),
{
rid: "3",
name: "Rule 3",
rid: "3fd34096-3ad8-410f-8080-972c5045b713",
name: "Remove NASA + Space Station Articles",
condition: {
all_of: [
{
args: {
pattern: "NASA",
},
name: "contains",
xpath: "title",
},
{
args: {
pattern: "Space Station",
},
name: "contains",
xpath: "title",
},
],
},
mutations: [
{
args: {},
name: "remove",
},
],
xpath: "//channel/item",
condition: DefaultFactories.condition(),
},
{
rid: "71850834-5d40-4cf8-8e9b-3c598082b19e",
name: "Change NASA to ROSCOM",
condition: {
args: {
pattern: "NASA",
},
name: "contains",
xpath: "title",
},
mutations: [
DefaultFactories.mutation(),
{
name: "changeTag",
args: {
tag: "test",
pattern: "NASA",
replacement: "ROSCOM",
trim: false,
},
name: "replace",
xpath: "title",
},
],
xpath: "//channel/item",
},
],
}

export const FeedTransformContext = createContext<FeedTransform>({
...initialFeedData,
...exampleTransform,
})
export const FeedTransformDispatchContext = createContext<
React.Dispatch<FeedAction>
Expand Down
4 changes: 2 additions & 2 deletions src/utils/migration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initialFeedData } from "@app/hooks/feedTransform"
import { exampleTransform } from "@app/hooks/feedTransform"
import { FeedTransform, Rule } from "@app/utils/rules"

type RuleWithoutMetadata = {
Expand All @@ -19,7 +19,7 @@ export default function migrate(
): FeedTransform {
// Move unversioned feed transforms up to V1
if (!("version" in feedTransform)) {
feedTransform = initialFeedData
feedTransform = exampleTransform
}

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

0 comments on commit 09187e0

Please sign in to comment.