funky-framadate-front/src/app/core/services/url.service.ts

27 lines
785 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Injectable } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { LoaderService } from './loader.service';
import { PollService } from './poll.service';
@Injectable({
providedIn: 'root',
})
export class UrlService {
constructor(
private route: ActivatedRoute,
private pollService: PollService,
private loaderService: LoaderService
) {}
public async loadPollFromUrl(): Promise<void> {
// TODO: behavior improvement needed.
// check if pollService currentPolls slug match the url : if yes, dont fetch again.
this.loaderService.setStatus(true);
const wantedSlug: string = this.route.snapshot.firstChild.firstChild.url[1].path;
await this.pollService.getPollBySlug(wantedSlug);
this.loaderService.setStatus(false);
}
}