tangled
alpha
login
or
join now
margin.at
/
margin
87
fork
atom
Write on the margins of the internet. Powered by the AT Protocol.
margin.at
extension
web
atproto
comments
87
fork
atom
overview
issues
4
pulls
1
pipelines
fix feed tweaking out
scanash.com
1 month ago
6ad38876
d1a13809
+16
-23
2 changed files
expand all
collapse all
unified
split
backend
internal
api
handler.go
web
src
pages
Feed.jsx
+11
-18
backend/internal/api/handler.go
···
8
8
"log"
9
9
"net/http"
10
10
"net/url"
11
11
+
"sort"
11
12
"strconv"
12
13
"strings"
13
14
"sync"
···
461
462
}
462
463
463
464
func sortFeed(feed []interface{}) {
464
464
-
for i := 0; i < len(feed); i++ {
465
465
-
for j := i + 1; j < len(feed); j++ {
466
466
-
t1 := getCreatedAt(feed[i])
467
467
-
t2 := getCreatedAt(feed[j])
468
468
-
if t1.Before(t2) {
469
469
-
feed[i], feed[j] = feed[j], feed[i]
470
470
-
}
471
471
-
}
472
472
-
}
465
465
+
sort.Slice(feed, func(i, j int) bool {
466
466
+
t1 := getCreatedAt(feed[i])
467
467
+
t2 := getCreatedAt(feed[j])
468
468
+
return t1.After(t2)
469
469
+
})
473
470
}
474
471
475
472
func getCreatedAt(item interface{}) time.Time {
···
488
485
}
489
486
490
487
func sortFeedByPopularity(feed []interface{}) {
491
491
-
for i := 0; i < len(feed); i++ {
492
492
-
for j := i + 1; j < len(feed); j++ {
493
493
-
p1 := getPopularity(feed[i])
494
494
-
p2 := getPopularity(feed[j])
495
495
-
if p1 < p2 {
496
496
-
feed[i], feed[j] = feed[j], feed[i]
497
497
-
}
498
498
-
}
499
499
-
}
488
488
+
sort.Slice(feed, func(i, j int) bool {
489
489
+
p1 := getPopularity(feed[i])
490
490
+
p2 := getPopularity(feed[j])
491
491
+
return p1 > p2
492
492
+
})
500
493
}
501
494
502
495
func getPopularity(item interface{}) int {
+5
-5
web/src/pages/Feed.jsx
···
46
46
const { user } = useAuth();
47
47
48
48
const fetchFeed = useCallback(
49
49
-
async (isLoadMore = false) => {
49
49
+
async (offset = 0) => {
50
50
try {
51
51
+
const isLoadMore = offset > 0;
51
52
if (isLoadMore) {
52
53
setLoadingMore(true);
53
54
} else {
···
74
75
};
75
76
const motivation = motivationMap[filter] || "";
76
77
const limit = 50;
77
77
-
const offset = isLoadMore ? annotations.length : 0;
78
78
79
79
const data = await getAnnotationFeed(
80
80
limit,
···
104
104
setLoadingMore(false);
105
105
}
106
106
},
107
107
-
[tagFilter, feedType, filter, user, annotations.length],
107
107
+
[tagFilter, feedType, filter, user],
108
108
);
109
109
110
110
useEffect(() => {
111
111
-
fetchFeed(false);
111
111
+
fetchFeed(0);
112
112
}, [fetchFeed]);
113
113
114
114
const deduplicatedAnnotations = useMemo(() => {
···
354
354
}}
355
355
>
356
356
<button
357
357
-
onClick={() => fetchFeed(true)}
357
357
+
onClick={() => fetchFeed(annotations.length)}
358
358
disabled={loadingMore}
359
359
className="feed-load-more"
360
360
>