1
Fork 0

Only load sidebar shares if authorized

This commit is contained in:
viktorstrate 2021-05-20 12:21:45 +02:00
parent 66b7588564
commit 15a43637b6
No known key found for this signature in database
GPG Key ID: 3F855605109C1E8A
1 changed files with 20 additions and 12 deletions

View File

@ -1,5 +1,5 @@
import React, { useState } from 'react'
import { useMutation, useQuery, gql } from '@apollo/client'
import React, { useEffect, useState } from 'react'
import { useMutation, useQuery, gql, useLazyQuery } from '@apollo/client'
import {
Table,
Button,
@ -37,6 +37,7 @@ import {
sidebarGetAlbumShares,
sidebarGetAlbumSharesVariables,
} from './__generated__/sidebarGetAlbumShares'
import { authToken } from '../../helpers/authentication'
const SHARE_PHOTO_QUERY = gql`
query sidebarGetPhotoShares($id: ID!) {
@ -304,16 +305,13 @@ type SidebarSharePhotoProps = {
export const SidebarPhotoShare = ({ id }: SidebarSharePhotoProps) => {
const { t } = useTranslation()
const {
loading: queryLoading,
error: sharesError,
data: sharesData,
} = useQuery<sidebarGetPhotoShares, sidebarGetPhotoSharesVariables>(
SHARE_PHOTO_QUERY,
{
variables: { id },
}
)
const [
loadShares,
{ loading: queryLoading, error: sharesError, data: sharesData },
] =
useLazyQuery<sidebarGetPhotoShares, sidebarGetPhotoSharesVariables>(
SHARE_PHOTO_QUERY
)
const [sharePhoto, { loading: mutationLoading }] = useMutation<
sidebarPhotoAddShare,
@ -322,6 +320,16 @@ export const SidebarPhotoShare = ({ id }: SidebarSharePhotoProps) => {
refetchQueries: [{ query: SHARE_PHOTO_QUERY, variables: { id } }],
})
useEffect(() => {
if (authToken()) {
loadShares({
variables: {
id,
},
})
}
}, [])
const loading = queryLoading || mutationLoading
if (sharesError) {