mirror of
				https://github.com/ae-utbm/sith.git
				synced 2025-10-31 09:03:06 +00:00 
			
		
		
		
	Close alerts related to a moderated event
This commit is contained in:
		| @@ -1,5 +1,5 @@ | ||||
| import { exportToHtml } from "#core:utils/globals"; | ||||
| import { newsDeleteNews, newsModerateNews } from "#openapi"; | ||||
| import { newsDeleteNews, newsFetchNewsDates, newsModerateNews } from "#openapi"; | ||||
|  | ||||
| // This will be used in jinja templates, | ||||
| // so we cannot use real enums as those are purely an abstraction of Typescript | ||||
| @@ -24,6 +24,7 @@ document.addEventListener("alpine:init", () => { | ||||
|       // biome-ignore lint/style/useNamingConvention: api is snake case | ||||
|       await newsModerateNews({ path: { news_id: this.newsId } }); | ||||
|       this.state = AlertState.MODERATED; | ||||
|       this.$dispatch("news-moderated", { newsId: this.newsId, state: this.state }); | ||||
|       this.loading = false; | ||||
|     }, | ||||
|  | ||||
| @@ -32,7 +33,36 @@ document.addEventListener("alpine:init", () => { | ||||
|       // biome-ignore lint/style/useNamingConvention: api is snake case | ||||
|       await newsDeleteNews({ path: { news_id: this.newsId } }); | ||||
|       this.state = AlertState.DELETED; | ||||
|       this.$dispatch("news-moderated", { newsId: this.newsId, state: this.state }); | ||||
|       this.loading = false; | ||||
|     }, | ||||
|  | ||||
|     /** | ||||
|      * Event receiver for when news dates are moderated. | ||||
|      * | ||||
|      * If the moderated date is linked to the same news | ||||
|      * as the one this moderation alert is attached to, | ||||
|      * then set the alert state to the same as the moderated one. | ||||
|      */ | ||||
|     dispatchModeration(event: CustomEvent) { | ||||
|       if (event.detail.newsId === this.newsId) { | ||||
|         this.state = event.detail.state; | ||||
|       } | ||||
|     }, | ||||
|  | ||||
|     /** | ||||
|      * Query the server to know the number of news dates that would be moderated | ||||
|      * if this one is moderated. | ||||
|      */ | ||||
|     async nbModerated() { | ||||
|       // What we want here is the count attribute of the response. | ||||
|       // We don't care about the actual results, | ||||
|       // so we ask for the minimum page size possible. | ||||
|       const response = await newsFetchNewsDates({ | ||||
|         // biome-ignore lint/style/useNamingConvention: api is snake-case | ||||
|         query: { news_id: this.newsId, page: 1, page_size: 1 }, | ||||
|       }); | ||||
|       return response.data.count; | ||||
|     }, | ||||
|   })); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user