Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aa20d25

Browse files
Merge pull request cangzhang#4 from cangzhang/fix/persist-webview
2 parents ba30678 + 90deb83 commit aa20d25

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

‎src/codingServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class CodingServer {
7272
}
7373

7474
Logger.error(`Error reading sessions: ${e}`);
75-
await keychain.deleteToken(TokenType.AccessToken);
75+
// await keychain.deleteToken(TokenType.AccessToken);
7676
}
7777
}
7878

‎webviews/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from 'styled-components';
44
import { view } from '@risingstack/react-easy-state';
55
import appStore from './store/appStore';
66
import { actions } from './store/constants';
7+
import persistDataHook from './hooks/persistDataHook';
78

89
const LoadingWrapper = styled.div`
910
font-size: 16px;
@@ -31,12 +32,13 @@ function App() {
3132
break;
3233
}
3334
default:
34-
console.log(type, value);
3535
break;
3636
}
3737
});
3838
}, [updateCurrentMR]);
3939

40+
persistDataHook();
41+
4042
if (!currentMR.iid) {
4143
return <LoadingWrapper>Please select an merge request first.</LoadingWrapper>;
4244
}

‎webviews/hooks/persistDataHook.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useEffect, useRef } from 'react';
2+
import { persistData, removeDataPersist } from '../store/appStore';
3+
4+
const persistDataHook = () => {
5+
const effect = useRef(() => {
6+
});
7+
8+
useEffect(() => {
9+
effect.current = persistData();
10+
11+
return () => {
12+
removeDataPersist(effect.current);
13+
};
14+
}, []);
15+
16+
return effect.current;
17+
}
18+
19+
export default persistDataHook;

‎webviews/store/appStore.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
import { store } from '@risingstack/react-easy-state';
1+
import { autoEffect,clearEffect,store } from '@risingstack/react-easy-state';
22
import { IMRWebViewDetail } from '../../src/typings/commonTypes';
33

4+
export const vscode = acquireVsCodeApi();
5+
46
const appStore = store({
5-
currentMR: {} as IMRWebViewDetail,
7+
currentMR: (vscode.getState()?.currentMR||{}) as IMRWebViewDetail,
68
updateCurrentMR(data: IMRWebViewDetail) {
79
appStore.currentMR = data;
810
},
911
});
1012

13+
export const persistData = () =>
14+
autoEffect(() => {
15+
const p = vscode.getState();
16+
vscode.setState({
17+
...p,
18+
currentMR: appStore.currentMR,
19+
});
20+
});
21+
export const removeDataPersist = (e: () => void) => clearEffect(e);
22+
1123
export default appStore;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /