@sneat/app 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { inject } from '@angular/core';
2
2
  import { Title } from '@angular/platform-browser';
3
3
  import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
4
- import { TelegramAuthService } from '@sneat/auth-core';
5
- import { AnalyticsService, TopMenuService } from '@sneat/core';
4
+ import { SneatAuthStateService, TelegramAuthService, } from '@sneat/auth-core';
5
+ import { AnalyticsService, clearCurrentSpace, TopMenuService } from '@sneat/core';
6
6
  import { filter } from 'rxjs';
7
7
  export class BaseAppComponent {
8
8
  constructor() {
@@ -11,8 +11,12 @@ export class BaseAppComponent {
11
11
  this.activatedRoute = inject(ActivatedRoute);
12
12
  this.analyticsService = inject(AnalyticsService);
13
13
  this.titleService = inject(Title);
14
+ this.authStateService = inject(SneatAuthStateService);
14
15
  this.topMenuService = inject(TopMenuService); // used in templates
15
16
  this.telegramAuthService.authenticateIfTelegramWebApp();
17
+ this.authStateService.authState.subscribe((s) => {
18
+ this.authStatus = s.status;
19
+ });
16
20
  this.router.events
17
21
  .pipe(filter((event) => event instanceof NavigationEnd))
18
22
  .subscribe((event) => {
@@ -33,8 +37,25 @@ export class BaseAppComponent {
33
37
  });
34
38
  title = title ? `${title} @ Sneat.App` : 'Sneat.App'; // Default title
35
39
  this.titleService.setTitle(title);
40
+ this.forgetCurrentSpaceIfLeftSpaces(event.urlAfterRedirects);
36
41
  });
37
42
  }
43
+ // Keep the persisted current space in sync with where an authenticated user is:
44
+ // once they navigate to a non-space page, forget it so login does not bounce them
45
+ // back to a space they had left. Auth routes are ignored so signing out from a
46
+ // space still restores it; the `authenticated` guard preserves the value during
47
+ // the logged-out login flow so the login page can still read it.
48
+ forgetCurrentSpaceIfLeftSpaces(url) {
49
+ if (this.authStatus !== 'authenticated') {
50
+ return;
51
+ }
52
+ if (url.startsWith('/space/') ||
53
+ url.startsWith('/login') ||
54
+ url.startsWith('/signed-out')) {
55
+ return;
56
+ }
57
+ clearCurrentSpace();
58
+ }
38
59
  }
