mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 23:12:39 +00:00
remove lookup by id funct and fix lost state functions
This commit is contained in:
@@ -36,34 +36,6 @@ const NotificationLookup = () => {
|
|||||||
const [searching, setSearching] = useState(false);
|
const [searching, setSearching] = useState(false);
|
||||||
const [error, setError] = useState(null);
|
const [error, setError] = useState(null);
|
||||||
const [notifications, setNotifications] = useState([]);
|
const [notifications, setNotifications] = useState([]);
|
||||||
|
|
||||||
const lookupRef = useRef(null);
|
|
||||||
|
|
||||||
const lookup = async () => {
|
|
||||||
const query = lookupRef.current.value;
|
|
||||||
|
|
||||||
if (!query.trim()) {
|
|
||||||
setError('Please enter a valid dismiss key.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setSearching(true);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await request.get(`/admin/notification/lookup/${query}`);
|
|
||||||
if (res.body) {
|
|
||||||
setFoundNotification(res.body);
|
|
||||||
} else {
|
|
||||||
setFoundNotification(null);
|
|
||||||
setError('No notification found.');
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
setError('Error fetching notification.');
|
|
||||||
} finally {
|
|
||||||
setSearching(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const lookupAll = async () => {
|
const lookupAll = async () => {
|
||||||
setSearching(true);
|
setSearching(true);
|
||||||
@@ -103,22 +75,6 @@ const NotificationLookup = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderFoundNotification = () => {
|
|
||||||
if (error) {
|
|
||||||
return <div className="error">{error}</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!foundNotification) {
|
|
||||||
return <div className="noNotification">No notification found.</div>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="foundNotification">
|
|
||||||
<NotificationDetail notification={foundNotification} onDelete={deleteNotification} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderNotificationsList = () => {
|
const renderNotificationsList = () => {
|
||||||
if (error) {
|
if (error) {
|
||||||
return <div className="error">{error}</div>;
|
return <div className="error">{error}</div>;
|
||||||
@@ -129,45 +85,22 @@ const NotificationLookup = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="notificationList">
|
<ul className="notificationList">
|
||||||
{notifications.map((notification) => (
|
{notifications.map((notification) => (
|
||||||
<details key={notification.dismissKey}>
|
<li key={notification.dismissKey} >
|
||||||
|
<details>
|
||||||
<summary>{notification.title || 'No Title'}</summary>
|
<summary>{notification.title || 'No Title'}</summary>
|
||||||
<NotificationDetail notification={notification} onDelete={deleteNotification} />
|
<NotificationDetail notification={notification} onDelete={deleteNotification} />
|
||||||
</details>
|
</details></li>
|
||||||
|
|
||||||
))}
|
))}
|
||||||
</div>
|
</ul>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="notificationLookup">
|
<div className="notificationLookup">
|
||||||
<div className="byId">
|
<h2>Check all Notifications</h2><button onClick={lookupAll}>
|
||||||
<h2>Lookup by dissmiss key</h2>
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
ref={lookupRef}
|
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (e.key === 'Enter') {
|
|
||||||
lookup();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
placeholder="dismiss key"
|
|
||||||
/>
|
|
||||||
<button onClick={lookup}>
|
|
||||||
<i
|
|
||||||
className={cx('fas', {
|
|
||||||
'fa-search': !searching,
|
|
||||||
'fa-spin fa-spinner': searching,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
{renderFoundNotification()}
|
|
||||||
</div>
|
|
||||||
<div className="all">
|
|
||||||
<h2>Check all Notifications</h2>
|
|
||||||
<button onClick={lookupAll}>
|
|
||||||
<i
|
<i
|
||||||
className={cx('fas', {
|
className={cx('fas', {
|
||||||
'fa-search': !searching,
|
'fa-search': !searching,
|
||||||
@@ -175,9 +108,9 @@ const NotificationLookup = () => {
|
|||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
|
|
||||||
{renderNotificationsList()}
|
{renderNotificationsList()}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user