Skip to content

Commit

Permalink
feat(GIST-105): change mygist url to username (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
dorian-grst authored Nov 16, 2024
1 parent 287d51a commit b6bba1c
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Gist } from "@/types"

interface MyGistIdPageProps {
gist: Gist
username?: string
onDownload: () => void
onSave: (name: string, code: string) => void
onDelete: (id: string) => void
Expand All @@ -13,6 +14,7 @@ interface MyGistIdPageProps {

export default function MyGistIdPage({
gist,
username,
onDownload,
onSave,
onDelete,
Expand All @@ -22,6 +24,7 @@ export default function MyGistIdPage({
}: MyGistIdPageProps) {
return (
<GistDetails
username={username ? username : ""}
orgName={"My Gists"}
gist={gist}
redirect={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps
const { gistId } = params
const { data } = useGist(gistId)
const { toast } = useToast()
const { data: me } = useMe()
const { data: user } = useMe()

const { mutate: updateName } = usePatchGistName({
onSuccess: () => {
Expand Down Expand Up @@ -55,7 +55,7 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps
visibility: "public",
org_id: null,
language: "plaintext",
owner_id: me?.id || "",
owner_id: user?.id || "",
})
}

Expand Down Expand Up @@ -96,6 +96,7 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps
}
return (
<MyGistIdPage
username={user?.name}
gist={data}
onDownload={onDownload}
onSave={onSave}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 1 addition & 3 deletions src/app/(gistLayout)/layout-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ function AppSidebar({
isOrgModalOpen,
setIsOrgModalOpen,
onCreateOrg,
onMyGists,
gistContent,
setGistContent,
language,
Expand Down Expand Up @@ -137,8 +136,7 @@ function AppSidebar({
variant="menu"
size="menu"
letter="M"
onClick={onMyGists}
href="/mygist"
href={`/${username}`}
className="w-full"
>
My Gists
Expand Down
3 changes: 3 additions & 0 deletions src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Gist } from "@/types"

interface MyOrgGistIdPageProps {
gist: Gist
username: string
orgName: string
onDownload: () => void
onSave: () => void
Expand All @@ -14,6 +15,7 @@ interface MyOrgGistIdPageProps {

export default function MyOrgGistIdPage({
orgName,
username,
gist,
onDownload,
onSave,
Expand All @@ -24,6 +26,7 @@ export default function MyOrgGistIdPage({
}: MyOrgGistIdPageProps) {
return (
<GistDetails
username={username}
orgName={orgName}
gist={gist}
onDownload={onDownload}
Expand Down
3 changes: 3 additions & 0 deletions src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useToast } from "@/components/shadcn/use-toast"
import GistDetails from "@/components/ui/gist-details"
import { useEditGist, useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries"
import { useOrg } from "@/lib/queries/orgs.queries"
import { useMe } from "@/lib/queries/user.queries"
import { getRawGistURL } from "@/lib/utils"
import React from "react"

Expand All @@ -15,6 +16,7 @@ interface MyOrgGistIdFeaturePageProps {

export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePageProps) {
const { orgId, gistId } = params
const { data: user } = useMe()
const { data: orgData } = useOrg(orgId)
const { data: gistData } = useGist(gistId)
const { toast } = useToast()
Expand Down Expand Up @@ -101,6 +103,7 @@ export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePag

return (
<GistDetails
username={user?.name || ""}
orgName={orgData ? orgData.name : "My Gists"}
gist={gistData}
onDownload={onDownload}
Expand Down
4 changes: 3 additions & 1 deletion src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useLocalAuth, useLocalAuthVerify } from "@/lib/queries/auth.queries"
import Login from "./page-ui"
import { redirect, useRouter } from "next/navigation"
import { useKeyPress } from "@/lib/hook/use-key-press"
import { useMe } from "@/lib/queries/user.queries"

interface FormData {
email: string
Expand All @@ -18,6 +19,7 @@ export default function LoginFeature() {
const [otpValue, setOtpValue] = useState("")
const { toast } = useToast()
const router = useRouter()
const { data: user } = useMe()

const { mutate: sendEmail } = useLocalAuth()
const { mutate: verifyEmail, data: verified } = useLocalAuthVerify()
Expand Down Expand Up @@ -105,7 +107,7 @@ export default function LoginFeature() {
title: "You have been verified.",
})

redirect("/mygist")
redirect(`/${user?.name}`)
}
}, [verified, toast])

Expand Down
4 changes: 3 additions & 1 deletion src/components/logic/mygist-list-logic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { useContext, useEffect } from "react"
import MyGistList from "../ui/mygist-list"
import { useDeleteGist, useGists } from "@/lib/queries/gists.queries"
import { PaginationContext } from "../contexts/pagination"
import { useMe } from "@/lib/queries/user.queries"

export function MyGistListFeature() {
const { data: user } = useMe()
const { offset, limit, setNbPages } = useContext(PaginationContext)
const { data, nb_pages } = useGists({
limit,
Expand All @@ -26,5 +28,5 @@ export function MyGistListFeature() {
deleteGist(id)
}

return <MyGistList gists={data || []} onDeleteGist={handleDeleteGist} />
return <MyGistList gists={data || []} username={user?.name} onDeleteGist={handleDeleteGist} />
}
8 changes: 6 additions & 2 deletions src/components/ui/gist-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Button } from "../shadcn/button"

interface GistDetailsProps {
gist: Gist
username: string
orgName: string
redirect?: boolean
onDownload: (name: string, code: string) => void
Expand All @@ -34,6 +35,7 @@ interface GistDetailsProps {

export default function GistDetails({
gist,
username,
orgName,
redirect,
onDownload,
Expand Down Expand Up @@ -71,6 +73,7 @@ export default function GistDetails({
<div className="flex flex-col w-full h-full p-2">
<Header
gist={gistState}
username={username}
orgName={orgName}
redirect={redirect}
onDownload={() => onDownload(gistName, gistCode)}
Expand Down Expand Up @@ -138,6 +141,7 @@ export default function GistDetails({

interface HeaderProps {
gist: Gist
username?: string
orgName: string
redirect?: boolean
onDownload: (name: string, code: string) => void
Expand All @@ -146,15 +150,15 @@ interface HeaderProps {
onOpenPlainText?: (gistID: string) => void
}

function Header({ gist, orgName, redirect, onDownload, onCopy, onCopyCurl, onOpenPlainText }: HeaderProps) {
function Header({ gist, username, orgName, redirect, onDownload, onCopy, onCopyCurl, onOpenPlainText }: HeaderProps) {
return (
<div className="py-4 px-6 flex flex-row justify-between items-center rounded-t-lg border-border border-l border-t border-r">
<div className="flex flex-row gap-6 items-center h-full">
<SidebarTrigger className="w-4 h-4" />
<div className="w-[1px] h-2/3 bg-border"></div>
<div className="flex flex-row gap-2 justify-center items-center">
{redirect ? (
<Link href="/mygist" className="hover:underline">
<Link href={`/${username}`} className="hover:underline">
{orgName}
</Link>
) : (
Expand Down
5 changes: 3 additions & 2 deletions src/components/ui/mygist-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import Card from "./card"
interface MyGistListProps {
gists: Gist[]
onDeleteGist: (id: string) => void
username?: string
}

export default function MyGistList({ gists, onDeleteGist }: MyGistListProps) {
export default function MyGistList({ gists, onDeleteGist, username }: MyGistListProps) {
if (gists.length === 0) {
return (
<div className="p-4 h-full flex items-center justify-center border-border border-r border-l">
Expand All @@ -18,7 +19,7 @@ export default function MyGistList({ gists, onDeleteGist }: MyGistListProps) {
return (
<div className="p-4 h-full grid grid-cols-3 grid-rows-3 gap-4 border-border border-r border-l">
{gists.map((gist) => (
<Card key={gist.id} gist={gist} href={`/mygist/${gist.id}`} onDeleteGist={() => onDeleteGist(gist.id)} />
<Card key={gist.id} gist={gist} href={`/${username}/${gist.id}`} onDeleteGist={() => onDeleteGist(gist.id)} />
))}
</div>
)
Expand Down

0 comments on commit b6bba1c

Please sign in to comment.