Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mygist): change mygist url to username #47

Merged
merged 1 commit into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 +16,9 @@
const { gistId } = params
const { data } = useGist(gistId)
const { toast } = useToast()
const { data: me } = useMe()
const { data: user } = useMe()

const { mutate: updateName } = usePatchGistName({

Check warning on line 21 in src/app/(gistLayout)/[username]/[gistId]/page.tsx

View workflow job for this annotation

GitHub Actions / Test linting

'updateName' is assigned a value but never used
onSuccess: () => {
toast({
title: "Gist Saved",
Expand All @@ -27,7 +27,7 @@
},
})

const { mutate: updateContent } = usePatchGistContent({

Check warning on line 30 in src/app/(gistLayout)/[username]/[gistId]/page.tsx

View workflow job for this annotation

GitHub Actions / Test linting

'updateContent' is assigned a value but never used
onSuccess: () => {},
})

Expand Down Expand Up @@ -55,7 +55,7 @@
visibility: "public",
org_id: null,
language: "plaintext",
owner_id: me?.id || "",
owner_id: user?.id || "",
})
}

Expand Down Expand Up @@ -96,6 +96,7 @@
}
return (
<MyGistIdPage
username={user?.name}
gist={data}
onDownload={onDownload}
onSave={onSave}
Expand Down
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 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 @@

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 All @@ -31,7 +33,7 @@
onSuccess: () => {},
})

const { mutate: edit } = useEditGist({

Check warning on line 36 in src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx

View workflow job for this annotation

GitHub Actions / Test linting

'edit' is assigned a value but never used
onSuccess: () => {
toast({
title: "Gist Saved",
Expand Down Expand Up @@ -64,7 +66,7 @@
})
}

const onDelete = (id: string) => {

Check warning on line 69 in src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx

View workflow job for this annotation

GitHub Actions / Test linting

'id' is defined but never used
toast({
title: "Gist Deleted",
description: "Your gist has been deleted successfully",
Expand Down Expand Up @@ -101,6 +103,7 @@

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
Loading