Skip to content

Commit

Permalink
Merge pull request #1769 from snypy/fixes-snippet-loading
Browse files Browse the repository at this point in the history
Fixes snippet loading when switching scopes
  • Loading branch information
nezhar authored Dec 18, 2022
2 parents 339cf76 + ca1aaaf commit d91ecea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 40 deletions.
12 changes: 10 additions & 2 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,21 @@ const DEFAULT_PERFECT_SCROLLBAR_CONFIG: PerfectScrollbarConfigInterface = {

const appRoutes: Routes = [
{
path: 'dashboard',
path: 'user',
component: BaseComponent,
children: [],
data: {
scope: 'user',
},
},
{
path: 'global',
component: BaseComponent,
children: [],
data: {
scope: 'global',
},
},
{
path: 'team/:id',
component: BaseComponent,
Expand All @@ -113,7 +121,7 @@ const appRoutes: Routes = [
},
{
path: '',
redirectTo: 'dashboard',
redirectTo: 'user',
pathMatch: 'full',
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/view-switch/view-switch.component.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div>
<span routerLink="/dashboard" class="user" (click)="loadUser()">
<span routerLink="/user" class="user">
<fa-icon icon="user"></fa-icon>
</span>
<span routerLink="/dashboard" class="user visually" (click)="loadGlobal()">
<span routerLink="/global" class="user">
<fa-icon icon="globe"></fa-icon>
</span>
</div>
9 changes: 2 additions & 7 deletions src/app/components/view-switch/view-switch.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import { HttpClientModule } from '@angular/common/http';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { NgxsModule } from '@ngxs/store';
import { ToastrModule } from 'ngx-toastr';
import { ActiveFilterService } from '../../services/navigation/activeFilter.service';
import { AuthResource } from '../../services/resources/auth.resource';
import { ViewSwitchComponent } from './view-switch.component';

describe('ViewSwitchComponent', () => {
Expand All @@ -13,8 +8,8 @@ describe('ViewSwitchComponent', () => {
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ViewSwitchComponent],
imports: [NgxsModule.forRoot(), HttpClientModule, ToastrModule.forRoot({})],
providers: [AuthResource, ActiveFilterService],
imports: [],
providers: [],
}).compileComponents();
}));

Expand Down
29 changes: 1 addition & 28 deletions src/app/components/view-switch/view-switch.component.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,8 @@
import { Component } from '@angular/core';
import { Store } from '@ngxs/store';
import { ActiveFilterService } from '../../services/navigation/activeFilter.service';
import { AuthResource } from '../../services/resources/auth.resource';
import { UpdateScope } from '../../state/scope/scope.actions';

@Component({
selector: 'app-view-switch',
templateUrl: './view-switch.component.html',
styleUrls: ['./view-switch.component.scss'],
})
export class ViewSwitchComponent {
constructor(private store: Store, private authResource: AuthResource, private activeFilterService: ActiveFilterService) {}

loadUser(): void {
console.log('Loading user!');
this.activeFilterService.updateFilter('main', 'all', false);
this.store.dispatch(
new UpdateScope({
area: 'user',
value: this.authResource.currentUser,
})
);
}

loadGlobal(): void {
console.log('Loading global!');
this.store.dispatch(
new UpdateScope({
area: 'global',
value: null,
})
);
}
}
export class ViewSwitchComponent {}
5 changes: 4 additions & 1 deletion src/app/layout/base/base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class BaseComponent implements OnInit, OnDestroy {
/**
* Refresh snippets on scope changes
*/
this.scopeSubscription = this.scope$.subscribe((scope: ScopeModel) => {
this.scopeSubscription = this.scope$.pipe(skip(1)).subscribe((scope: ScopeModel) => {
if (scope && scope.area) {
this.store.dispatch(new UpdateSnippets());
this.store.dispatch(new UpdateLabels());
Expand Down Expand Up @@ -88,6 +88,9 @@ export class BaseComponent implements OnInit, OnDestroy {
this.store.dispatch(new UpdateScope({ area: 'user', value: this.authResource.currentUser }));
break;
}
case 'global': {
this.store.dispatch(new UpdateScope({ area: 'global', value: null }));
}
default: {
this.store.dispatch(new UpdateScope({ area: null, value: null }));
break;
Expand Down

0 comments on commit d91ecea

Please sign in to comment.