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

fix/delete gist redirect #48

Closed
wants to merge 2 commits into from
Closed
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
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,10 +16,11 @@
export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps) {
const { gistId } = params
const { data } = useGist(gistId)
const router = useRouter()
const { toast } = useToast()
const { data: user } = useMe()

const { mutate: updateName } = usePatchGistName({

Check warning on line 23 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 +29,7 @@
},
})

const { mutate: updateContent } = usePatchGistContent({

Check warning on line 32 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 All @@ -46,7 +48,6 @@
})
}
const onSave = (name: string, code: string) => {
console.log("save")
edit({
id: gistId,
name,
Expand All @@ -59,8 +60,18 @@
})
}

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 @@
gist={data}
onDownload={onDownload}
onSave={onSave}
onDelete={onDelete}
onDelete={handleDeleteGist}
onShare={onShare}
onCopy={onCopy}
onCopyCurl={onCopyCurl}
Expand Down
1 change: 1 addition & 0 deletions src/app/(gistLayout)/layout-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function CreateGistModal({
onClick={() => {
onCreateGist(gistName, gistContent)
setGistName("")
setGistContent("")
setIsGistModalOpen(false)
}}
>
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 @@ -33,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 @@ -66,11 +66,17 @@
})
}

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 @@
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
Loading