diff --git a/postrify-backend/src/main/resources/application.properties b/postrify-backend/src/main/resources/application.properties index 3f29d19..cec5469 100644 --- a/postrify-backend/src/main/resources/application.properties +++ b/postrify-backend/src/main/resources/application.properties @@ -4,5 +4,5 @@ spring.datasource.username=postgres spring.datasource.password=postgres spring.jpa.hibernate.ddl-auto=update app.jwtSecret=YourJwtSecretKey -app.jwtExpirationInMs=2592000000 +app.jwtExpirationInMs=604800000 spring.jpa.open-in-view=false diff --git a/postrify-frontend/src/app/components/post-form/post-form.component.ts b/postrify-frontend/src/app/components/post-form/post-form.component.ts index c891e52..8293cbd 100644 --- a/postrify-frontend/src/app/components/post-form/post-form.component.ts +++ b/postrify-frontend/src/app/components/post-form/post-form.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { Post } from '../../models/post.model'; import { Router } from '@angular/router'; import { PostService } from '../../services/post.service'; @@ -24,6 +24,7 @@ import { ToastService } from '../../services/toast.service'; minlength="3" maxlength="30" #titleInput="ngModel" + (ngModelChange)="saveFormState()" />
{{ post.title.length }}/30
@if (titleInput.invalid && (titleInput.dirty || titleInput.touched)) { @@ -47,6 +48,7 @@ import { ToastService } from '../../services/toast.service'; minlength="10" maxlength="1000" #contentInput="ngModel" + (ngModelChange)="saveFormState()" >
{{ post.content.length }}/1000
@if ( @@ -143,7 +145,7 @@ import { ToastService } from '../../services/toast.service'; } `, }) -export class PostFormComponent { +export class PostFormComponent implements OnInit { post: Post = { title: '', content: '', @@ -155,11 +157,32 @@ export class PostFormComponent { private router: Router, ) {} + ngOnInit(): void { + this.loadFormState(); + } + + saveFormState(): void { + localStorage.setItem('postFormData', JSON.stringify(this.post)); + } + + loadFormState(): void { + const savedData = localStorage.getItem('postFormData'); + if (savedData) { + this.post = JSON.parse(savedData); + } + } + + clearFormState(): void { + localStorage.removeItem('postFormData'); + this.post = { title: '', content: '' }; + } + onSubmit(): void { this.postService.createPost(this.post).subscribe({ next: (data) => { console.log('Post created successfully', data); this.toastService.show('Post created successfully', 'success'); + this.clearFormState(); this.router.navigate(['/']); }, error: (error) => {