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

Function FeedLayoutProvider

packages/shared/src/contexts/FeedContext.tsx:116–201  ·  view source on GitHub ↗
({
  children,
}: PropsWithChildren)

Source from the content-addressed store, hash-verified

114);
115
116export function FeedLayoutProvider({
117 children,
118}: PropsWithChildren): ReactElement {
119 const { sidebarExpanded } = useSettingsContext();
120 const { sidebarRendered } = useSidebarRendered();
121 const { isPlus } = usePlusSubscription();
122 const feedAdTemplateFeature = useConditionalFeature({
123 feature: featureFeedAdTemplate,
124 shouldEvaluate: !isPlus,
125 });
126
127 // Debounce sidebar expanded state to sync with sidebar CSS transition
128 // This prevents the feed layout from jumping mid-animation
129 const [debouncedSidebarExpanded, setDebouncedSidebarExpanded] =
130 useState(sidebarExpanded);
131
132 useEffect(() => {
133 const timer = setTimeout(() => {
134 setDebouncedSidebarExpanded(sidebarExpanded);
135 }, SIDEBAR_TRANSITION_DURATION);
136
137 return () => clearTimeout(timer);
138 }, [sidebarExpanded]);
139
140 const { feedSettings, defaultFeedSettings } = useMemo(() => {
141 const enhancedFeedSettings = Object.entries(baseFeedSettings).reduce(
142 (acc, [feedSettingsKey, feedSettingsValue]) => {
143 acc[feedSettingsKey] = {
144 ...feedSettingsValue,
145 adTemplate:
146 feedAdTemplateFeature.value[feedSettingsKey] ||
147 feedAdTemplateFeature.value.default,
148 };
149
150 return acc;
151 },
152 {},
153 ) as typeof baseFeedSettings;
154
155 return {
156 feedSettings: [
157 enhancedFeedSettings.desktop,
158 enhancedFeedSettings.laptopXL,
159 enhancedFeedSettings.laptopL,
160 enhancedFeedSettings.laptop,
161 enhancedFeedSettings.tablet,
162 ],
163 defaultFeedSettings: enhancedFeedSettings.default,
164 };
165 }, [feedAdTemplateFeature.value]);
166
167 // Generate the breakpoints for the feed settings
168 // Uses debounced sidebar state to sync layout change with sidebar animation
169 const feedBreakpoints = useMemo(() => {
170 const breakpoints = feedSettings.map((setting) =>
171 setting.breakpoint.replace('@media ', ''),
172 );
173

Callers

nothing calls this directly

Calls 7

useSettingsContextFunction · 0.90
usePlusSubscriptionFunction · 0.90
useConditionalFeatureFunction · 0.90
useMediaFunction · 0.90
useSidebarRenderedFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected