minor improvements

This commit is contained in:
Abhinav 2022-01-24 16:42:23 +05:30
parent 826f9a1b0f
commit b2cac4f629
2 changed files with 18 additions and 13 deletions

View file

@ -17,7 +17,7 @@ import { getData, LS_KEYS } from 'utils/storage/localStorage';
import SubmitButton from './SubmitButton'; import SubmitButton from './SubmitButton';
import MessageDialog from './MessageDialog'; import MessageDialog from './MessageDialog';
import { Collection } from 'types/collection'; import { Collection } from 'types/collection';
import { transformShareURLForHost } from 'utils/collection'; import { appendCollectionKeyToShareURL } from 'utils/collection';
import { Row, Value } from './Container'; import { Row, Value } from './Container';
import { CodeBlock } from './CodeBlock'; import { CodeBlock } from './CodeBlock';
import { ButtonVariant, getVariantColor } from './pages/gallery/LinkButton'; import { ButtonVariant, getVariantColor } from './pages/gallery/LinkButton';
@ -46,7 +46,7 @@ function CollectionShare(props: Props) {
useEffect(() => { useEffect(() => {
const main = async () => { const main = async () => {
if (props.collection?.publicURLs?.[0]?.url) { if (props.collection?.publicURLs?.[0]?.url) {
const t = await transformShareURLForHost( const t = await appendCollectionKeyToShareURL(
props.collection?.publicURLs?.[0]?.url, props.collection?.publicURLs?.[0]?.url,
props.collection.key props.collection.key
); );
@ -92,8 +92,12 @@ function CollectionShare(props: Props) {
try { try {
galleryContext.startLoading(); galleryContext.startLoading();
const publicURL = await createShareableURL(props.collection); const publicURL = await createShareableURL(props.collection);
const sharableURL = await appendCollectionKeyToShareURL(
publicURL.url,
props.collection.key
);
galleryContext.finishLoading(); galleryContext.finishLoading();
setPublicShareUrl(publicURL.url); setPublicShareUrl(sharableURL);
await galleryContext.syncWithRemote(false, true); await galleryContext.syncWithRemote(false, true);
} catch (e) { } catch (e) {
const errorMessage = handleSharingErrors(e); const errorMessage = handleSharingErrors(e);
@ -275,8 +279,7 @@ function CollectionShare(props: Props) {
</Table> </Table>
</> </>
)} )}
{props.collection.sharees?.length === 0 && {props.collection.sharees?.length === 0 && !publicShareUrl && (
props.collection.publicURLs?.length === 0 && (
<div style={{ marginTop: '12px' }}> <div style={{ marginTop: '12px' }}>
{constants.ZERO_SHAREES()} {constants.ZERO_SHAREES()}
</div> </div>

View file

@ -109,7 +109,7 @@ export async function downloadCollection(
} }
} }
export async function transformShareURLForHost( export async function appendCollectionKeyToShareURL(
url: string, url: string,
collectionKey: string collectionKey: string
) { ) {
@ -117,10 +117,12 @@ export async function transformShareURLForHost(
if (!url) { if (!url) {
return null; return null;
} }
const host = window.location.host;
const sharableURL = new URL(url); const sharableURL = new URL(url);
if (process.env.NODE_ENV === 'development') {
const host = window.location.host;
sharableURL.host = host; sharableURL.host = host;
sharableURL.pathname = '/shared-album'; sharableURL.pathname = '/shared-album';
}
sharableURL.hash = await worker.toHex(collectionKey); sharableURL.hash = await worker.toHex(collectionKey);
sharableURL.protocol = 'http'; sharableURL.protocol = 'http';
return sharableURL.href; return sharableURL.href;