Skip to content

Commit

Permalink
πŸ’ŽπŸ›Ή ↝ New planet data added from table, found issues in #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Gizmotronn committed Feb 26, 2023
1 parent 7cd00b1 commit 7315f94
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/NavigationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function NavigationCard(){
</svg>
<span className="hidden md:block">Saved posts</span>
</Link>
<Link href="/planets/cebdc7a2-d8af-45b3-b37f-80f328ff54d6" className={pathname === '/notifications' ? activeElementClasses : nonActiveElementClasses}> {/* For testing -> final should be /posts/notifications */}
<Link href="/planets/fdd401bf-3925-49ba-a155-4c3dba8dd93f" className={pathname === '/notifications' ? activeElementClasses : nonActiveElementClasses}> {/* For testing -> final should be /posts/notifications */}
<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="M14.857 17.082a23.848 23.848 0 005.454-1.31A8.967 8.967 0 0118 9.75v-.7V9A6 6 0 006 9v.75a8.967 8.967 0 01-2.312 6.022c1.733.64 3.56 1.085 5.455 1.31m5.714 0a24.255 24.255 0 01-5.714 0m5.714 0a3 3 0 11-5.714 0" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion components/Planets/PlanetNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function PlanetTabs ({ planetId, activeTab }) {
</svg>
<span className="hidden sm:block">Datasets</span>
</Link>
<Link href={`/planets/${planetId}/refs`} className={activeTab === 'refs' ? activeTabClasses : tabClasses}> {/* Posts that mention/use the planetId */}
<Link href={`/planets/${planetId}/data`} className={activeTab === 'refs' ? activeTabClasses : tabClasses}> {/* Posts that mention/use the planetId */}
<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="M9.568 3H5.25A2.25 2.25 0 003 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 005.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 009.568 3z" />
<path strokeLinecap="round" strokeLinejoin="round" d="M6 6h.008v.008H6V6z" />
Expand Down
39 changes: 36 additions & 3 deletions pages/planets/planet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useRouter } from "next/router";

import Layout, { ProfileLayout } from "../../components/Layout";
import Card from "../../components/Card";
import { useSupabaseClient } from "@supabase/auth-helpers-react";
import { useSession, useSupabaseClient } from "@supabase/auth-helpers-react";
import PlanetCoverImage from "../../components/Planets/Cover";
import PlanetAvatar from "../../components/Planets/PlanetAvatar";
import PlanetTabs from "../../components/Planets/PlanetNavigation";
Expand All @@ -18,22 +18,46 @@ export default function PlanetPage () {

const supabase = useSupabaseClient();
const [planet, setPlanet] = useState(null);
const [planetOwner, setPlanetOwner] = useState(null);

const session = useSession();
const [profile, setProfile] = useState(null);

useEffect(() => {
if (!planetId) { return; }
fetchPlanet();
})

function fetchPlanet () {
supabase.from('planets')
.select()
.select("*")
.eq('id', planetId) // How should the ID be generated -> similar to how `userId` is generated? Combination of user + org + article + dataset number??
.then(result => {
if (result.error) { throw result.error; };
if (result.data) { setPlanet(result.data[0]); };
if (result.data) { setPlanet(result.data[0]); /*console.log(planet);*/ setPlanetOwner(planet?.ownerId); };
}
);
};

function fetchProfile () {
supabase.from('profiles') // Grab profile of userId
.select()
.eq('id', session?.user?.id)
.then(result => {
if (result.error) { throw result.error; };
if (result.data) { setProfile(result.data[0]); };
}
)
}

function claimPlanet () {
supabase.from('planets').upsert({
'id': planetId,
//'userId': 'profile?.username',
'ownerId': session?.user?.id,
})
}

return (
<Layout hideNavigation={false}> {/* Should be set to <ProfileLayout /> */}
<Card noPadding={true}>
Expand All @@ -52,9 +76,18 @@ export default function PlanetPage () {
<input type='file' className='hidden' /> {/* Use this to update location, address (will later be handled by Thirdweb), username, profile pic. Maybe just have a blanket button to include the cover as well */} {/*
<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="M6.827 6.175A2.31 2.31 0 015.186 7.23c-.38.054-.757.112-1.134.175C2.999 7.58 2.25 8.507 2.25 9.574V18a2.25 2.25 0 002.25 2.25h15A2.25 2.25 0 0021.75 18V9.574c0-1.067-.75-1.994-1.802-2.169a47.865 47.865 0 00-1.134-.175 2.31 2.31 0 01-1.64-1.055l-.822-1.316a2.192 2.192 0 00-1.736-1.039 48.774 48.774 0 00-5.232 0 2.192 2.192 0 00-1.736 1.039l-.821 1.316z" /><path strokeLinecap="round" strokeLinejoin="round" d="M16.5 12.75a4.5 4.5 0 11-9 0 4.5 4.5 0 019 0zM18.75 10.5h.008v.008h-.008V10.5z" /></svg>Update profile</label>
</div>*/}

{/*<div className="@apply text-blue-200 leading-4 mb-2 mt-2 ml-10">{profile?.address}{/* | Only show this on mouseover {profile?.username}*/}{/*</div> {/* Profile Location (from styles css) */}
</div>
<PlanetTabs activeTab={tab} planetId={planet?.id} />
<br /><br /><br />
<button onClick={claimPlanet}>Claim Planet</button>
<br /><br />
<p>Owner of this anomaly: {planetOwner}</p>
{planetOwner == session?.user?.id && (
<div>Hello World</div>
)}
<br /><br /><br />
</div>
</div>
</Card>
Expand Down

0 comments on commit 7315f94

Please sign in to comment.