fix: max 50 comments
This commit is contained in:
parent
82d8e34560
commit
bc1687e40a
1 changed files with 5 additions and 3 deletions
|
|
@ -22,6 +22,8 @@
|
||||||
let isLoading = $state(true);
|
let isLoading = $state(true);
|
||||||
let shouldSignIn = $state(false);
|
let shouldSignIn = $state(false);
|
||||||
|
|
||||||
|
const MAX_COMMENTS = 50;
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
websocketController.setCoin(coinSymbol);
|
websocketController.setCoin(coinSymbol);
|
||||||
websocketController.subscribeToComments(coinSymbol, handleWebSocketMessage);
|
websocketController.subscribeToComments(coinSymbol, handleWebSocketMessage);
|
||||||
|
|
@ -37,7 +39,7 @@
|
||||||
// check if comment already exists
|
// check if comment already exists
|
||||||
const commentExists = comments.some((c) => c.id === message.data.id);
|
const commentExists = comments.some((c) => c.id === message.data.id);
|
||||||
if (!commentExists) {
|
if (!commentExists) {
|
||||||
comments = [message.data, ...comments];
|
comments = [message.data, ...comments.slice(0, MAX_COMMENTS - 1)];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'comment_liked':
|
case 'comment_liked':
|
||||||
|
|
@ -61,7 +63,7 @@
|
||||||
const response = await fetch(`/api/coin/${coinSymbol}/comments`);
|
const response = await fetch(`/api/coin/${coinSymbol}/comments`);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
const result = await response.json();
|
const result = await response.json();
|
||||||
comments = result.comments;
|
comments = result.comments.slice(0, MAX_COMMENTS);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to load comments:', e);
|
console.error('Failed to load comments:', e);
|
||||||
|
|
@ -91,7 +93,7 @@
|
||||||
// check if comment already exists (from ws) before adding
|
// check if comment already exists (from ws) before adding
|
||||||
const commentExists = comments.some((c) => c.id === result.comment.id);
|
const commentExists = comments.some((c) => c.id === result.comment.id);
|
||||||
if (!commentExists) {
|
if (!commentExists) {
|
||||||
comments = [result.comment, ...comments];
|
comments = [result.comment, ...comments.slice(0, MAX_COMMENTS - 1)];
|
||||||
}
|
}
|
||||||
newComment = '';
|
newComment = '';
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Reference in a new issue