Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Multi-line Text, Correct Image Path, and Add Pagination #178

Open
wants to merge 1 commit into
base: autopilot/177-20240803234259070
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/frontend/src/components/message/message.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
grid-area: body;
padding-left: 5px;
padding-right: 5px;
white-space: pre-line;
}

.messagetags {
Expand Down
75 changes: 53 additions & 22 deletions app/frontend/src/components/messages/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useLastOpenTime } from '../../hooks/use-lastopen';
import { useMessageReceiver } from '../../hooks/use-messagereceiver';
import Message from '../message/message';
import style from './messages.css';
import { useEffect } from 'preact/hooks';
import { useEffect, useState } from 'preact/hooks';

const Messages: FunctionalComponent = () => {
const messages = useMessageReceiver();
Expand All @@ -13,33 +13,64 @@ const Messages: FunctionalComponent = () => {
const newMessages = messages.filter(e => !(e.receivedAt <= lastOpenTime));
const oldMessages = messages.filter(e => e.receivedAt <= lastOpenTime);

const [currentPage, setCurrentPage] = useState(1);
const [messagesPerPage] = useState(10);

const indexOfLastMessage = currentPage * messagesPerPage;
const indexOfFirstMessage = indexOfLastMessage - messagesPerPage;
const currentNewMessages = newMessages.slice(indexOfFirstMessage, indexOfLastMessage);
const currentOldMessages = oldMessages.slice(indexOfFirstMessage, indexOfLastMessage);

const totalPagesNew = Math.ceil(newMessages.length / messagesPerPage);
const totalPagesOld = Math.ceil(oldMessages.length / messagesPerPage);

const handleNextPage = () => {
if (currentPage < Math.max(totalPagesNew, totalPagesOld)) {
setCurrentPage(currentPage + 1);
}
};

const handlePrevPage = () => {
if (currentPage > 1) {
setCurrentPage(currentPage - 1);
}
};

useEffect(() => {
if (navigator && (navigator as any).clearAppBadge) {
(navigator as any).clearAppBadge();
}
}, [messages]);

return (<div class={style.content}>
<div class={style.main}>
<ul class={style.messagelist}>
{newMessages.map((message) => (
<li class={style.nobullet}>
<Message message={message} />
</li>)
)}
</ul>

{(newMessages.length > 0) && <div class={style.divider}></div>}

<ul class={style.messagelist}>
{oldMessages.map((message) => (
<li class={style.nobullet}>
<Message message={message} />
</li>)
)}
</ul>
return (
<div class={style.content}>
<div class={style.main}>
<ul class={style.messagelist}>
{currentNewMessages.map((message) => (
<li class={style.nobullet}>
<Message message={message} />
</li>
))}
</ul>

{(newMessages.length > 0) && <div class={style.divider}></div>}

<ul class={style.messagelist}>
{currentOldMessages.map((message) => (
<li class={style.nobullet}>
<Message message={message} />
</li>
))}
</ul>

<div class={style.pagination}>
<button onClick={handlePrevPage} disabled={currentPage === 1}>Previous</button>
<span>Page {currentPage}</span>
<button onClick={handleNextPage} disabled={currentPage >= Math.max(totalPagesNew, totalPagesOld)}>Next</button>
</div>
</div>
</div>
</div>)
}
);
};

export default Messages;
4 changes: 2 additions & 2 deletions app/frontend/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
"platform": "android"
},
{
"src": "/assets/icons/desktop-screenshot.png",
"src": "/assets/screenshots/desktop-screenshot.png",
"sizes": "2038x1301",
"type": "image/png",
"form_factor": "wide",
"label": "Home screen of Awesome App",
"platform": "windows"
},
{
"src": "/assets/icons/desktop-screenshot.png",
"src": "/assets/screenshots/desktop-screenshot.png",
"sizes": "2038x1301",
"type": "image/png",
"form_factor": "wide",
Expand Down