Skip to content

Commit 8bb074f

Browse files
aster-voidnakaterm
authored andcommitted
fixed home showing "sent like to all" while loading (#607)
closes #605
1 parent 882ac65 commit 8bb074f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

web/app/home/page.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,22 @@ export default function Home() {
2323
} = useAboutMe();
2424

2525
const [_, rerender] = useState({});
26-
const [recommended, setRecommended] = useState<
27-
Queue<UserWithCoursesAndSubjects>
28-
>(() => new Queue([]));
26+
const [recommended, setRecommended] =
27+
useState<Queue<UserWithCoursesAndSubjects> | null>(null);
2928
useEffect(() => {
3029
if (data) setRecommended(new Queue(data));
3130
}, [data]);
3231

33-
const displayedUser = recommended.peek(1);
34-
const nextUser = recommended.peek(2);
32+
const displayedUser = recommended?.peek(0);
33+
const nextUser = recommended?.peek(1);
3534
const reject = useCallback(() => {
36-
const current = recommended.pop();
35+
const current = recommended?.pop();
3736
if (!current) return;
38-
recommended.push(current);
37+
recommended?.push(current);
3938
rerender({});
4039
}, [recommended]);
4140
const accept = useCallback(async () => {
42-
const current = recommended.pop();
41+
const current = recommended?.pop();
4342
if (!current) return;
4443
request.send(current.id);
4544
rerender({});
@@ -73,10 +72,10 @@ export default function Home() {
7372
});
7473
}, [controls, accept]);
7574

76-
if (currentUser == null) {
75+
if (recommended == null) {
7776
return <FullScreenCircularProgress />;
7877
}
79-
if (recommended == null) {
78+
if (currentUser == null) {
8079
return <FullScreenCircularProgress />;
8180
}
8281
if (displayedUser == null) {
@@ -180,9 +179,9 @@ class Queue<T> {
180179
push(top: T): void {
181180
this.store.push(top);
182181
}
183-
// peek(1) to peek the next elem to be popped, peek(2) peeks the second next element to be popped.
182+
// peek(0) to peek the next elem to be popped, peek(1) peeks the second next element to be popped.
184183
peek(nth: number): T | undefined {
185-
return this.store[nth - 1];
184+
return this.store[nth];
186185
}
187186
pop(): T | undefined {
188187
return this.store.shift();

0 commit comments

Comments
 (0)