@if ( mode == 'default') {
diff --git a/ng-ttc-frontend/src/app/content/main-project-content/main-project-content.ts b/ng-ttc-frontend/src/app/content/main-project-content/main-project-content.ts
index 147599c..b2f3c96 100644
--- a/ng-ttc-frontend/src/app/content/main-project-content/main-project-content.ts
+++ b/ng-ttc-frontend/src/app/content/main-project-content/main-project-content.ts
@@ -2,6 +2,7 @@ import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { GeneralService } from '../../services/generalservice';
import { MainProjectAdd } from '../../component/main-project-add/main-project-add'; // Import Dumb Component
+import { ProjectStateService } from '../../services/state/project-state.service';
@Component({
selector: 'app-main-project-content',
@@ -18,6 +19,7 @@ export class MainProjectContent implements OnInit {
constructor(
private route: ActivatedRoute,
private router: Router,
+ private projectStateService: ProjectStateService, // Inject ProjectStateService
private generalService: GeneralService
) {}
@@ -33,6 +35,8 @@ export class MainProjectContent implements OnInit {
this.mode = 'default';
}
});
+
+ this.onSearchPrj();
}
// รับ Event (save) จากลูก แล้วยิง API
@@ -65,6 +69,26 @@ export class MainProjectContent implements OnInit {
});
}
+ // ฟังก์ชันดึงข้อมูลโครงการ และ update state
+ onSearchPrj(): void {
+ const uri = '/api/ttc/projectsearch?column=user';
+ const request = {}; // body ว่างตามที่ระบุ
+
+ this.generalService.postRequest(uri, request).subscribe({
+ next: (result: any) => {
+ if (result.code === '200') {
+ // สำเร็จ: นำข้อมูลใส่ State (Pattern: Service ยิง -> ได้ของ -> ยัดใส่ State -> Component Subscribe รอรับ)
+ this.projectStateService.setProjectState(result.data);
+ } else {
+ this.generalService.trowApi(result);
+ }
+ },
+ error: (error: any) => {
+ this.generalService.trowApi(error);
+ }
+ });
+ }
+
// รับ Event (cancel) จากลูก
onCancelProject(): void {
this.router.navigate(['/main/project']);