Skip to content

Commit

Permalink
fix(gist): add delete gist and redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
dorian-grst committed Nov 17, 2024
1 parent cc13184 commit 2e194c2
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 21 deletions.
21 changes: 16 additions & 5 deletions src/app/(gistLayout)/[username]/[gistId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"use client"
import React from "react"
import MyGistIdPage from "./page-ui"
import { useEditGist, useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries"
import { useDeleteGist, useEditGist, useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries"
import { useToast } from "@/components/shadcn/use-toast"
import { getRawGistURL } from "@/lib/utils"
import { useMe } from "@/lib/queries/user.queries"
import { redirect, useRouter } from "next/navigation"

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

View workflow job for this annotation

GitHub Actions / Test linting

'redirect' is defined but never used

interface MyGistIdFeaturePageProps {
params: {
Expand All @@ -15,6 +16,7 @@ interface MyGistIdFeaturePageProps {
export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps) {
const { gistId } = params
const { data } = useGist(gistId)
const router = useRouter()
const { toast } = useToast()
const { data: user } = useMe()

Expand Down Expand Up @@ -46,7 +48,6 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps
})
}
const onSave = (name: string, code: string) => {
console.log("save")
edit({
id: gistId,
name,
Expand All @@ -59,8 +60,18 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps
})
}

const onDelete = (id: string) => {
console.log(`Deleting gist with ID: ${id}`)
const { mutate: deleteGist } = useDeleteGist({
onSuccess: () => {
toast({
title: "Gist Deleted",
description: "Your gist has been deleted successfully",
})
router.push(`/${user?.name}`)
},
})

const handleDeleteGist = (id: string) => {
deleteGist(id)
}

const onShare = () => {
Expand Down Expand Up @@ -100,7 +111,7 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps
gist={data}
onDownload={onDownload}
onSave={onSave}
onDelete={onDelete}
onDelete={handleDeleteGist}
onShare={onShare}
onCopy={onCopy}
onCopyCurl={onCopyCurl}
Expand Down
20 changes: 13 additions & 7 deletions src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client"
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 { useDeleteGist, 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"
Expand Down Expand Up @@ -66,11 +66,17 @@ export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePag
})
}

const onDelete = (id: string) => {
toast({
title: "Gist Deleted",
description: "Your gist has been deleted successfully",
})
const { mutate: deleteGist } = useDeleteGist({
onSuccess: () => {
toast({
title: "Gist Deleted",
description: "Your gist has been deleted successfully",
})
},
})

const handleDeleteGist = (id: string) => {
deleteGist(id)
}

const onCopy = (code: string) => {
Expand Down Expand Up @@ -109,7 +115,7 @@ export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePag
onDownload={onDownload}
onSave={onSave}
onShare={onShare}
onDelete={onDelete}
onDelete={handleDeleteGist}
onCopy={onCopy}
onCopyCurl={onCopyCurl}
/>
Expand Down
8 changes: 6 additions & 2 deletions src/components/logic/mygist-list-logic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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"
import { toast } from "../shadcn/use-toast"

export function MyGistListFeature() {
const { data: user } = useMe()
Expand All @@ -19,8 +20,11 @@ export function MyGistListFeature() {
}, [nb_pages, setNbPages])

const { mutate: deleteGist } = useDeleteGist({
onSuccess: (id) => {
console.log(`Deleting gist with ID: ${id}`)
onSuccess: () => {
toast({
title: "Gist Deleted",
description: "Your gist has been deleted successfully",
})
},
})

Expand Down
32 changes: 25 additions & 7 deletions src/components/logic/org-list-logic.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
import { useDeleteGist } from "@/lib/queries/gists.queries"
import { OrgList } from "../ui/org-list"
import { useDeleteOrgs, useOrgs } from "@/lib/queries/orgs.queries"
import { toast } from "../shadcn/use-toast"

export function OrgListFeature() {
const { data } = useOrgs()
const { mutate } = useDeleteOrgs({ onSuccess: () => console.log("Deleted") })
const { mutate: deleteOrg } = useDeleteOrgs({
onSuccess: () => {
toast({
title: "Orgnization Deleted",
description: "Your organization has been deleted successfully",
})
},
})

const onDeleteTeam = (id: string) => {
mutate(id)
const handleDeleteOrg = (id: string) => {
deleteOrg(id)
}

const onGistOrg = () => {
console.log("Gist Org Clicked")
}

const onDeleteGist = (id: string) => {
console.log(`Deleting gist with ID: ${id}`)
const { mutate: deleteGist } = useDeleteGist({
onSuccess: () => {
toast({
title: "Gist Deleted",
description: "Your gist has been deleted successfully",
})
},
})

const handleDeleteGist = (id: string) => {
deleteGist(id)
}

const onUpdateOrg = (id: string, name: string) => {
Expand All @@ -25,8 +43,8 @@ export function OrgListFeature() {
<OrgList
orgs={data || []}
onGistOrg={onGistOrg}
onDeleteOrg={onDeleteTeam}
onDeleteGist={onDeleteGist}
onDeleteOrg={handleDeleteOrg}
onDeleteGist={handleDeleteGist}
onUpdateOrg={onUpdateOrg}
/>
)
Expand Down

0 comments on commit 2e194c2

Please sign in to comment.