MCPcopy Create free account
hub / github.com/dailydotdev/apps / applyChange

Function applyChange

packages/shared/src/features/feedExplain/useFeedControls.ts:79–127  ·  view source on GitHub ↗
(
  controls: FeedControls,
  change: FeedControlChange,
)

Source from the content-addressed store, hash-verified

77};
78
79const applyChange = (
80 controls: FeedControls,
81 change: FeedControlChange,
82): FeedControls => {
83 switch (change.kind) {
84 case ChangeKind.Topic: {
85 const topics = controls.topics.filter(
86 ({ keyword }) => keyword !== change.keyword,
87 );
88 const stored = toStored(change, FeedTopicMode.Off);
89 return {
90 ...controls,
91 topics: stored
92 ? [...topics, { keyword: change.keyword, ...stored }]
93 : topics,
94 };
95 }
96 case ChangeKind.Source: {
97 const sources = controls.sources.filter(
98 ({ source }) => source.id !== change.sourceId,
99 );
100 const source = controls.sources.find(
101 (item) => item.source.id === change.sourceId,
102 )?.source ?? { id: change.sourceId };
103 const stored = toStored(change);
104 return {
105 ...controls,
106 sources: stored ? [...sources, { source, ...stored }] : sources,
107 };
108 }
109 case ChangeKind.Author: {
110 const authors = controls.authors.filter(
111 ({ user }) => user.id !== change.userId,
112 );
113 const user = controls.authors.find(
114 (item) => item.user.id === change.userId,
115 )?.user ?? { id: change.userId };
116 const stored = toStored(change);
117 return {
118 ...controls,
119 authors: stored ? [...authors, { user, ...stored }] : authors,
120 };
121 }
122 case ChangeKind.Learning:
123 return { ...controls, learning: change.enabled };
124 default:
125 return { ...controls, fillIns: change.enabled };
126 }
127};
128
129const sendChange = (change: FeedControlChange): Promise<unknown> => {
130 switch (change.kind) {

Callers 1

useFeedControlsFunction · 0.85

Calls 1

toStoredFunction · 0.85

Tested by

no test coverage detected