Open mskian opened 3 months ago
To address the task, we need to make three main changes:
To ensure that text within the messagebody
class displays on multiple lines, we need to add the white-space: pre-line
property to the CSS.
app/frontend/src/components/message/message.css
.message {
max-width: 100%;
display: grid;
grid-template-areas:
"title time"
"body body"
"tags tags"
"image image";
grid-template-columns: repeat(2, minmax(0, 1fr));
align-content: space-between;
padding: 10px;
}
.messagetitle {
grid-area: title;
font-size: 1.2em;
padding-left: 5px;
overflow: hidden;
margin-top: 0px;
}
.messagetime {
grid-area: time;
justify-self: right;
padding-right: 5px;
margin-top: 0px;
}
.messagebody {
grid-area: body;
padding-left: 5px;
padding-right: 5px;
white-space: pre-line; /* Add this line to allow multi-line text */
}
.messagetags {
grid-area: tags;
}
.messageimage {
grid-area: image;
max-width: 100%;
max-height: 25vh;
justify-self: center;
}
We need to update the manifest.json
file to correct the path for the desktop screenshot image.
app/frontend/src/manifest.json
{
"name": "notify app",
"short_name": "notify",
"start_url": "/",
"display": "standalone",
"orientation": "portrait",
"background_color": "#000",
"theme_color": "#000",
"categories": [
"utilities",
"productivity"
],
"description": "Notify is a simple app that allows you to receive notifications from a webhook.",
"icons": [
{
"src": "/assets/icons/notify_big.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "/assets/icons/notify_big.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/assets/icons/notify_small.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/assets/icons/notify_small.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
}
],
"screenshots": [
{
"src": "/assets/screenshots/mobile-screenshot.png",
"sizes": "1170x2532",
"type": "image/png",
"form_factor": "narrow",
"label": "App screenshot with example notification",
"platform": "ios"
},
{
"src": "/assets/screenshots/mobile-screenshot.png",
"sizes": "1170x2532",
"type": "image/png",
"form_factor": "narrow",
"label": "App screenshot with example notification",
"platform": "android"
},
{
"src": "/assets/screenshots/desktop-screenshot.png",
"sizes": "2038x1301",
"type": "image/png",
"form_factor": "wide",
"label": "Home screen of Awesome App",
"platform": "windows"
},
{
"src": "/assets/screenshots/desktop-screenshot.png",
"sizes": "2038x1301",
"type": "image/png",
"form_factor": "wide",
"label": "Home screen of Awesome App",
"platform": "macos"
}
]
}
To implement pagination in the Messages
component, we need to manage the state for the current page and the number of messages per page, and provide controls to navigate between pages.
app/frontend/src/components/messages/messages.tsx
import { FunctionalComponent, h } from 'preact';
import 'preact-material-components/Theme/style.css';
import { useLastOpenTime } from '../../hooks/use-lastopen';
import { useMessageReceiver } from '../../hooks/use-messagereceiver';
import Message from '../message/message';
import style from './messages.css';
import { useEffect, useState } from 'preact/hooks';
const Messages: FunctionalComponent = () => {
const messages = useMessageReceiver();
const lastOpenTime = useLastOpenTime();
const newMessages = messages.filter(e => !(e.receivedAt <= lastOpenTime));
const oldMessages = messages.filter(e => e.receivedAt <= lastOpenTime);
const [currentPage, setCurrentPage] = useState(1);
const messagesPerPage = 10;
const totalMessages = newMessages.length + oldMessages.length;
const totalPages = Math.ceil(totalMessages / messagesPerPage);
const paginateMessages = (messages, page) => {
const startIndex = (page - 1) * messagesPerPage;
return messages.slice(startIndex, startIndex + messagesPerPage);
};
const handleNextPage = () => {
if (currentPage < totalPages) {
setCurrentPage(currentPage + 1);
}
};
const handlePreviousPage = () => {
if (currentPage > 1) {
setCurrentPage(currentPage - 1);
}
};
useEffect(() => {
if (navigator && (navigator as any).clearAppBadge) {
(navigator as any).clearAppBadge();
}
}, [messages]);
const paginatedNewMessages = paginateMessages(newMessages, currentPage);
const paginatedOldMessages = paginateMessages(oldMessages, currentPage - Math.ceil(newMessages.length / messagesPerPage));
return (
<div class={style.content}>
<div class={style.main}>
<ul class={style.messagelist}>
{paginatedNewMessages.map((message) => (
<li class={style.nobullet}>
<Message message={message} />
</li>)
)}
</ul>
{(newMessages.length > 0) && <div class={style.divider}></div>}
<ul class={style.messagelist}>
{paginatedOldMessages.map((message) => (
<li class={style.nobullet}>
<Message message={message} />
</li>)
)}
</ul>
<div class={style.pagination}>
<button onClick={handlePreviousPage} disabled={currentPage === 1}>Previous</button>
<span>Page {currentPage} of {totalPages}</span>
<button onClick={handleNextPage} disabled={currentPage === totalPages}>Next</button>
</div>
</div>
</div>
);
};
export default Messages;
This implementation ensures that:
messagebody
class displays on multiple lines.Click here to create a Pull Request with the proposed solution
Files used for this task:
Oh My AI Boy Good work and Suggestion 😀
Front-end UI Need Some Improvements