-
Notifications
You must be signed in to change notification settings - Fork 131
feat: Shell integration with external bridge container apps #3644
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
Draft
ecnivtwelve
wants to merge
18
commits into
master
Choose a base branch
from
feat/shell-release
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
146a4ee
refactor: Moved all logics that're related to shift selection out of …
lethemanh a346dcd
refactor: Implemented new hook and helper functions for shift selecti…
lethemanh 46c91d6
refactor: Implemented unit test for shift selection :recycle:
lethemanh 5bc25de
refactor: Modified folder view component to trigger shift selection :…
lethemanh 98d5e16
refactor: Modified useLongPress to be available with shift selection …
lethemanh ff1f734
fix: Resolve problem when deselect last item by using shift arrow :bug:
lethemanh 32f4f16
refactor: Rename props that're used to interact with file :recycle:
lethemanh ed2fa87
refactor: Change logic to update selected items by using reduce :recy…
lethemanh c7086c6
fix: Resolve sharing link issue :bug:
lethemanh 27d317a
chore: bump version 🔖
rezk2ll 066b323
feat(shell): Add useShell hook to get shell context
ecnivtwelve 126c534
fix(shell): useShell when no provider
ecnivtwelve 10506ac
feat(shell): Show file selection in shell
ecnivtwelve 9e32377
feat(shell): Use shell to open Docs files in Docs
ecnivtwelve fa26c74
Merge branch 'master' into feat/shell-release
ecnivtwelve 6013d0c
chore: Fix lint
ecnivtwelve 6fbbf5f
fix: Error on sharings view
ecnivtwelve f8cf12a
chore: Fix lint issues and refactor code
ecnivtwelve 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| // Imports | ||
| import React, { createContext, useContext, useEffect, useState } from 'react' | ||
| import { useNavigate } from 'react-router-dom' | ||
|
|
||
| import { BarLeft } from 'cozy-bar' | ||
| import type { File } from '@/components/FolderPicker/types' | ||
|
|
||
| // Types | ||
| interface ShellContextType { | ||
| runsInShell: boolean | ||
| setRunsInShell: React.Dispatch<React.SetStateAction<boolean>> | ||
| selectedFile: string | null | ||
| setSelectedFile: React.Dispatch<React.SetStateAction<string | null>> | ||
| openFileInParent: (file: File) => void | ||
| } | ||
|
|
||
| // Context | ||
| const ShellContext = createContext<ShellContextType | undefined>(undefined) | ||
|
|
||
| export const ShellProvider = ({ | ||
| children | ||
| }: { | ||
| children: React.ReactNode | ||
| }): JSX.Element => { | ||
| const navigate = useNavigate() | ||
|
|
||
| const [runsInShell, setRunsInShell] = useState(false) | ||
| const [selectedFile, setSelectedFile] = useState<string | null>(null) | ||
|
|
||
| useEffect(() => { | ||
| if (window.top) { | ||
| window.top.postMessage('loaded', '*') | ||
| } | ||
|
|
||
| window.onmessage = function (e: MessageEvent): void { | ||
| if (e.data == undefined || e.data == null || typeof e.data !== 'string') | ||
| return | ||
| if (e.data === 'inShell:true') { | ||
| setRunsInShell(true) | ||
| } | ||
| if (e.data.startsWith('selectedFile:')) { | ||
| const fileId = e.data.split('selectedFile:')[1].trim() | ||
| setSelectedFile(fileId) | ||
| } | ||
| if (e.data.startsWith('openFolder:')) { | ||
| const folderId = e.data.split('openFolder:')[1].trim() | ||
| navigate(`/folder/${folderId}`) | ||
| } | ||
| } | ||
| }, [navigate]) | ||
|
|
||
| if (runsInShell) { | ||
| const CSS = ` | ||
| .coz-bar-container nav, .coz-bar-container a { | ||
| display: none !important; | ||
| } | ||
|
|
||
| .coz-bar-container button[aria-label="Rechercher"] { | ||
| margin-right: -12px; | ||
| } | ||
| ` | ||
|
|
||
| const style = document.createElement('style') | ||
| style.type = 'text/css' | ||
| style.appendChild(document.createTextNode(CSS)) | ||
| document.head.appendChild(style) | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be done by a new entry / target. |
||
|
|
||
| const openFileInParent = (file: File): void => { | ||
| if ('metadata' in file && window.top) { | ||
| const id = file.metadata.externalId || '' | ||
| window.top.postMessage('openFile:' + id, '*') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who is listening / definning this openFile ? |
||
| } | ||
| } | ||
|
|
||
| const contextValue: ShellContextType = { | ||
| runsInShell, | ||
| setRunsInShell, | ||
| selectedFile, | ||
| setSelectedFile, | ||
| openFileInParent | ||
| } | ||
|
|
||
| return ( | ||
| <ShellContext.Provider value={contextValue}> | ||
| {runsInShell && ( | ||
| <BarLeft> | ||
| <div style={{ width: 12 }}></div> | ||
| </BarLeft> | ||
| )} | ||
|
|
||
| {children} | ||
| </ShellContext.Provider> | ||
| ) | ||
| } | ||
|
|
||
| // Hook | ||
| export const useShell = (): ShellContextType => { | ||
| const context = useContext(ShellContext) | ||
| if (!context) { | ||
| return { | ||
| runsInShell: false, | ||
| setRunsInShell: (): void => { | ||
| return | ||
| }, | ||
| selectedFile: null, | ||
| setSelectedFile: (): void => { | ||
| return | ||
| }, | ||
| openFileInParent: (): void => { | ||
| return | ||
| } | ||
| } | ||
| } | ||
| return context | ||
| } | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
who is the window.top here?