Skip to content

Commit

Permalink
👨🏻‍🎓🌞 ↝ Adding more USER directory components, appears that connectio…
Browse files Browse the repository at this point in the history
…n/sb speed is the issue for #26
  • Loading branch information
Gizmotronn committed Feb 27, 2023
1 parent bb76261 commit 65319a7
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/NavigationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function NavigationCard(){
</svg>
<span className="hidden md:block">Home</span>
</Link>
<Link href="/posts/profile/friends" className={pathname === '/profile/friends' ? activeElementClasses : nonActiveElementClasses}>
<Link href="/posts/user/cebdc7a2-d8af-45b3-b37f-80f328ff54d6" className={pathname === '/profile/friends' ? activeElementClasses : nonActiveElementClasses}>
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M18 18.72a9.094 9.094 0 003.741-.479 3 3 0 00-4.682-2.72m.94 3.198l.001.031c0 .225-.012.447-.037.666A11.944 11.944 0 0112 21c-2.17 0-4.207-.576-5.963-1.584A6.062 6.062 0 016 18.719m12 0a5.971 5.971 0 00-.941-3.197m0 0A5.995 5.995 0 0012 12.75a5.995 5.995 0 00-5.058 2.772m0 0a3 3 0 00-4.681 2.72 8.986 8.986 0 003.74.477m.94-3.197a5.971 5.971 0 00-.94 3.197M15 6.75a3 3 0 11-6 0 3 3 0 016 0zm6 3a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0zm-13.5 0a2.25 2.25 0 11-4.5 0 2.25 2.25 0 014.5 0z" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion components/Planets/PlanetAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function PlanetAvatar ({ uid, url, size, /*onUpload*/ }: {
const [uploading, setUploading] = useState(false);

const supabase = useSupabaseClient<Database>();
const [avatarUrl, setAvatarUrl] = useState<Planets['avatar_url']>(null);
const [avatarUrl, setAvatarUrl] = useState<Planets['avatar_url']>(null); // I believe this is causing the invalid uuid syntax error

useEffect(() => {
if (url) downloadImage(url);
Expand Down
8 changes: 4 additions & 4 deletions components/PostFormCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function PostFormCard ( { onPost } ) {
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" strokeWidth={1.5} stroke="currentColor" className="w-6 h-6">
<path strokeLinecap="round" strokeLinejoin="round" d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13" />
</svg>
<span className="hidden md:block">Media / File</span>
<span className="hidden md:block">Media</span>
</label>
</div>
<div>
Expand All @@ -113,7 +113,7 @@ export default function PostFormCard ( { onPost } ) {
<path strokeLinecap="round" strokeLinejoin="round" d="M15 10.5a3 3 0 11-6 0 3 3 0 016 0z" />
<path strokeLinecap="round" strokeLinejoin="round" d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1115 0z" />
</svg>
<span className="hidden md:block">Check in</span>
<span className="hidden md:block">Checkin</span>
</button>
</div>
<div>
Expand All @@ -132,7 +132,7 @@ export default function PostFormCard ( { onPost } ) {
);
}

export function PlanetTagPostForm ( { onPost } ) {
/*export function PlanetTagPostForm ( { onPost } ) {
const supabase = useSupabaseClient();
const [content, setContent] = useState('');
const session = useSession();
Expand All @@ -143,4 +143,4 @@ export function PlanetTagPostForm ( { onPost } ) {
const [avatar_url, setAvatarUrl] = useState<Profiles['avatar_url']>();
const [planet, setPlanet] = useState('');
}
}*/
85 changes: 85 additions & 0 deletions components/User/UserAvatar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, { useState, useEffect } from "react";

import { useSupabaseClient } from "@supabase/auth-helpers-react";
import { Database } from "../../utils/database.types";

type Profiles = Database['public']['Tables']['profiles']['Row'];

export default function UserAvatar ({
uid,
url,
size
}: {
uid: string,
url: Profiles['avatar_url']
size: number
}) {
const supabase = useSupabaseClient<Database>();
const [avatarUrl, setAvatarUrl] = useState<Profiles['avatar_url']>(null);

const [uploading, setUploading] = useState(false);
let width = 'w-12';

useEffect(() => {
if (url) downloadImage(url);
}, [url]);

async function downloadImage(path: string) { // Get the avatar url from Supabase for the user (if it exists)
try {
const { data, error } = await supabase.storage.from('avatars').download(path);
if (error) {
throw error;
};
const url = URL.createObjectURL(data);
setAvatarUrl(url);
} catch (error) {
console.log('Error downloading image: ', error)
}
};
};

export function UserPostAvatar ({
url,
size,
}: {
url: Profiles['avatar_url']
size: number
}) {
const supabase = useSupabaseClient<Database>();
const [avatarUrl, setAvatarUrl] = useState<Profiles['avatar_url']>(null);

const [uploading, setUploading] = useState(false);
let width = 'w-12';

useEffect(() => {
if (url) downloadImage(url);
}, [url]);

async function downloadImage(path: string) { // Get the avatar url from Supabase for the user (if it exists)
try {
const { data, error } = await supabase.storage.from('avatars').download(path);
if (error) {
throw error;
};
const url = URL.createObjectURL(data);
setAvatarUrl(url);
} catch (error) {
console.log('Error downloading image: ', error)
}
};

return (
<div className="${width} rounded-lg overflow-hidden">
{avatarUrl ? (
<img
src={avatarUrl}
alt='Avatar'
className="avatar image"
style={{ height: size, width: size }}
/>
) : (
<div className="avatar no-image" style={{ height: size, width: size }} />
)}
</div>
);
}
6 changes: 5 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useSession } from "@supabase/auth-helpers-react";
import Link from "next/link";
import React from "react";

export default function Home() {
const session = useSession();

return (
<div>Entry point to client</div>
<>
<div>Entry point to client</div>
<Link href='/posts'>Test</Link>
</>
)
}
3 changes: 0 additions & 3 deletions pages/posts/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { useRouter } from "next/router";
import Layout from "../../components/Layout";
import Card from "../../components/Card";

import { Database } from "../../utils/database.types";
import { useSupabaseClient, useSession } from "@supabase/auth-helpers-react";
//import AnomalyContextProvider from '../../context/AnomalyContext';
import { UserContext, UserContextProvider } from "../../context/UserContext";
Expand All @@ -14,8 +13,6 @@ import ProfileTabs from "../../components/Posts/ProfileNavigation";
import UserCoverImage from "../../components/Cover";
import { PostCardAvatar } from "../../components/AccountAvatar";

type Profiles = Database['public']['Tables']['profiles']['Row'];

export default function UserPage () {
const supabase = useSupabaseClient();
const session = useSession();
Expand Down

0 comments on commit 65319a7

Please sign in to comment.