Skip to content

Commit

Permalink
fix reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov committed Mar 20, 2024
1 parent f646563 commit 5eb1cd3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
23 changes: 15 additions & 8 deletions src/components/shared/Widget/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,25 @@ export default class WidgetsGrid extends Vue {
private breakpoint: BreakpointKey = BreakpointKey.md;
private updateResponsiveLayouts = debounce(this.saveLayouts, 250);
public layouts: ResponsiveLayouts = cloneDeep(EMPTY_LAYOUTS);
@Watch('layouts', { deep: true })
private onLayoutsUpdate(): void {
private onLayoutsUpdate = debounce(this.checkLayoutUpdate, 250, { leading: false });
public layout: Layout = [];
@Watch('layout', { deep: true })
private onLayoutUpdate = debounce(this.checkLayoutsUpdate, 250, { leading: false });
private checkLayoutUpdate(): void {
if (this.responsiveLayout && this.shouldUpdate) {
this.layout = cloneDeep(this.responsiveLayout) as Layout;

Check warning on line 151 in src/components/shared/Widget/Grid.vue

View check run for this annotation

Soramitsu-Sonar-PR-decoration / polkaswap-exchange-web Sonarqube Results

src/components/shared/Widget/Grid.vue#L151

This assertion is unnecessary since it does not change the type of the expression.
}
}
public layout: Layout = [];
@Watch('layout', { deep: true })
private onLayoutUpdate(): void {
private checkLayoutsUpdate(): void {
if (this.shouldUpdate) {
this.updateResponsiveLayouts({ ...this.layouts, [this.breakpoint]: this.gridLayout });
this.saveLayouts({ ...this.layouts, [this.breakpoint]: this.gridLayout });
}
}
Expand Down Expand Up @@ -188,9 +192,12 @@ export default class WidgetsGrid extends Vue {
this.init();
}
private init(): void {
private async init(): Promise<void> {
// important to reset layout & layouts to initial state
this.layout = [];
this.layouts = cloneDeep(EMPTY_LAYOUTS);
// to update lib component inner models to initial states
await this.$nextTick();
const storedLayouts = layoutsStorage.get(this.gridId);
Expand Down
6 changes: 3 additions & 3 deletions src/views/Swap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export default class Swap extends Mixins(mixins.LoadingMixin, TranslationMixin,
readonly DefaultLayouts: ResponsiveLayouts = {
lg: [
{ x: 0, y: 0, w: 6, h: 20, minW: 4, minH: 20, i: SwapWidgets.Form },
{ x: 0, y: 20, w: 6, h: 4, minW: 4, minH: 4, i: SwapWidgets.Customise },
{ x: 0, y: 24, w: 6, h: 4, minW: 4, minH: 4, i: SwapWidgets.Distribution },
{ x: 6, y: 0, w: 9, h: 24, minW: 4, minH: 20, i: SwapWidgets.Chart },
{ x: 0, y: 20, w: 6, h: 4, minW: 4, minH: 4, i: SwapWidgets.Distribution },
{ x: 6, y: 0, w: 9, h: 20, minW: 4, minH: 20, i: SwapWidgets.Chart },
{ x: 6, y: 20, w: 6, h: 4, minW: 4, minH: 4, i: SwapWidgets.Customise },
{ x: 15, y: 0, w: 9, h: 24, minW: 4, minH: 24, i: SwapWidgets.Transactions },
],
md: [
Expand Down

0 comments on commit 5eb1cd3

Please sign in to comment.