-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GIST-42): implemented gist update action
- Loading branch information
1 parent
d315c47
commit f7c1cda
Showing
3 changed files
with
197 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,63 @@ | ||
'use client' | ||
import React from 'react' | ||
import MyGistIdPage from './page-ui' | ||
import { useGist } from '@/lib/queries/gists.queries' | ||
import { useToast } from '@/components/shadcn/use-toast' | ||
"use client"; | ||
import React from "react"; | ||
import MyGistIdPage from "./page-ui"; | ||
import { | ||
useGist, | ||
usePatchGistContent, | ||
usePatchGistName, | ||
} from "@/lib/queries/gists.queries"; | ||
import { useToast } from "@/components/shadcn/use-toast"; | ||
|
||
interface MyGistIdFeaturePageProps { | ||
params: { | ||
gistId: string | ||
} | ||
gistId: string; | ||
}; | ||
} | ||
|
||
export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps) { | ||
const { gistId } = params | ||
const { data } = useGist(gistId) | ||
const { toast } = useToast() | ||
export default function MyGistIdFeaturePage({ | ||
params, | ||
}: MyGistIdFeaturePageProps) { | ||
const { gistId } = params; | ||
const { data } = useGist(gistId); | ||
const { toast } = useToast(); | ||
|
||
const { mutate: updateName } = usePatchGistName({ | ||
onSuccess: () => { | ||
toast({ | ||
title: "Gist Saved", | ||
description: "Your gist has been saved successfully", | ||
}); | ||
}, | ||
}); | ||
|
||
const { mutate: updateContent } = usePatchGistContent({ | ||
onSuccess: () => { | ||
console.log("Gist content updated"); | ||
}, | ||
}); | ||
|
||
const onDownloadClick = () => { | ||
console.log('Downloading gist') | ||
console.log("Downloading gist"); | ||
toast({ | ||
title: 'Gist Downloaded', | ||
description: 'Your gist has been downloaded successfully', | ||
}) | ||
} | ||
title: "Gist Downloaded", | ||
description: "Your gist has been downloaded successfully", | ||
}); | ||
}; | ||
const onSaveClick = (name: string, code: string) => { | ||
console.log('Saving gist with name:', name, 'and code:', code) | ||
toast({ | ||
title: 'Gist Saved', | ||
description: 'Your gist has been saved successfully', | ||
}) | ||
} | ||
console.log("Saving gist with name:", name, "and code:", code); | ||
|
||
updateContent({ id: gistId, content: code }); | ||
|
||
updateName({ id: gistId, name }); | ||
}; | ||
if (!data) { | ||
return null | ||
return null; | ||
} | ||
return <MyGistIdPage gist={data} onDownloadClick={onDownloadClick} onSaveClick={onSaveClick} /> | ||
return ( | ||
<MyGistIdPage | ||
gist={data} | ||
onDownloadClick={onDownloadClick} | ||
onSaveClick={onSaveClick} | ||
/> | ||
); | ||
} |
79 changes: 53 additions & 26 deletions
79
src/app/(gistLayout)/team/[teamId]/gist/[gistId]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,69 @@ | ||
'use client' | ||
import { useToast } from '@/components/shadcn/use-toast' | ||
import GistDetails from '@/components/ui/gist-details' | ||
import { useGist } from '@/lib/queries/gists.queries' | ||
import React from 'react' | ||
"use client"; | ||
import { useToast } from "@/components/shadcn/use-toast"; | ||
import GistDetails from "@/components/ui/gist-details"; | ||
import { | ||
useGist, | ||
usePatchGistContent, | ||
usePatchGistName, | ||
} from "@/lib/queries/gists.queries"; | ||
import React from "react"; | ||
|
||
interface MyTeamGistIdFeaturePageProps { | ||
params: { | ||
teamId: string | ||
gistId: string | ||
} | ||
teamId: string; | ||
gistId: string; | ||
}; | ||
} | ||
|
||
const folderMock = 'Team A' | ||
const folderMock = "Team A"; | ||
|
||
export default function MyTeamGistIdFeaturePage({ | ||
params, | ||
}: MyTeamGistIdFeaturePageProps) { | ||
const { teamId, gistId } = params; | ||
const { data } = useGist(gistId); | ||
const { toast } = useToast(); | ||
const { mutate: updateName } = usePatchGistName({ | ||
onSuccess: () => { | ||
toast({ | ||
title: "Gist Saved", | ||
description: "Your gist has been saved successfully a ", | ||
}); | ||
}, | ||
}); | ||
|
||
export default function MyTeamGistIdFeaturePage({ params }: MyTeamGistIdFeaturePageProps) { | ||
const { teamId, gistId } = params | ||
const { data } = useGist(gistId) | ||
const { toast } = useToast() | ||
const { mutate: updateContent } = usePatchGistContent({ | ||
onSuccess: () => { | ||
console.log("Gist content updated"); | ||
}, | ||
}); | ||
|
||
const onDownloadClick = () => { | ||
console.log('Downloading gist') | ||
console.log("Downloading gist"); | ||
toast({ | ||
title: 'Gist Downloaded', | ||
description: 'Your gist has been downloaded successfully', | ||
}) | ||
} | ||
title: "Gist Downloaded", | ||
description: "Your gist has been downloaded successfully", | ||
}); | ||
}; | ||
|
||
const onSaveClick = (name: string, code: string) => { | ||
console.log('Saving gist with name:', name, 'and code:', code) | ||
toast({ | ||
title: 'Gist Saved', | ||
description: 'Your gist has been saved successfully', | ||
}) | ||
} | ||
console.log("Saving gist with name:", name, "and code:", code); | ||
|
||
updateContent({ id: gistId, content: code }); | ||
|
||
updateName({ id: gistId, name }); | ||
}; | ||
|
||
if (!data) { | ||
return null | ||
return null; | ||
} | ||
|
||
return <GistDetails folder={folderMock} gist={data} onDownloadClick={onDownloadClick} onSaveClick={onSaveClick} /> | ||
return ( | ||
<GistDetails | ||
folder={folderMock} | ||
gist={data} | ||
onDownloadClick={onDownloadClick} | ||
onSaveClick={onSaveClick} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters