feat: add in_reply_to_url field to FeedRow and ThoughtRow, update related queries and handlers
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { revalidateTag } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
import { updateProfile as apiUpdateProfile, UpdateProfileSchema } from "@/lib/api";
|
||||
import { z } from "zod";
|
||||
|
||||
async function getToken(): Promise<string> {
|
||||
const token = (await cookies()).get("auth_token")?.value;
|
||||
if (!token) throw new Error("Not authenticated");
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function updateProfile(
|
||||
username: string,
|
||||
data: z.infer<typeof UpdateProfileSchema>
|
||||
) {
|
||||
const token = await getToken();
|
||||
const updated = await apiUpdateProfile(data, token);
|
||||
revalidateTag(`profile:${username}`);
|
||||
revalidateTag("me");
|
||||
return updated;
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { revalidateTag } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
import {
|
||||
followUser as apiFollowUser,
|
||||
unfollowUser as apiUnfollowUser,
|
||||
} from "@/lib/api";
|
||||
|
||||
async function getToken(): Promise<string> {
|
||||
const token = (await cookies()).get("auth_token")?.value;
|
||||
if (!token) throw new Error("Not authenticated");
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function followUser(username: string) {
|
||||
const token = await getToken();
|
||||
await apiFollowUser(username, token);
|
||||
revalidateTag(`profile:${username}`);
|
||||
revalidateTag("feed");
|
||||
}
|
||||
|
||||
export async function unfollowUser(username: string) {
|
||||
const token = await getToken();
|
||||
await apiUnfollowUser(username, token);
|
||||
revalidateTag(`profile:${username}`);
|
||||
revalidateTag("feed");
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
"use server";
|
||||
|
||||
import { revalidateTag } from "next/cache";
|
||||
import { cookies } from "next/headers";
|
||||
import {
|
||||
createThought as apiCreateThought,
|
||||
deleteThought as apiDeleteThought,
|
||||
CreateThoughtSchema,
|
||||
} from "@/lib/api";
|
||||
import { z } from "zod";
|
||||
|
||||
async function getToken(): Promise<string> {
|
||||
const token = (await cookies()).get("auth_token")?.value;
|
||||
if (!token) throw new Error("Not authenticated");
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function createThought(data: z.infer<typeof CreateThoughtSchema>) {
|
||||
const token = await getToken();
|
||||
const thought = await apiCreateThought(data, token);
|
||||
revalidateTag("feed");
|
||||
return thought;
|
||||
}
|
||||
|
||||
export async function deleteThought(thoughtId: string) {
|
||||
const token = await getToken();
|
||||
await apiDeleteThought(thoughtId, token);
|
||||
revalidateTag("feed");
|
||||
revalidateTag(`thought:${thoughtId}`);
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import * as React from "react";
|
||||
import { Check, ChevronsUpDown } from "lucide-react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
Command,
|
||||
CommandEmpty,
|
||||
CommandGroup,
|
||||
CommandInput,
|
||||
CommandItem,
|
||||
CommandList,
|
||||
} from "@/components/ui/command";
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { getFriends, User } from "@/lib/api";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { Skeleton } from "./ui/skeleton";
|
||||
|
||||
interface TopFriendsComboboxProps {
|
||||
value: string[];
|
||||
onChange: (value: string[]) => void;
|
||||
}
|
||||
|
||||
export function TopFriendsCombobox({
|
||||
value,
|
||||
onChange,
|
||||
}: TopFriendsComboboxProps) {
|
||||
const [open, setOpen] = React.useState(false);
|
||||
const [friends, setFriends] = React.useState<User[]>([]);
|
||||
const [isLoading, setIsLoading] = React.useState(true);
|
||||
const { token } = useAuth();
|
||||
|
||||
React.useEffect(() => {
|
||||
if (token) {
|
||||
getFriends(token)
|
||||
.then((data) => setFriends(data.users))
|
||||
.catch(() => console.error("Failed to fetch friends"))
|
||||
.finally(() => setIsLoading(false));
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
if (isLoading) {
|
||||
return <Skeleton className="h-10 w-full" />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
role="combobox"
|
||||
aria-expanded={open}
|
||||
className="w-full justify-between"
|
||||
>
|
||||
{value.length > 0
|
||||
? `${value.length} friend(s) selected`
|
||||
: "Select up to 8 friends..."}
|
||||
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent className="w-full p-0">
|
||||
<Command>
|
||||
<CommandInput placeholder="Search friends..." />
|
||||
<CommandList>
|
||||
<CommandEmpty>No friends found.</CommandEmpty>
|
||||
<CommandGroup>
|
||||
{friends.map((friend) => (
|
||||
<CommandItem
|
||||
key={friend.id}
|
||||
value={friend.username}
|
||||
onSelect={(currentValue) => {
|
||||
const newValue = value.includes(currentValue)
|
||||
? value.filter((v) => v !== currentValue)
|
||||
: [...value, currentValue];
|
||||
|
||||
if (newValue.length <= 8) {
|
||||
onChange(newValue);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Check
|
||||
className={cn(
|
||||
"mr-2 h-4 w-4",
|
||||
value.includes(friend.username)
|
||||
? "opacity-100"
|
||||
: "opacity-0"
|
||||
)}
|
||||
/>
|
||||
{friend.username}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -101,9 +101,6 @@ export const ApiKeyResponseSchema = ApiKeySchema.extend({
|
||||
key: z.string().optional(),
|
||||
});
|
||||
|
||||
export const ApiKeyListSchema = z.object({
|
||||
keys: z.array(ApiKeySchema),
|
||||
});
|
||||
|
||||
export const CreateApiKeySchema = z.object({
|
||||
name: z.string().min(1, "Key name cannot be empty."),
|
||||
|
||||
Reference in New Issue
Block a user