34 lines hidden | ||
35 | } from "@/primitives/icons"; | |
36 | import { useDropzone } from "react-dropzone"; | |
37 | import { Alert } from "@/primitives/Alert"; | |
38 | + import { useRouter } from "next/navigation"; | |
39 |
| |
40 | export const UserForm = (props: { | |
41 | discordToken: string; | |
42 | discordClientId: string; | |
43 | }) => { | |
44 | + const router = useRouter(); | |
45 | const supabase = clientClient(); | |
46 | const authenticatedUser = useUser(); | |
47 | if (!authenticatedUser) { | |
175 lines hidden | ||
223 | throw error; | |
224 | } | |
225 |
| |
226 | ~ router.refresh(); | |
227 | }; | |
228 |
| |
229 | return ( | |
394 lines hidden |
41 lines hidden | ||
42 | import dynamic from "next/dynamic"; | |
43 | import { notFound } from "next/navigation"; | |
44 | import { PropsWithChildren, Suspense } from "react"; | |
45 | + import { PushRefresh } from "./PushRefresh"; | |
46 |
| |
47 | export const runtime = "edge"; | |
48 |
| |
76 lines hidden | ||
125 | loggedOutBranch={loggedOutBranch} | |
126 | permissions={share?.permissions} | |
127 | > | |
128 | + <PushRefresh /> | |
129 | <Suspense> | |
130 | {branch && ( | |
131 | <BottomBar | |
370 lines hidden |
1 | + "use client"; | |
2 | +
| |
3 | + import { useCurrentBranch } from "@/contexts/BranchProvider"; | |
4 | + import { useRouter } from "next/navigation"; | |
5 | + import { useEffect, useRef } from "react"; | |
6 | + import { toast } from "sonner"; | |
7 | +
| |
8 | + export const PushRefresh = () => { | |
9 | + const router = useRouter(); | |
10 | + const latestPush = useRef<string>(); | |
11 | + const branch = useCurrentBranch(); | |
12 | +
| |
13 | + useEffect(() => { | |
14 | + const latest = branch.latest_sha || ""; | |
15 | +
| |
16 | + if (!latestPush.current) { | |
17 | + latestPush.current = latest; | |
18 | + return; | |
19 | + } | |
20 | +
| |
21 | + if (latestPush.current !== latest) { | |
22 | + toast.info("New push detected, updating branch…"); | |
23 | + latestPush.current = latest; | |
24 | + router.refresh(); | |
25 | + } | |
26 | + }, [branch.latest_sha]); | |
27 | +
| |
28 | + return null; | |
29 | + }; |
7 lines hidden | ||
8 | import { EditableText, Text } from "@/primitives/Text"; | |
9 | import debounce from "lodash.debounce"; | |
10 | import Link from "next/link"; | |
11 | + import { useRouter } from "next/navigation"; | |
12 | import { useCallback, useState } from "react"; | |
13 |
| |
14 | export const Title = ({ | |
8 lines hidden | ||
23 | const [title, setTitle] = useState(_title || fallbackTitle); | |
24 | const supabase = clientClient(); | |
25 | const value = title; | |
26 | + const router = useRouter() | |
27 |
| |
28 | useSubscribe({ | |
29 | table: "branches", | |
9 lines hidden | ||
39 | const debouncedChangeHandler = useCallback( | |
40 | debounce((title: string) => { | |
41 | supabase.from("branches").update({ title }).eq("id", branchId).then(); | |
42 | + router.refresh() | |
43 | }, 300), | |
44 | [], | |
45 | ); | |
18 lines hidden |
24 lines hidden | ||
25 | teamUrl, | |
26 | null, | |
27 | () => { | |
28 | + // don't block on this, but revalidate list type for next page visit | |
29 | + fetch(`/api/revalidate?path=/${teamUrl}/${type}`); | |
30 | +
| |
31 | if (type === "branches") { | |
32 | return recentBranchesQuery(client, user!.id, teamUrl); | |
33 | } else { | |
15 lines hidden |
4 lines hidden | ||
5 | import { IconButtonWithBorder } from "@/primitives/Icon"; | |
6 | import { IconMenu } from "@/primitives/icons"; | |
7 |
| |
8 | ~ export const SidebarOpenButton = () => { | |
9 | const handleToggle = () => { | |
10 | const page = document.querySelector("#pierre-page") as HTMLElement; | |
11 | page.style.gridTemplateColumns = `var(--sidebar-width) auto`; | |
19 lines hidden |
32 lines hidden | ||
33 | count?: number; | |
34 | disabled?: boolean; | |
35 | href?: string; | |
36 | id?: string; | |
37 | prefetch?: boolean; | |
38 | style?: React.CSSProperties; | |
85 lines hidden |
287 lines hidden | ||
288 | data-id={repo.id} | |
289 | > | |
290 | <SidebarRepo | |
291 | + prefetch={true} | |
292 | href={`/${teamUrl}/${repo.repo.url}`} | |
293 | style={{ fontSize: 13 }} | |
294 | team={teamUrl} | |
97 lines hidden |
1 | + import { revalidatePath } from "next/cache"; | |
2 | + import { NextRequest } from "next/server"; | |
3 | +
| |
4 | + export async function GET(request: NextRequest) { | |
5 | + const path = request.nextUrl.searchParams.get("path"); | |
6 | +
| |
7 | + if (path) { | |
8 | + revalidatePath(path); | |
9 | + return Response.json({ revalidated: true, now: Date.now() }); | |
10 | + } | |
11 | +
| |
12 | + return Response.json({ | |
13 | + revalidated: false, | |
14 | + now: Date.now(), | |
15 | + message: "Missing path to revalidate", | |
16 | + }); | |
17 | + } |
24 lines hidden | ||
25 | data: { session }, | |
26 | } = await supabase.auth.getSession(); | |
27 |
| |
28 | + // be chill about revalidating | |
29 | + if (req.nextUrl.pathname === "/api/revalidate") { | |
30 | + return res; | |
31 | + } | |
32 | +
| |
33 | // Load or redirect / based on logged in & cookies | |
34 | if (req.nextUrl.pathname === "/") { | |
35 | if (!session) { | |
161 lines hidden |
25 lines hidden | ||
26 | useSubscribe({ | |
27 | table: "branch_authors", | |
28 | filter: `user_id=eq.${user.id}`, | |
29 | ~ callback: (payload) => { | |
30 | // If we are added to a whole new branch we need to reload | |
31 | + if (!payload.eventType) return; | |
32 | reloadQuery().then((br) => { | |
33 | setBranches(br || []); | |
34 | }); | |
35 | }, | |
36 | }); | |
37 |
| |
38 | + // console.log("settings up branch_reads listener"); | |
39 | useSubscribe({ | |
40 | table: "branch_reads", | |
41 | filter: `user_id=eq.${user.id}`, | |
42 | ~ callback: (payload) => { | |
43 | + if (!payload.eventType) return; | |
44 | reloadQuery().then((br) => { | |
45 | setBranches(br || []); | |
46 | }); | |
26 lines hidden |
useRouter
UserForm.tsx
Title.tsx.
PushRefresh.tsx