39
60
  function capitalizeFirstLetter(text) {
40
61
  return text.charAt(0).toUpperCase() + text.slice(1);
@@ -1 +1 @@
1
- {"version":3,"file":"base-app.component.js","sourceRoot":"","sources":["../../../../../libs/app/src/lib/base-app.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,MAAM,OAAO,gBAAgB;IAQ3B;QAPiB,wBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAClD,WAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QACxB,mBAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QACxC,qBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC5C,iBAAY,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3B,mBAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,oBAAoB;QAG9E,IAAI,CAAC,mBAAmB,CAAC,4BAA4B,EAAE,CAAC;QACxD,IAAI,CAAC,MAAM,CAAC,MAAM;aACf,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,YAAY,aAAa,CAAC,CAAC;aACvD,SAAS,CAAC,CAAC,KAAoB,EAAE,EAAE;YAClC,IAAI,KAAK,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC;YAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,CAAC;gBACzB,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC;YAC3B,CAAC;YACD,IAAI,KAAK,GAAG,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,SAAS,GAAG,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;gBAC9D,IAAI,SAAS,EAAE,CAAC;oBACd,KAAK,GAAG,GAAG,qBAAqB,CAAC,SAAS,CAAC,IAAI,KAAK,EAAE,CAAC;gBACzD,CAAC;YACH,CAAC;YACD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,WAAW,EAAE;gBAC1C,SAAS,EAAE,KAAK,CAAC,iBAAiB;gBAClC,KAAK;aACN,CAAC,CAAC;YACH,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,cAAc,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,gBAAgB;YACtE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC,CAAC,CAAC;IACP,CAAC;CACF;AAED,SAAS,qBAAqB,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { inject } from '@angular/core';\nimport { Title } from '@angular/platform-browser';\nimport { ActivatedRoute, NavigationEnd, Router } from '@angular/router';\nimport { TelegramAuthService } from '@sneat/auth-core';\nimport { AnalyticsService, TopMenuService } from '@sneat/core';\nimport { filter } from 'rxjs';\n\nexport class BaseAppComponent {\n private readonly telegramAuthService = inject(TelegramAuthService);\n private readonly router = inject(Router);\n private readonly activatedRoute = inject(ActivatedRoute);\n private readonly analyticsService = inject(AnalyticsService);\n private readonly titleService = inject(Title);\n protected readonly topMenuService = inject(TopMenuService); // used in templates\n\n constructor() {\n this.telegramAuthService.authenticateIfTelegramWebApp();\n this.router.events\n .pipe(filter((event) => event instanceof NavigationEnd))\n .subscribe((event: NavigationEnd) => {\n let route = this.activatedRoute.firstChild;\n while (route?.firstChild) {\n route = route.firstChild;\n }\n let title = route?.snapshot.data['title'];\n if (title) {\n const spaceType = route?.snapshot?.paramMap?.get('spaceType');\n if (spaceType) {\n title = `${capitalizeFirstLetter(spaceType)} ${title}`;\n }\n }\n this.analyticsService.logEvent('$pageview', {\n page_path: event.urlAfterRedirects,\n title,\n });\n title = title ? `${title} @ Sneat.App` : 'Sneat.App'; // Default title\n this.titleService.setTitle(title);\n });\n }\n}\n\nfunction capitalizeFirstLetter(text: string): string {\n return text.charAt(0).toUpperCase() + text.slice(1);\n}\n"]}
1
+ {"version":3,"file":"base-app.component.js","sourceRoot":"","sources":["../../../../../libs/app/src/lib/base-app.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAEL,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAE9B,MAAM,OAAO,gBAAgB;IAW3B;QAViB,wBAAmB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAClD,WAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;QACxB,mBAAc,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;QACxC,qBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC5C,iBAAY,GAA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WAAW,CAAC,CAAC,gBAAgB;YACtE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAElC,IAAI,CAAC,8BAA8B,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;QAC/D,CAAC,CAAC,CAAC;IACP,CAAC;IAED,gFAAgF;IAChF,kFAAkF;IAClF,+EAA+E;IAC/E,gFAAgF;IAChF,iEAAiE;IACzD,8BAA8B,CAAC,GAAW;QAChD,IAAI,IAAI,CAAC,UAAU,KAAK,eAAe,EAAE,CAAC;YACxC,OAAO;QACT,CAAC;QACD,IACE,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC;YACzB,GAAG,CAAC,UAAU,CAAC,QAAQ,CAAC;YACxB,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,EAC7B,CAAC;YACD,OAAO;QACT,CAAC;QACD,iBAAiB,EAAE,CAAC;IACtB,CAAC;CACF;AAED,SAAS,qBAAqB,CAAC,IAAY;IACzC,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { inject } from '@angular/core';\nimport { Title } from '@angular/platform-browser';\nimport { ActivatedRoute, NavigationEnd, Router } from '@angular/router';\nimport {\n AuthStatus,\n SneatAuthStateService,\n TelegramAuthService,\n} from '@sneat/auth-core';\nimport { AnalyticsService, clearCurrentSpace, TopMenuService } from '@sneat/core';\nimport { filter } from 'rxjs';\n\nexport class BaseAppComponent {\n private readonly telegramAuthService = inject(TelegramAuthService);\n private readonly router = inject(Router);\n private readonly activatedRoute = inject(ActivatedRoute);\n private readonly analyticsService = inject(AnalyticsService);\n private readonly titleService = inject(Title);\n private readonly authStateService = inject(SneatAuthStateService);\n protected readonly topMenuService = inject(TopMenuService); // used in templates\n\n private authStatus?: AuthStatus;\n\n constructor() {\n this.telegramAuthService.authenticateIfTelegramWebApp();\n this.authStateService.authState.subscribe((s) => {\n this.authStatus = s.status;\n });\n this.router.events\n .pipe(filter((event) => event instanceof NavigationEnd))\n .subscribe((event: NavigationEnd) => {\n let route = this.activatedRoute.firstChild;\n while (route?.firstChild) {\n route = route.firstChild;\n }\n let title = route?.snapshot.data['title'];\n if (title) {\n const spaceType = route?.snapshot?.paramMap?.get('spaceType');\n if (spaceType) {\n title = `${capitalizeFirstLetter(spaceType)} ${title}`;\n }\n }\n this.analyticsService.logEvent('$pageview', {\n page_path: event.urlAfterRedirects,\n title,\n });\n title = title ? `${title} @ Sneat.App` : 'Sneat.App'; // Default title\n this.titleService.setTitle(title);\n\n this.forgetCurrentSpaceIfLeftSpaces(event.urlAfterRedirects);\n });\n }\n\n // Keep the persisted current space in sync with where an authenticated user is:\n // once they navigate to a non-space page, forget it so login does not bounce them\n // back to a space they had left. Auth routes are ignored so signing out from a\n // space still restores it; the `authenticated` guard preserves the value during\n // the logged-out login flow so the login page can still read it.\n private forgetCurrentSpaceIfLeftSpaces(url: string): void {\n if (this.authStatus !== 'authenticated') {\n return;\n }\n if (\n url.startsWith('/space/') ||\n url.startsWith('/login') ||\n url.startsWith('/signed-out')\n ) {\n return;\n }\n clearCurrentSpace();\n }\n}\n\nfunction capitalizeFirstLetter(text: string): string {\n return text.charAt(0).toUpperCase() + text.slice(1);\n}\n"]}
@@ -5,6 +5,9 @@ export declare class BaseAppComponent {
5
5
  private readonly activatedRoute;
6
6
  private readonly analyticsService;
7
7
  private readonly titleService;
8
+ private readonly authStateService;
8
9
  protected readonly topMenuService: TopMenuService;
10
+ private authStatus?;
9
11
  constructor();
12
+ private forgetCurrentSpaceIfLeftSpaces;
10
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sneat/app",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },