-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Open note inside public repository
The opening of the notes is subtle. The note is always opened in the instance of the note creator. This is especially true for shared notes or notes in shared folders. In this case, you need to contact the cozy-stack to find out where to open it. As this can take a little time, we use a redirection page rather than pre-calculating all the links when a folder is displayed
- Loading branch information
Showing
10 changed files
with
287 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,68 @@ | ||
import React, { FC, useEffect, useState } from 'react' | ||
import { useParams } from 'react-router-dom' | ||
|
||
import { useClient } from 'cozy-client' | ||
import { fetchURL } from 'cozy-client/dist/models/note' | ||
import Empty from 'cozy-ui/transpiled/react/Empty' | ||
import Icon from 'cozy-ui/transpiled/react/Icon' | ||
import SadCozyIcon from 'cozy-ui/transpiled/react/Icons/SadCozy' | ||
import Spinner from 'cozy-ui/transpiled/react/Spinner' | ||
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n' | ||
|
||
import { joinPath } from 'lib/path' | ||
import { DummyLayout } from 'modules/layout/DummyLayout' | ||
|
||
const PublicNoteRedirect: FC = () => { | ||
const { t } = useI18n() | ||
const { fileId } = useParams() | ||
const client = useClient() | ||
|
||
const [noteUrl, setNoteUrl] = useState<string | null>(null) | ||
const [fetchStatus, setFetchStatus] = useState< | ||
'failed' | 'loading' | 'pending' | 'loaded' | ||
>('pending') | ||
|
||
useEffect(() => { | ||
const fetchNoteUrl = async (fileId: string): Promise<void> => { | ||
setFetchStatus('loading') | ||
try { | ||
const url = await fetchURL( | ||
client, | ||
{ | ||
id: fileId | ||
}, | ||
{ | ||
pathname: joinPath(location.pathname, '') | ||
} | ||
) | ||
setNoteUrl(url) | ||
setFetchStatus('loaded') | ||
} catch (error) { | ||
setFetchStatus('failed') | ||
} | ||
} | ||
|
||
if (fileId) { | ||
void fetchNoteUrl(fileId) | ||
} | ||
}, [fileId, client]) | ||
|
||
if (noteUrl) { | ||
window.location.href = noteUrl | ||
} | ||
|
||
return ( | ||
<DummyLayout> | ||
{fetchStatus === 'failed' && ( | ||
<Empty | ||
icon={<Icon icon={SadCozyIcon} color="var(--primaryColor)" />} | ||
title={t('PublicNoteRedirect.error.title')} | ||
text={t('PublicNoteRedirect.error.subtitle')} | ||
/> | ||
)} | ||
{fetchStatus !== 'failed' && <Spinner size="xxlarge" middle noMargin />} | ||
</DummyLayout> | ||
) | ||
} | ||
|
||
export { PublicNoteRedirect } |
This file contains 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 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 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.