napp-wallet-post-feed-test 1.0.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +157 -0
- package/dist/0ae4e6254fc19607c79e.woff2 +0 -0
- package/dist/1f38a564cd9eae27ebc3.woff2 +0 -0
- package/dist/432.napp.bundle.js +1 -0
- package/dist/661bd6b7245d5205d3e1.woff2 +0 -0
- package/dist/Post.browser.js +24 -0
- package/dist/Post.js +606 -0
- package/dist/components/CodeSplitting.js +88 -0
- package/dist/components/Deeplink/Deeplink.js +813 -0
- package/dist/components/EditPostModal.js +916 -0
- package/dist/components/ErrorBoundary.js +74 -0
- package/dist/components/ExpandedTest/ExpandableText.js +38 -0
- package/dist/components/FilterDropdown.js +71 -0
- package/dist/components/ImagePreloader.js +1194 -0
- package/dist/components/Loader.js +42 -0
- package/dist/components/LoadingSkeletons.js +978 -0
- package/dist/components/MediaRenderer.js +759 -0
- package/dist/components/MemoryManager.js +302 -0
- package/dist/components/PostCard.js +446 -0
- package/dist/components/PostViews.js +247 -0
- package/dist/components/Postfeed.js +251 -0
- package/dist/components/Svgloader.js +231 -0
- package/dist/components/UploadPostModal.js +1352 -0
- package/dist/components/VideoPlayer.js +1304 -0
- package/dist/components/ViewPostModal/MediaPreloadManager.js +379 -0
- package/dist/components/ViewPostModal/README.md +164 -0
- package/dist/components/ViewPostModal/ShareModal.js +96 -0
- package/dist/components/ViewPostModal/VirtualPost.js +248 -0
- package/dist/components/ViewPostModal/useBodyScrollLock.js +42 -0
- package/dist/components/ViewPostModal/useDeviceDetection.js +38 -0
- package/dist/components/ViewPostModal/useFullscreenManager.js +43 -0
- package/dist/components/ViewPostModal/useNavigationManager.js +185 -0
- package/dist/components/ViewPostModal/usePostDataManager.js +143 -0
- package/dist/components/ViewPostModal/usePreloadManager.js +97 -0
- package/dist/components/ViewPostModal/useShareManager.js +76 -0
- package/dist/components/ViewPostModal.js +552 -0
- package/dist/components/VirtualPostFeed.js +475 -0
- package/dist/components/hooks/useFeedVisibility.js +72 -0
- package/dist/components/hooks/useIntersectionObserver.js +54 -0
- package/dist/components/hooks/usePerformanceMonitor.js +159 -0
- package/dist/components/hooks/usePostApi.js +381 -0
- package/dist/components/hooks/usePostState.js +116 -0
- package/dist/components/useImagePreloading.js +231 -0
- package/dist/e7461d69dbbff1310a5c.woff2 +0 -0
- package/dist/helper/Helper.js +504 -0
- package/dist/index.browser.js +5 -0
- package/dist/index.js +3 -0
- package/dist/napp.bundle.js +2 -0
- package/dist/napp.bundle.js.LICENSE.txt +733 -0
- package/dist/style/post.css +5751 -0
- package/dist/style/post.css.map +1 -0
- package/dist/style/post.purged.css +3236 -0
- package/dist/style/post.scss +5910 -0
- package/dist/utils/bootstrap.js +4 -0
- package/dist/utils/ffmpegLoader.js +40 -0
- package/package.json +70 -0
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// useImagePreloading.jsx - React hook for managing image preloading
|
|
2
|
+
import useEffect from "react";
|
|
3
|
+
import useRef from "react";
|
|
4
|
+
import useCallback from "react";
|
|
5
|
+
import useMemo from "react";
|
|
6
|
+
import imagePreloader from "./ImagePreloader";
|
|
7
|
+
|
|
8
|
+
// Hook for preloading images based on intersection observer
|
|
9
|
+
export var useImagePreloading = function useImagePreloading(posts) {
|
|
10
|
+
var enabled = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
11
|
+
var preloadedPosts = useRef(new Set());
|
|
12
|
+
var lastPostsRef = useRef(null);
|
|
13
|
+
|
|
14
|
+
// Memoize posts to prevent unnecessary re-renders
|
|
15
|
+
var memoizedPosts = useMemo(function () {
|
|
16
|
+
return posts;
|
|
17
|
+
}, [posts]);
|
|
18
|
+
|
|
19
|
+
// Memoize the preloading function to prevent recreation on every render
|
|
20
|
+
var preloadImages = useCallback(function (newPosts) {
|
|
21
|
+
if (!newPosts || newPosts.length === 0) return;
|
|
22
|
+
|
|
23
|
+
// Mark posts as being preloaded
|
|
24
|
+
newPosts.forEach(function (post) {
|
|
25
|
+
if (post !== null && post !== void 0 && post.rsmguid) {
|
|
26
|
+
preloadedPosts.current.add(post.rsmguid);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// Preload images for new posts
|
|
31
|
+
imagePreloader.preloadPostImages(newPosts, 0, Math.min(newPosts.length, 10),
|
|
32
|
+
// Limit to 10 posts at a time
|
|
33
|
+
imagePreloader.priorities.HIGH);
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
// Memoize the filtering logic
|
|
37
|
+
var getNewPosts = useCallback(function (currentPosts) {
|
|
38
|
+
if (!currentPosts || currentPosts.length === 0) return [];
|
|
39
|
+
return currentPosts.filter(function (post) {
|
|
40
|
+
return post && post.rsmguid && !preloadedPosts.current.has(post.rsmguid);
|
|
41
|
+
});
|
|
42
|
+
}, []);
|
|
43
|
+
useEffect(function () {
|
|
44
|
+
if (!enabled || !memoizedPosts || memoizedPosts.length === 0) return;
|
|
45
|
+
|
|
46
|
+
// Check if posts have actually changed to prevent unnecessary processing
|
|
47
|
+
var postsChanged = lastPostsRef.current !== memoizedPosts;
|
|
48
|
+
if (!postsChanged) return;
|
|
49
|
+
lastPostsRef.current = memoizedPosts;
|
|
50
|
+
|
|
51
|
+
// Only preload posts that haven't been preloaded yet
|
|
52
|
+
var newPosts = getNewPosts(memoizedPosts);
|
|
53
|
+
if (newPosts.length > 0) {
|
|
54
|
+
preloadImages(newPosts);
|
|
55
|
+
}
|
|
56
|
+
}, [enabled, memoizedPosts, preloadImages, getNewPosts]);
|
|
57
|
+
|
|
58
|
+
// Cleanup function
|
|
59
|
+
useEffect(function () {
|
|
60
|
+
return function () {
|
|
61
|
+
// Clear preloaded posts set when component unmounts
|
|
62
|
+
preloadedPosts.current.clear();
|
|
63
|
+
lastPostsRef.current = null;
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
// Return utility functions for external use
|
|
68
|
+
return {
|
|
69
|
+
isPostPreloaded: useCallback(function (postId) {
|
|
70
|
+
return preloadedPosts.current.has(postId);
|
|
71
|
+
}, []),
|
|
72
|
+
getPreloadedCount: useCallback(function () {
|
|
73
|
+
return preloadedPosts.current.size;
|
|
74
|
+
}, []),
|
|
75
|
+
clearPreloadedPosts: useCallback(function () {
|
|
76
|
+
preloadedPosts.current.clear();
|
|
77
|
+
}, [])
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Hook for preloading visible viewport images
|
|
82
|
+
export var useViewportImagePreloading = function useViewportImagePreloading(containerRef, posts, visibleRange) {
|
|
83
|
+
var lastPreloadedRange = useRef({
|
|
84
|
+
start: -1,
|
|
85
|
+
end: -1
|
|
86
|
+
});
|
|
87
|
+
var lastPostsRef = useRef(null);
|
|
88
|
+
|
|
89
|
+
// Memoize posts and visible range
|
|
90
|
+
var memoizedPosts = useMemo(function () {
|
|
91
|
+
return posts;
|
|
92
|
+
}, [posts]);
|
|
93
|
+
var memoizedVisibleRange = useMemo(function () {
|
|
94
|
+
return visibleRange;
|
|
95
|
+
}, [visibleRange]);
|
|
96
|
+
|
|
97
|
+
// Memoize the viewport preloading function
|
|
98
|
+
var preloadViewportImages = useCallback(function (currentPosts, range) {
|
|
99
|
+
if (!currentPosts || currentPosts.length === 0 || !range) return;
|
|
100
|
+
var start = range.start,
|
|
101
|
+
end = range.end;
|
|
102
|
+
var _lastPreloadedRange$c = lastPreloadedRange.current,
|
|
103
|
+
lastStart = _lastPreloadedRange$c.start,
|
|
104
|
+
lastEnd = _lastPreloadedRange$c.end;
|
|
105
|
+
|
|
106
|
+
// Only preload if range has significantly changed
|
|
107
|
+
if (Math.abs(start - lastStart) > 2 || Math.abs(end - lastEnd) > 2) {
|
|
108
|
+
// Preload current viewport plus buffer
|
|
109
|
+
var bufferSize = 3;
|
|
110
|
+
var preloadStart = Math.max(0, start - bufferSize);
|
|
111
|
+
var preloadEnd = Math.min(currentPosts.length, end + bufferSize);
|
|
112
|
+
imagePreloader.preloadPostImages(currentPosts, preloadStart, preloadEnd - preloadStart, imagePreloader.priorities.HIGH);
|
|
113
|
+
lastPreloadedRange.current = {
|
|
114
|
+
start: start,
|
|
115
|
+
end: end
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}, []);
|
|
119
|
+
useEffect(function () {
|
|
120
|
+
if (!memoizedPosts || memoizedPosts.length === 0 || !memoizedVisibleRange) return;
|
|
121
|
+
|
|
122
|
+
// Check if data has actually changed
|
|
123
|
+
var dataChanged = lastPostsRef.current !== memoizedPosts;
|
|
124
|
+
if (!dataChanged) return;
|
|
125
|
+
lastPostsRef.current = memoizedPosts;
|
|
126
|
+
preloadViewportImages(memoizedPosts, memoizedVisibleRange);
|
|
127
|
+
}, [memoizedPosts, memoizedVisibleRange, preloadViewportImages]);
|
|
128
|
+
|
|
129
|
+
// Cleanup
|
|
130
|
+
useEffect(function () {
|
|
131
|
+
return function () {
|
|
132
|
+
lastPostsRef.current = null;
|
|
133
|
+
lastPreloadedRange.current = {
|
|
134
|
+
start: -1,
|
|
135
|
+
end: -1
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
}, []);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// Hook for managing image cache and cleanup
|
|
142
|
+
export var useImageCacheManagement = function useImageCacheManagement() {
|
|
143
|
+
var maxCacheSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 500;
|
|
144
|
+
var intervalRef = useRef(null);
|
|
145
|
+
|
|
146
|
+
// Memoize the cache management function
|
|
147
|
+
var manageCache = useCallback(function () {
|
|
148
|
+
var stats = imagePreloader.getStats();
|
|
149
|
+
|
|
150
|
+
// Clear cache if it gets too large
|
|
151
|
+
if (stats.cacheSize > maxCacheSize) {
|
|
152
|
+
imagePreloader.clearCache();
|
|
153
|
+
}
|
|
154
|
+
}, [maxCacheSize]);
|
|
155
|
+
useEffect(function () {
|
|
156
|
+
// Clear any existing interval
|
|
157
|
+
if (intervalRef.current) {
|
|
158
|
+
clearInterval(intervalRef.current);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Set up new interval
|
|
162
|
+
intervalRef.current = setInterval(manageCache, 30000); // Check every 30 seconds
|
|
163
|
+
|
|
164
|
+
return function () {
|
|
165
|
+
if (intervalRef.current) {
|
|
166
|
+
clearInterval(intervalRef.current);
|
|
167
|
+
intervalRef.current = null;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}, [manageCache]);
|
|
171
|
+
|
|
172
|
+
// Return cache stats for debugging
|
|
173
|
+
return useMemo(function () {
|
|
174
|
+
return {
|
|
175
|
+
getCacheStats: function getCacheStats() {
|
|
176
|
+
return imagePreloader.getStats();
|
|
177
|
+
},
|
|
178
|
+
clearCache: function clearCache() {
|
|
179
|
+
return imagePreloader.clearCache();
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}, []);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// Hook for prefetching critical images on app load
|
|
186
|
+
export var useCriticalImagePrefetch = function useCriticalImagePrefetch(criticalImageUrls) {
|
|
187
|
+
var lastUrlsRef = useRef(null);
|
|
188
|
+
|
|
189
|
+
// Memoize the critical image URLs
|
|
190
|
+
var memoizedUrls = useMemo(function () {
|
|
191
|
+
return criticalImageUrls;
|
|
192
|
+
}, [criticalImageUrls]);
|
|
193
|
+
|
|
194
|
+
// Memoize the prefetch function
|
|
195
|
+
var prefetchImages = useCallback(function (urls) {
|
|
196
|
+
if (!urls || urls.length === 0) return;
|
|
197
|
+
|
|
198
|
+
// Prefetch critical images using browser's prefetch mechanism
|
|
199
|
+
imagePreloader.prefetchCriticalImages(urls);
|
|
200
|
+
|
|
201
|
+
// Also preload them through our system
|
|
202
|
+
urls.forEach(function (url) {
|
|
203
|
+
imagePreloader.preloadImage(url, imagePreloader.priorities.HIGH).catch(function (error) {
|
|
204
|
+
// Silently handle preload failures
|
|
205
|
+
// Critical image preload failed
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}, []);
|
|
209
|
+
useEffect(function () {
|
|
210
|
+
if (!memoizedUrls || memoizedUrls.length === 0) return;
|
|
211
|
+
|
|
212
|
+
// Check if URLs have changed
|
|
213
|
+
var urlsChanged = lastUrlsRef.current !== memoizedUrls;
|
|
214
|
+
if (!urlsChanged) return;
|
|
215
|
+
lastUrlsRef.current = memoizedUrls;
|
|
216
|
+
prefetchImages(memoizedUrls);
|
|
217
|
+
}, [memoizedUrls, prefetchImages]);
|
|
218
|
+
|
|
219
|
+
// Cleanup
|
|
220
|
+
useEffect(function () {
|
|
221
|
+
return function () {
|
|
222
|
+
lastUrlsRef.current = null;
|
|
223
|
+
};
|
|
224
|
+
}, []);
|
|
225
|
+
};
|
|
226
|
+
export default {
|
|
227
|
+
useImagePreloading: useImagePreloading,
|
|
228
|
+
useViewportImagePreloading: useViewportImagePreloading,
|
|
229
|
+
useImageCacheManagement: useImageCacheManagement,
|
|
230
|
+
useCriticalImagePrefetch: useCriticalImagePrefetch
|
|
231
|
+
};
|
|
Binary file
|