Skip to content

Commit 6e7dcc4

Browse files
committed
remove decoder oop and fix bugs
1 parent b1842b4 commit 6e7dcc4

File tree

13 files changed

+38
-93
lines changed

13 files changed

+38
-93
lines changed

src/commons/controlBar/ControlBarShareButton.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type StateProps = {
2222
shortURL?: string;
2323
key: string;
2424
isSicp?: boolean;
25-
programConfig: Partial<ShareLinkState>;
25+
programConfig: ShareLinkState;
2626
};
2727

2828
type State = {
@@ -39,6 +39,7 @@ export class ControlBarShareButton extends React.PureComponent<ControlBarShareBu
3939
this.selectShareInputText = this.selectShareInputText.bind(this);
4040
this.handleChange = this.handleChange.bind(this);
4141
this.toggleButton = this.toggleButton.bind(this);
42+
this.fetchUUID = this.fetchUUID.bind(this);
4243
this.shareInputElem = React.createRef();
4344
this.state = { keyword: '', isLoading: false, isSuccess: false };
4445
}
@@ -53,7 +54,7 @@ export class ControlBarShareButton extends React.PureComponent<ControlBarShareBu
5354

5455
handleKeyDown = (event: any) => {
5556
if (event.key === 'Enter' && event.ctrlKey) {
56-
// console.log('Ctrl+Enter pressed!');
57+
// press Ctrl+Enter to generate and copy new share link directly
5758
this.setState({ keyword: 'Test' });
5859
this.props.handleShortenURL(this.state.keyword);
5960
this.setState({ isLoading: true });
@@ -144,7 +145,6 @@ export class ControlBarShareButton extends React.PureComponent<ControlBarShareBu
144145
}
145146

146147
// reset state
147-
// this.props.handleUpdateShortURL('');
148148
this.setState({ keyword: '', isLoading: false, isSuccess: false });
149149
}
150150

@@ -178,11 +178,11 @@ export class ControlBarShareButton extends React.PureComponent<ControlBarShareBu
178178
})
179179
.then(resp => {
180180
this.setState({
181-
// seems like there's no frontend url env variavle, should be replaced by frontend server accordingly
181+
// seems like there's no frontend url env variable, should be replaced by frontend server accordingly
182182
keyword: `http://localhost:8000/playground/share/` + resp.uuid
183183
});
184184
this.setState({ isLoading: true, isSuccess: true });
185185
})
186-
.catch(err => showWarningMessage('fail to generate url!' + err));
186+
.catch(err => showWarningMessage('Fail to generate url! Error: ' + err));
187187
}
188188
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type ShareLinkState = {
1+
type ShareLinkState = Partial<{
22
isFolder: string;
33
tabs: string;
44
tabIdx: string;
@@ -8,6 +8,6 @@ type ShareLinkState = {
88
exec: string;
99
files: string;
1010
prgrm: string;
11-
};
11+
}>;
1212

1313
export default ShareLinkState;

src/features/playground/shareLinks/decoder/Decoder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ShareLinkStateDecoder {
1111
this.encodedString = encodedString;
1212
}
1313

14-
decodeWith(decoderDelegate: DecoderDelegate): Partial<ShareLinkState> {
14+
decodeWith(decoderDelegate: DecoderDelegate): ShareLinkState {
1515
return decoderDelegate.decode(this.encodedString);
1616
}
1717
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ShareLinkState from '../../ShareLinkState';
22

33
interface DecoderDelegate {
4-
decode(str: string): Partial<ShareLinkState>;
4+
decode(str: string): ShareLinkState;
55
}
66

77
export default DecoderDelegate;

src/features/playground/shareLinks/decoder/delegates/JsonDecoderDelegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ShareLinkState from '../../ShareLinkState';
22
import DecoderDelegate from './DecoderDelegate';
33

44
class JsonDecoderDelegate implements DecoderDelegate {
5-
decode(str: string): Partial<ShareLinkState> {
5+
decode(str: string): ShareLinkState {
66
const jsonObject = JSON.parse(str);
77
return jsonObject.data;
88
}

src/features/playground/shareLinks/decoder/delegates/UrlParamsDecoderDelegate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ShareLinkState from '../../ShareLinkState';
44
import DecoderDelegate from './DecoderDelegate';
55

66
class UrlParamsDecoderDelegate implements DecoderDelegate {
7-
decode(str: string): Partial<ShareLinkState> {
7+
decode(str: string): ShareLinkState {
88
const qs: Partial<IParsedQuery> = parseQuery(str);
99
return {
1010
chap: qs.chap,

src/features/playground/shareLinks/encoder/Encoder.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/features/playground/shareLinks/encoder/URLEncoder.tsx renamed to src/features/playground/shareLinks/encoder/Encoder.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EditorTabState } from 'src/commons/workspace/WorkspaceTypes';
88

99
import ShareLinkState from '../ShareLinkState';
1010

11-
export const useURLEncoder = () => {
11+
export const useUrlEncoder = () => {
1212
const isFolderModeEnabled = useTypedSelector(
1313
state => state.workspaces.playground.isFolderModeEnabled
1414
);
@@ -23,11 +23,11 @@ export const useURLEncoder = () => {
2323
const chapter = useTypedSelector(state => state.workspaces.playground.context.chapter);
2424
const variant = useTypedSelector(state => state.workspaces.playground.context.variant);
2525
const execTime = useTypedSelector(state => state.workspaces.playground.execTime);
26-
const fileSystem = useGetFileSystem();
26+
const files = useGetFile();
2727

28-
const result: Partial<ShareLinkState> = {
28+
const result: ShareLinkState = {
2929
isFolder: isFolderModeEnabled.toString(),
30-
files: useGetFile(fileSystem).toString(),
30+
files: files.toString(),
3131
tabs: editorTabFilePaths.map(compressToEncodedURIComponent)[0],
3232
tabIdx: activeEditorTabIndex?.toString(),
3333
chap: chapter.toString(),
@@ -39,14 +39,10 @@ export const useURLEncoder = () => {
3939
return result;
4040
};
4141

42-
const useGetFileSystem = () => {
42+
const useGetFile = () => {
4343
const fileSystem = useTypedSelector(state => state.fileSystem.inBrowserFileSystem);
44-
return fileSystem as FSModule;
45-
};
46-
47-
const useGetFile = (fileSystem: FSModule) => {
4844
const [files, setFiles] = useState<Record<string, string>>({});
49-
retrieveFilesInWorkspaceAsRecord('playground', fileSystem).then(result => {
45+
retrieveFilesInWorkspaceAsRecord('playground', fileSystem as FSModule).then(result => {
5046
setFiles(result);
5147
});
5248
return compressToEncodedURIComponent(qs.stringify(files));

src/features/playground/shareLinks/encoder/delegates/EncoderDelegate.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/features/playground/shareLinks/encoder/delegates/JsonEncoderDelegate.tsx

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)