Reinitializing noteIndex when fetching new notes (to avoid out of length indexes).

This commit is contained in:
Eric van der Vlist 2022-10-11 14:15:46 +02:00
parent 5a7402313e
commit 304c4d38b7
1 changed files with 37 additions and 35 deletions

View File

@ -77,6 +77,7 @@ const LocationInfo: React.FC<{}> = () => {
const findNotes = async () => {
setNotes(undefined);
setNoteIndex(0);
const metresPerDegree =
111111 * Math.cos((scope.center.lat * Math.PI) / 180);
const deltaDegrees = 2000 / metresPerDegree;
@ -249,41 +250,42 @@ const LocationInfo: React.FC<{}> = () => {
/>
</ConversationHeader>
<MessageList>
{notes.features[noteIndex].properties.comments.map(
(comment: any, index: number) => (
<Message
key={`${notes.features[noteIndex].properties.id}/${index}`}
model={{
direction: 'incoming',
position: 'single',
sender: comment.user,
sentTime: comment.date,
payload: comment.html,
}}
>
<Message.Header
sender={comment.user}
sentTime={comment.date}
/>
<Message.Footer sentTime={comment.action} />
<Avatar
src={AvatarInitial.initialAvatar({
size: 100,
initials: comment.user ? comment.user : '??',
initial_fg: comment.user
? 'darkblue'
: 'lightgrey',
initial_bg: comment.user ? 'ivory' : 'darkred',
initial_size: 0, // Defaults to height / 2
initial_weight: 1000,
initial_font_family:
"'Lato', 'Lato-Regular', 'Helvetica Neue'",
})}
name={comment.user ? comment.user : 'anonymous'}
/>
</Message>
)
)}
{noteIndex < notes.features.length &&
notes.features[noteIndex].properties.comments.map(
(comment: any, index: number) => (
<Message
key={`${notes.features[noteIndex].properties.id}/${index}`}
model={{
direction: 'incoming',
position: 'single',
sender: comment.user,
sentTime: comment.date,
payload: comment.html,
}}
>
<Message.Header
sender={comment.user}
sentTime={comment.date}
/>
<Message.Footer sentTime={comment.action} />
<Avatar
src={AvatarInitial.initialAvatar({
size: 100,
initials: comment.user ? comment.user : '??',
initial_fg: comment.user
? 'darkblue'
: 'lightgrey',
initial_bg: comment.user ? 'ivory' : 'darkred',
initial_size: 0, // Defaults to height / 2
initial_weight: 1000,
initial_font_family:
"'Lato', 'Lato-Regular', 'Helvetica Neue'",
})}
name={comment.user ? comment.user : 'anonymous'}
/>
</Message>
)
)}
</MessageList>
</ChatContainer>
</MainContainer>