Skip to content

Commit

Permalink
Merge pull request #1045 from abdelrhman-arnos/feature/reopen-closed-…
Browse files Browse the repository at this point in the history
…tabs-999

Feature/reopen closed tabs 999
  • Loading branch information
imolorhe committed Nov 3, 2019
2 parents b8a9b29 + 0f2beb4 commit b2c3dac
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,12 @@
{{ 'CLOSE_OTHER_WINDOWS_TEXT' | translate }}
</span>
</ng-template>
<ng-template *ngIf="(closedWindows?.length)" contextMenuItem (execute)="reopenClosedTab()">
<span class="menu-icon">
<clr-icon shape="circle" class="is-solid"></clr-icon>
</span>
<span class="menu-text">
{{ 'REOPEN_CLOSED_WINDOW_TEXT' | translate }}
</span>
</ng-template>
</context-menu>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class WindowSwitcherComponent implements OnInit {

@Input() windows = {};
@Input() windowIds = [];
@Input() closedWindows = [];
@Input() activeWindowId = '';
@Input() isElectron = false;
@Output() activeWindowChange = new EventEmitter();
Expand Down Expand Up @@ -87,6 +88,10 @@ export class WindowSwitcherComponent implements OnInit {
this.duplicateWindowChange.next(windowId);
}

reopenClosedTab() {
this.reopenClosedWindowChange.emit();
}

log(str) {
debug.log(str);
}
Expand Down
1 change: 1 addition & 0 deletions src/app/containers/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
[windows]="windows"
[windowIds] = "windowIds"
[activeWindowId]="activeWindowId"
[closedWindows]="closedWindows"
[isElectron]="isElectron"
(newWindowChange)="newWindow()"
(activeWindowChange)="setActiveWindow($event)"
Expand Down
2 changes: 2 additions & 0 deletions src/app/containers/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class AppComponent implements OnDestroy {

windowIds = [];
windows = {};
closedWindows = [];
activeWindowId = '';
isElectron = isElectron;
isWebApp = config.isWebApp;
Expand Down Expand Up @@ -129,6 +130,7 @@ export class AppComponent implements OnDestroy {
.subscribe(data => {
this.windows = data.windows;
this.windowIds = Object.keys(data.windows);
this.closedWindows = data.local.closedWindows;
this.showDonationAlert = data.donation.showAlert;

this.showImportCurlDialog = data.windowsMeta.showImportCurlDialog;
Expand Down
6 changes: 4 additions & 2 deletions src/app/effects/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class WindowsEffects {
return { closedWindows: state.local.closedWindows, windows: state.windows, windowIds: state.windowsMeta.windowIds, action };
}),
switchMap(data => {
const lastClosedWindow = data.closedWindows.pop();
const lastClosedWindow = data.closedWindows[data.closedWindows.length - 1];
if (!lastClosedWindow || !lastClosedWindow.windowId) {
return observableEmpty();
}
Expand All @@ -74,8 +74,10 @@ export class WindowsEffects {

windows[lastClosedWindowId] = lastClosedWindow;
this.store.dispatch(new windowActions.SetWindowsAction(Object.values(windows)));
this.windowService.setupWindow(lastClosedWindowId);
const newWindowIds = [ ...data.windowIds, lastClosedWindowId ];
return observableOf(new windowsMetaActions.SetWindowIdsAction({ ids: newWindowIds }));
this.store.dispatch(new windowsMetaActions.SetWindowIdsAction({ ids: newWindowIds }));
return observableOf(new windowsMetaActions.SetActiveWindowIdAction({ windowId: lastClosedWindowId }));
}),
tap(() => {
this.store.dispatch(new localActions.PopFromClosedWindowsAction());
Expand Down
9 changes: 7 additions & 2 deletions src/app/reducers/local/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import * as local from '../../actions/local/local';

const MAX_CLOSED_WINDOWS_LENGTH = 50;

export interface State {
closedWindows: any[];
}
Expand All @@ -11,14 +13,17 @@ const initialState: State = {
};

export function localReducer(state = initialState, action: local.Action): State {
const len = state.closedWindows.length;
switch (action.type) {
case local.PUSH_CLOSED_WINDOW_TO_LOCAL:
return {
...state,
closedWindows: [ ...state.closedWindows, action.payload.window ],
closedWindows: len === MAX_CLOSED_WINDOWS_LENGTH ?
[ ...state.closedWindows.slice(1), action.payload.window ] :
[ ...state.closedWindows, action.payload.window ],

};
case local.POP_FROM_CLOSED_WINDOWS:
const len = state.closedWindows.length;
return {
...state,
closedWindows: state.closedWindows.filter((_, i) => i < len - 1),
Expand Down
13 changes: 6 additions & 7 deletions src/app/reducers/windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function windows(reducer: ActionReducer<any>) {
return function(state = initialState, action: any) {

const _state = Object.assign({}, state);
let _windowState = _state[action.windowId];
const _windowState = _state[action.windowId];

switch (action.type) {
case windowsActions.ADD_WINDOW:
Expand All @@ -72,16 +72,15 @@ export function windows(reducer: ActionReducer<any>) {
const _windows = action.payload;

const newWindowsState = {};
_windows.forEach(window => {
_windows.forEach((window: fromRoot.PerWindowState) => {
const windowKey = window.windowId;
const windowTitle = window.title;
// const windowTitle = window.layout.title;

// Using JSON.parse and JSON.stringify instead of Object.assign for deep cloning
_windowState = JSON.parse(JSON.stringify(initWindowState));
_windowState.windowId = windowKey;
_windowState.layout.title = _windowState.layout.title || windowTitle;
// _windowState = JSON.parse(JSON.stringify(initWindowState));
// _windowState.windowId = windowKey;

newWindowsState[windowKey] = { ..._windowState };
newWindowsState[windowKey] = { ...window };
});

return newWindowsState;
Expand Down
2 changes: 1 addition & 1 deletion src/app/services/window.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class WindowService {
/**
* Carry out any necessary house cleaning tasks.
*/
private setupWindow(windowId) {
setupWindow(windowId) {
this.store.dispatch(new queryActions.SetSubscriptionResponseListAction(windowId, { list: [] }));
this.store.dispatch(new queryActions.StopSubscriptionAction(windowId));
this.store.dispatch(new streamActions.StopStreamClientAction(windowId));
Expand Down

0 comments on commit b2c3dac

Please sign in to comment.