-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/auth and save story #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hashirjamal
wants to merge
10
commits into
main
Choose a base branch
from
feat/auth-and-save-story
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f6fb77
chore: firebase auth service
hashirjamal ad4c86b
chore: signin and signup UI with routes
hashirjamal a5c536d
chor: business logic and state management of auth
hashirjamal afb31da
chore: save story service
hashirjamal 50262f4
chore: UI links and routing
hashirjamal 103a9e0
chore: save story button and service call
hashirjamal 130f103
chore: saved stories page and logic
hashirjamal 8fc080e
chore: unsave button with modal
hashirjamal f8fcf0a
chore: snack bar on save and unsave
hashirjamal e581c3c
chore: code cleanup
hashirjamal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <section class="py-12 px-6 bg-base-100"> | ||
| <h2 class="text-center text-3xl font-bold mb-10">Your Stories</h2> | ||
|
|
||
| <div class="max-w-3xl mx-auto flex flex-col gap-6"> | ||
| @if (!loading() && userStories().length > 0) { @for (story of userStories(); | ||
| track story.id) { | ||
| <div class="card bg-base-200 shadow-xl min-h-48"> | ||
| <figure class="relative aspect-video overflow-hidden"> | ||
| <img | ||
| [src]="story.storyParts[0].imageUri" | ||
| alt="{{ story.name }}" | ||
| class="absolute inset-0 w-full h-full object-cover" | ||
| /> | ||
| </figure> | ||
| <div class="card-body text-center items-center"> | ||
| <h3 class="card-title text-lg h-16 text-white">{{ story.name }}</h3> | ||
| <div class="card-actions justify-center gap-2"> | ||
| <a | ||
| class="btn btn-primary" | ||
| [routerLink]="'/viewStory'" | ||
| [queryParams]="{ id: story.id }" | ||
| > | ||
| Read Story | ||
| </a> | ||
| <button | ||
| class="btn btn-secondary" | ||
| (click)="openConfirmationModal(story.id)" | ||
| > | ||
| Unsave | ||
| </button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| } } @else if (!loading()) { | ||
| <p class="text-center text-gray-400">No stories saved yet.</p> | ||
| } @else { | ||
| <!-- Skeleton loader --> | ||
| @for (_ of [1, 2]; track _) { | ||
| <div class="card bg-base-200 shadow-xl min-h-48 animate-pulse"> | ||
| <figure class="h-48 bg-base-300"> | ||
| <div class="skeleton w-full h-full"></div> | ||
| </figure> | ||
| <div class="card-body text-center items-center space-y-4"> | ||
| <div class="skeleton h-6 w-3/4"></div> | ||
| <div class="skeleton h-10 w-24"></div> | ||
| </div> | ||
| </div> | ||
| } } | ||
| </div> | ||
| </section> | ||
|
|
||
| <!-- Confirmation Modal --> | ||
| @if (isModalOpen()) { | ||
| <dialog class="modal modal-open modal-bottom sm:modal-middle"> | ||
| <div class="modal-box"> | ||
| <h3 class="font-bold text-lg">Confirm Unsave</h3> | ||
| <p class="py-4"> | ||
| Are you sure you want to unsave this story? This action cannot be undone. | ||
| </p> | ||
| <div class="modal-action"> | ||
| <button class="btn btn-ghost" (click)="closeConfirmationModal()"> | ||
| Cancel | ||
| </button> | ||
| <button class="btn btn-error" (click)="confirmUnsave()">Unsave</button> | ||
| </div> | ||
| </div> | ||
| </dialog> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { Component, inject, effect, signal } from '@angular/core'; | ||
| import { StorySaveService } from '../../services/save.story.service'; | ||
| import { AuthStore } from '../../services/auth.store'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { RouterLink } from '@angular/router'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-my-stories', | ||
| templateUrl: './my-stories.html', | ||
| styleUrls: ['./my-stories.css'], | ||
| imports: [CommonModule, RouterLink], | ||
| }) | ||
| export class UserStoriesComponent { | ||
| userStories = signal<any[]>([]); | ||
| loading = signal(true); | ||
| isModalOpen = signal(false); | ||
| selectedStoryId = signal<string | null>(null); | ||
|
|
||
| private readonly storyService = inject(StorySaveService); | ||
| private readonly authService = inject(AuthStore); | ||
|
|
||
| constructor() { | ||
| // reactively respond to auth changes | ||
| effect(async () => { | ||
| const user = this.authService.user(); // signal | ||
| if (user?.uid) { | ||
| this.loading.set(true); | ||
| try { | ||
| const stories = await this.storyService.getUserStory(user.uid); | ||
|
|
||
| const storiesArray = stories.map((v) => ({ ...v.data(), id: v.id })); | ||
| this.userStories.set(storiesArray); | ||
| console.log(this.userStories()); | ||
| } catch (err) { | ||
| console.error('Error loading stories:', err); | ||
| } finally { | ||
| this.loading.set(false); | ||
|
Comment on lines
+36
to
+37
|
||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| openConfirmationModal(storyId: string): void { | ||
| this.selectedStoryId.set(storyId); | ||
| this.isModalOpen.set(true); | ||
| } | ||
|
|
||
| closeConfirmationModal(): void { | ||
| this.isModalOpen.set(false); | ||
| this.selectedStoryId.set(null); | ||
| } | ||
|
|
||
| async confirmUnsave(): Promise<void> { | ||
| const storyId = this.selectedStoryId(); | ||
| const user = this.authService.user(); | ||
|
|
||
| if (storyId && user?.uid) { | ||
| const result = await this.storyService.removeSavedStory( | ||
| storyId, | ||
| user.uid | ||
| ); | ||
| if (result.success) { | ||
| this.userStories.update((stories) => | ||
| stories.filter((story) => story.id !== storyId) | ||
| ); | ||
| } else { | ||
| // Optional: handle error with a user-facing message | ||
| console.error('Failed to unsave story:', result.message); | ||
| } | ||
| this.closeConfirmationModal(); | ||
| } | ||
| } | ||
| } | ||
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| <div | ||
| class="min-h-screen flex items-center justify-center bg-dracula text-dracula-foreground" | ||
| > | ||
| <div class="w-full max-w-md p-8 rounded-2xl shadow-lg bg-dracula-selection"> | ||
| <!-- Branding --> | ||
| <div class="text-center mb-6"> | ||
| <h1 class="text-3xl font-bold text-primary">Kidlytics</h1> | ||
| <p class="text-sm text-dracula-comment mt-1">AI Powered Story Teller</p> | ||
| </div> | ||
|
|
||
| <!-- Login Form --> | ||
| <form | ||
| [formGroup]="form" | ||
| (ngSubmit)="onEmailLogin()" | ||
| class="flex flex-col gap-4" | ||
| > | ||
| <input | ||
| class="p-3 rounded-lg border border-dracula-purple bg-dracula text-dracula-foreground focus:ring-2 focus:ring-primary transition" | ||
| type="email" | ||
| formControlName="email" | ||
| placeholder="Email" | ||
| /> | ||
|
|
||
| <input | ||
| class="p-3 rounded-lg border border-dracula-purple bg-dracula text-dracula-foreground focus:ring-2 focus:ring-primary transition" | ||
| type="password" | ||
| formControlName="password" | ||
| placeholder="Password" | ||
| /> | ||
|
|
||
| <button | ||
| type="submit" | ||
| class="btn-primary p-3 rounded-lg text-white font-bold transition hover:scale-105 disabled:opacity-50 cursor-pointer border border-5 shadow-lg" | ||
| [disabled]="form.invalid || loading()" | ||
| > | ||
| {{ loading() ? 'Logging in...' : 'Login' }} | ||
| </button> | ||
| </form> | ||
|
|
||
| <!-- Divider --> | ||
| <div class="flex items-center my-6"> | ||
| <div class="flex-grow border-t border-dracula-purple"></div> | ||
| <span class="px-3 text-dracula-comment text-sm">or</span> | ||
| <div class="flex-grow border-t border-dracula-purple"></div> | ||
| </div> | ||
|
|
||
| <!-- Google login --> | ||
| <button | ||
| class="btn btn-sm btn-primary w-full hover:btn-ghost cursor-pointer" | ||
| (click)="onGoogleLogin()" | ||
| [disabled]="loading()" | ||
| > | ||
| Continue with Google | ||
| </button> | ||
|
|
||
| <!-- Error --> | ||
| @if(error()) { | ||
| <p class="text-sm text-red-400 mt-3 text-center">Could not Sign In</p> | ||
| } | ||
| </div> | ||
| </div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace 'any[]' with a proper type definition. Consider creating an interface for the story data structure to improve type safety.