mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-04 21:23:07 +00:00
feat: Enhance validation viewing functionality with event emission
- Updated the `createMarkViewedHandler` to emit an event when a validation is marked as viewed, allowing the UI to update the unviewed count dynamically. - Modified the `useUnviewedValidations` hook to handle the new event type for decrementing the unviewed validations count. - Introduced a new event type `issue_validation_viewed` in the issue validation event type definition for better event handling.
This commit is contained in:
@@ -45,7 +45,7 @@ export function createGitHubRoutes(events: EventEmitter): Router {
|
|||||||
router.post(
|
router.post(
|
||||||
'/validation-mark-viewed',
|
'/validation-mark-viewed',
|
||||||
validatePathParams('projectPath'),
|
validatePathParams('projectPath'),
|
||||||
createMarkViewedHandler()
|
createMarkViewedHandler(events)
|
||||||
);
|
);
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Request, Response } from 'express';
|
import type { Request, Response } from 'express';
|
||||||
|
import type { EventEmitter } from '../../../lib/events.js';
|
||||||
|
import type { IssueValidationEvent } from '@automaker/types';
|
||||||
import {
|
import {
|
||||||
isValidationRunning,
|
isValidationRunning,
|
||||||
getValidationStatus,
|
getValidationStatus,
|
||||||
@@ -193,7 +195,7 @@ export function createDeleteValidationHandler() {
|
|||||||
/**
|
/**
|
||||||
* POST /validation-mark-viewed - Mark a validation as viewed by the user
|
* POST /validation-mark-viewed - Mark a validation as viewed by the user
|
||||||
*/
|
*/
|
||||||
export function createMarkViewedHandler() {
|
export function createMarkViewedHandler(events: EventEmitter) {
|
||||||
return async (req: Request, res: Response): Promise<void> => {
|
return async (req: Request, res: Response): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const { projectPath, issueNumber } = req.body as {
|
const { projectPath, issueNumber } = req.body as {
|
||||||
@@ -215,6 +217,16 @@ export function createMarkViewedHandler() {
|
|||||||
|
|
||||||
const success = await markValidationViewed(projectPath, issueNumber);
|
const success = await markValidationViewed(projectPath, issueNumber);
|
||||||
|
|
||||||
|
if (success) {
|
||||||
|
// Emit event so UI can update the unviewed count
|
||||||
|
const viewedEvent: IssueValidationEvent = {
|
||||||
|
type: 'issue_validation_viewed',
|
||||||
|
issueNumber,
|
||||||
|
projectPath,
|
||||||
|
};
|
||||||
|
events.emit('issue-validation:event', viewedEvent);
|
||||||
|
}
|
||||||
|
|
||||||
res.json({ success });
|
res.json({ success });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logError(error, 'Mark validation viewed failed');
|
logError(error, 'Mark validation viewed failed');
|
||||||
|
|||||||
@@ -45,7 +45,11 @@ export function useUnviewedValidations(currentProject: Project | null) {
|
|||||||
const unsubscribe = api.github.onValidationEvent((event) => {
|
const unsubscribe = api.github.onValidationEvent((event) => {
|
||||||
if (event.projectPath === currentProject.path) {
|
if (event.projectPath === currentProject.path) {
|
||||||
if (event.type === 'issue_validation_complete') {
|
if (event.type === 'issue_validation_complete') {
|
||||||
|
// New validation completed - increment count
|
||||||
setCount((prev) => prev + 1);
|
setCount((prev) => prev + 1);
|
||||||
|
} else if (event.type === 'issue_validation_viewed') {
|
||||||
|
// Validation was viewed - decrement count
|
||||||
|
setCount((prev) => Math.max(0, prev - 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -109,6 +109,11 @@ export type IssueValidationEvent =
|
|||||||
issueNumber: number;
|
issueNumber: number;
|
||||||
error: string;
|
error: string;
|
||||||
projectPath: string;
|
projectPath: string;
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
type: 'issue_validation_viewed';
|
||||||
|
issueNumber: number;
|
||||||
|
projectPath: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user