-
Notifications
You must be signed in to change notification settings - Fork 172
Shared links frontend #2890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Shared links frontend #2890
Changes from 23 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
635cde8
connect shared links creation with backend database
Rachelcoll c4c0747
shared links procedure change
Rachelcoll 5b655e0
shared links url change
Rachelcoll 2b99c40
Merge branch 'master' into shared-links-frontend
RichDom2185 91b84e1
delete unnecessary lines
Rachelcoll 5218f9d
Merge branch 'shared-links-frontend' of https://github.com/source-aca…
Rachelcoll a67a6b7
Merge branch 'master' into shared-links-frontend
RichDom2185 b6f036b
Fix format errors
RichDom2185 2315ede
Revert lockfile change
RichDom2185 d133925
Revert TS config change
RichDom2185 0f0fb61
test check
Rachelcoll 76c2178
Merge branch 'shared-links-frontend' of https://github.com/source-aca…
Rachelcoll 0a356ca
format
Rachelcoll 55c81a8
format
Rachelcoll 557d23a
format
Rachelcoll ccb8023
Merge branch 'master' into shared-links-frontend
RichDom2185 91a0a1e
Fix incorrect merge resolution
RichDom2185 8518e65
Add OOP-oriented implementation of encoding and decoding of share lin…
chownces 433c81e
debug and add decoder oop
Rachelcoll bfe97cc
debug and add decoder oop
Rachelcoll b1842b4
Merge branch 'master' into shared-links-frontend
martin-henz 6e7dcc4
remove decoder oop and fix bugs
Rachelcoll 7bd35c8
Merge branch 'master' into shared-links-frontend
martin-henz cf4c625
Merge branch 'master' into shared-links-frontend
martin-henz cc412f0
change request method and fix bugs
Rachelcoll 49537fc
Merge branch 'shared-links-frontend' of https://github.com/source-aca…
Rachelcoll 5618a03
Revert lockfile changes
RichDom2185 fe9eea2
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 d7333da
Merge branch 'master' into shared-links-frontend
RichDom2185 840e5d5
Merge branch 'master' into shared-links-frontend
RichDom2185 cd4760e
Shared links frontend refactor (#2937)
chownces 9b701f0
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 b48948a
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 ecb2063
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 bde45d1
Merge branch 'master' of https://github.com/source-academy/frontend i…
RichDom2185 2cf4672
Merge branch 'master' into shared-links-updated
chownces 59e8106
Remove redundant playground saga test
chownces File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
type ShareLinkState = Partial<{ | ||
chownces marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isFolder: string; | ||
tabs: string; | ||
tabIdx: string; | ||
chap: string; | ||
variant: string; | ||
ext: string; | ||
exec: string; | ||
files: string; | ||
prgrm: string; | ||
}>; | ||
|
||
export default ShareLinkState; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import ShareLinkState from '../ShareLinkState'; | ||
import DecoderDelegate from './delegates/DecoderDelegate'; | ||
|
||
/** | ||
* Decodes the given encodedString with the specified decoder in `decodeWith`. | ||
*/ | ||
class ShareLinkStateDecoder { | ||
encodedString: string; | ||
|
||
constructor(encodedString: string) { | ||
this.encodedString = encodedString; | ||
} | ||
|
||
decodeWith(decoderDelegate: DecoderDelegate): ShareLinkState { | ||
return decoderDelegate.decode(this.encodedString); | ||
} | ||
} | ||
|
||
export default ShareLinkStateDecoder; |
7 changes: 7 additions & 0 deletions
7
src/features/playground/shareLinks/decoder/delegates/DecoderDelegate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import ShareLinkState from '../../ShareLinkState'; | ||
|
||
interface DecoderDelegate { | ||
decode(str: string): ShareLinkState; | ||
} | ||
|
||
export default DecoderDelegate; |
11 changes: 11 additions & 0 deletions
11
src/features/playground/shareLinks/decoder/delegates/JsonDecoderDelegate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import ShareLinkState from '../../ShareLinkState'; | ||
import DecoderDelegate from './DecoderDelegate'; | ||
|
||
class JsonDecoderDelegate implements DecoderDelegate { | ||
decode(str: string): ShareLinkState { | ||
const jsonObject = JSON.parse(str); | ||
return jsonObject.data; | ||
} | ||
} | ||
|
||
export default JsonDecoderDelegate; |
23 changes: 23 additions & 0 deletions
23
src/features/playground/shareLinks/decoder/delegates/UrlParamsDecoderDelegate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IParsedQuery, parseQuery } from 'src/commons/utils/QueryHelper'; | ||
|
||
import ShareLinkState from '../../ShareLinkState'; | ||
import DecoderDelegate from './DecoderDelegate'; | ||
|
||
class UrlParamsDecoderDelegate implements DecoderDelegate { | ||
decode(str: string): ShareLinkState { | ||
const qs: Partial<IParsedQuery> = parseQuery(str); | ||
return { | ||
chap: qs.chap, | ||
exec: qs.exec, | ||
files: qs.files, | ||
isFolder: qs.isFolder, | ||
tabIdx: qs.tabIdx, | ||
tabs: qs.tabs, | ||
variant: qs.variant, | ||
prgrm: qs.prgrm, | ||
ext: qs.ext | ||
}; | ||
} | ||
} | ||
|
||
export default UrlParamsDecoderDelegate; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { FSModule } from 'browserfs/dist/node/core/FS'; | ||
import { compressToEncodedURIComponent } from 'lz-string'; | ||
import qs from 'query-string'; | ||
import { useState } from 'react'; | ||
import { retrieveFilesInWorkspaceAsRecord } from 'src/commons/fileSystem/utils'; | ||
import { useTypedSelector } from 'src/commons/utils/Hooks'; | ||
import { EditorTabState } from 'src/commons/workspace/WorkspaceTypes'; | ||
|
||
import ShareLinkState from '../ShareLinkState'; | ||
|
||
export const useUrlEncoder = () => { | ||
const isFolderModeEnabled = useTypedSelector( | ||
state => state.workspaces.playground.isFolderModeEnabled | ||
); | ||
|
||
const editorTabs = useTypedSelector(state => state.workspaces.playground.editorTabs); | ||
const editorTabFilePaths = editorTabs | ||
.map((editorTab: EditorTabState) => editorTab.filePath) | ||
.filter((filePath): filePath is string => filePath !== undefined); | ||
const activeEditorTabIndex: number | null = useTypedSelector( | ||
state => state.workspaces.playground.activeEditorTabIndex | ||
); | ||
const chapter = useTypedSelector(state => state.workspaces.playground.context.chapter); | ||
const variant = useTypedSelector(state => state.workspaces.playground.context.variant); | ||
const execTime = useTypedSelector(state => state.workspaces.playground.execTime); | ||
const files = useGetFile(); | ||
|
||
const result: ShareLinkState = { | ||
chownces marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isFolder: isFolderModeEnabled.toString(), | ||
files: files.toString(), | ||
tabs: editorTabFilePaths.map(compressToEncodedURIComponent)[0], | ||
tabIdx: activeEditorTabIndex?.toString(), | ||
chap: chapter.toString(), | ||
variant, | ||
ext: 'NONE', | ||
exec: execTime.toString() | ||
}; | ||
|
||
return result; | ||
}; | ||
|
||
const useGetFile = () => { | ||
const fileSystem = useTypedSelector(state => state.fileSystem.inBrowserFileSystem); | ||
const [files, setFiles] = useState<Record<string, string>>({}); | ||
retrieveFilesInWorkspaceAsRecord('playground', fileSystem as FSModule).then(result => { | ||
setFiles(result); | ||
}); | ||
return compressToEncodedURIComponent(qs.stringify(files)); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.