fix: document fetch

This commit is contained in:
AykutSarac 2023-08-02 19:30:01 +03:00
parent 9b7fc7255f
commit f9bfcf7fb4
No known key found for this signature in database
3 changed files with 6 additions and 6 deletions

View File

@ -217,13 +217,13 @@ export const BottomBar = () => {
</Flex> </Flex>
)} )}
</StyledBottomBarItem> </StyledBottomBarItem>
{(data?.owner_id === user?.id || (!data && user)) && ( {(data?.owner_email === user?.email || (!data && user)) && (
<StyledBottomBarItem onClick={handleSaveJson} disabled={isUpdating}> <StyledBottomBarItem onClick={handleSaveJson} disabled={isUpdating}>
{hasChanges ? <AiOutlineCloudUpload /> : <AiOutlineCloudSync />} {hasChanges ? <AiOutlineCloudUpload /> : <AiOutlineCloudSync />}
{hasChanges ? (query?.json ? "Unsaved Changes" : "Create Document") : "Saved"} {hasChanges ? (query?.json ? "Unsaved Changes" : "Create Document") : "Saved"}
</StyledBottomBarItem> </StyledBottomBarItem>
)} )}
{data?.owner_id === user?.id && ( {data?.owner_email === user?.email && (
<StyledBottomBarItem onClick={setPrivate} disabled={isUpdating}> <StyledBottomBarItem onClick={setPrivate} disabled={isUpdating}>
{isPrivate ? <AiOutlineLock /> : <AiOutlineUnlock />} {isPrivate ? <AiOutlineLock /> : <AiOutlineUnlock />}
{isPrivate ? "Private" : "Public"} {isPrivate ? "Private" : "Public"}

View File

@ -24,13 +24,13 @@ const getFromCloud = async (doc_id: string): Promise<PostgrestSingleResponse<Fil
}; };
const getAllJson = async (): Promise<File[]> => { const getAllJson = async (): Promise<File[]> => {
const userId = useUser.getState().user?.id; const userEmail = useUser.getState().user?.email;
if (!userId) return []; if (!userEmail) return [];
const { data, error } = await supabase const { data, error } = await supabase
.from("document") .from("document")
.select() .select()
.eq("owner_id", userId) .eq("owner_email", userEmail)
.order("created_at", { ascending: false }); .order("created_at", { ascending: false });
if (error) { if (error) {

View File

@ -42,7 +42,7 @@ interface JsonActions {
export type File = { export type File = {
id: string; id: string;
views: number; views: number;
owner_id: string; owner_email: string;
name: string; name: string;
content: string; content: string;
private: boolean; private: boolean;