Skip to content

Commit

Permalink
Use revalidateProfile and revalidateServer functions after updating p…
Browse files Browse the repository at this point in the history
…rofiles/servers
  • Loading branch information
chimpdev committed Apr 14, 2024
1 parent 0f2ebcd commit 5a2be90
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { motion } from 'framer-motion';
import Tooltip from '@/app/components/Tooltip';
import useAuthStore from '@/stores/auth';
import CopyButton from '@/app/components/CopyButton';
import revalidateProfile from '@/lib/revalidate/profile';

export default function Actions({ profile }) {
const loggedIn = useAuthStore(state => state.loggedIn);
Expand All @@ -28,6 +29,7 @@ export default function Actions({ profile }) {
success: (isLiked) => {
setLiked(isLiked);
setLoading(false);
revalidateProfile(profile.slug);

return isLiked ? `Liked ${profile.slug}!` : `Unliked ${profile.slug}!`;
},
Expand Down
2 changes: 2 additions & 0 deletions client/app/(profiles)/profile/[slug]/edit/components/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import GenderDropdown from '@/app/(profiles)/profile/[slug]/edit/components/Drop
import PreferredHostDropdown from '@/app/(profiles)/profile/[slug]/edit/components/Dropdown/PreferredHost';
import Link from 'next/link';
import { PiWarningCircleFill } from 'react-icons/pi';
import revalidateProfile from '@/lib/revalidate/profile';

export default function Edit({ profileData }) {
const canBeEditedKeys = [
Expand Down Expand Up @@ -68,6 +69,7 @@ export default function Edit({ profileData }) {
setTimeout(() => router.push(config.getProfileURL(changedKeys['newSlug'], newProfile.preferredHost)), 3000);
return 'Profile updated! You will be redirected to new profile in 3 seconds.';
} else {
revalidateProfile(newProfile.slug);
setLoading(false);
return 'Profile updated!';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import cn from '@/lib/cn';
import config from '@/config';
import getDisplayableURL from '@/lib/utils/profiles/getDisplayableURL';
import getIconPath from '@/lib/utils/profiles/getIconPath';
import revalidateProfile from '@/lib/revalidate/profile';

export default function Socials({ profile }) {
const [socials, setSocials] = useState(profile.socials);
Expand Down Expand Up @@ -83,6 +84,7 @@ export default function Socials({ profile }) {
setNewSocialValue('');
setLoading(false);
setSocials(newSocials);
revalidateProfile(profile.slug);

return 'New social added successfully.';
},
Expand All @@ -107,6 +109,7 @@ export default function Socials({ profile }) {
setNewSocialValue('');
setLoading(false);
setSocials(newSocials);
revalidateProfile(profile.slug);

return 'New social media added successfully.';
},
Expand All @@ -132,6 +135,7 @@ export default function Socials({ profile }) {
setNewSocialValue('');
setLoading(false);
setSocials(newSocials);
revalidateProfile(profile.slug);

return 'Social media deleted successfully.';
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import createReminder from '@/lib/request/servers/createReminder';
import Countdown from '@/app/components/Countdown';
import Tooltip from '@/app/components/Tooltip';
import { FaRegBell, FaBell } from 'react-icons/fa';
import revalidateServer from '@/lib/revalidate/server';

export default function Actions({ server }) {
const [serverVotes, setServerVotes] = useState(server.votes);
Expand Down Expand Up @@ -57,6 +58,7 @@ export default function Actions({ server }) {
setServerVotes(serverVotes + (server.badges.includes('Premium') ? 2 : 1));
setVoteTimeout({ createdAt: new Date().getTime() + 86400000 });
setCanSetReminder(data.inGuild);
revalidateServer(server.id);

return `Successfully voted for ${server.name}!`;
},
Expand Down
7 changes: 7 additions & 0 deletions client/lib/revalidate/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use server';

import { revalidatePath } from 'next/cache';

export default async function revalidateProfile(slug) {
revalidatePath(`/profile/${slug}`);
}

0 comments on commit 5a2be90

Please sign in to comment.