Replace demo pages with live app data
This commit is contained in:
70
src/lib/friend-actions.ts
Normal file
70
src/lib/friend-actions.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { prisma } from "./prisma";
|
||||
import { requireCurrentUser } from "./session";
|
||||
|
||||
export async function sendFriendRequest(formData: FormData) {
|
||||
const user = await requireCurrentUser();
|
||||
const receiverId = String(formData.get("receiverId") || "");
|
||||
|
||||
if (!receiverId || receiverId === user.id) return;
|
||||
|
||||
const existing = await prisma.friendship.findFirst({
|
||||
where: {
|
||||
OR: [
|
||||
{ requesterId: user.id, receiverId },
|
||||
{ requesterId: receiverId, receiverId: user.id }
|
||||
]
|
||||
},
|
||||
select: { id: true, status: true }
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
await prisma.friendship.create({
|
||||
data: {
|
||||
requesterId: user.id,
|
||||
receiverId,
|
||||
status: "PENDING"
|
||||
}
|
||||
});
|
||||
} else if (existing.status === "DECLINED") {
|
||||
await prisma.friendship.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
requesterId: user.id,
|
||||
receiverId,
|
||||
status: "PENDING"
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath("/friends");
|
||||
revalidatePath("/dashboard");
|
||||
}
|
||||
|
||||
export async function acceptFriendRequest(formData: FormData) {
|
||||
await updateIncomingRequest(formData, "ACCEPTED");
|
||||
}
|
||||
|
||||
export async function declineFriendRequest(formData: FormData) {
|
||||
await updateIncomingRequest(formData, "DECLINED");
|
||||
}
|
||||
|
||||
async function updateIncomingRequest(formData: FormData, status: "ACCEPTED" | "DECLINED") {
|
||||
const user = await requireCurrentUser();
|
||||
const friendshipId = String(formData.get("friendshipId") || "");
|
||||
if (!friendshipId) return;
|
||||
|
||||
await prisma.friendship.updateMany({
|
||||
where: {
|
||||
id: friendshipId,
|
||||
receiverId: user.id,
|
||||
status: "PENDING"
|
||||
},
|
||||
data: { status }
|
||||
});
|
||||
|
||||
revalidatePath("/friends");
|
||||
revalidatePath("/dashboard");
|
||||
}
|
||||
52
src/lib/media-actions.ts
Normal file
52
src/lib/media-actions.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { normalizeMediaUrl } from "./media";
|
||||
import { prisma } from "./prisma";
|
||||
import { requireCurrentUser } from "./session";
|
||||
|
||||
export async function addMediaToRoom(formData: FormData) {
|
||||
const user = await requireCurrentUser();
|
||||
const roomId = String(formData.get("roomId") || "");
|
||||
const sourceUrl = String(formData.get("sourceUrl") || "").trim();
|
||||
|
||||
if (!roomId || !sourceUrl) return;
|
||||
|
||||
const room = await prisma.room.findFirst({
|
||||
where: {
|
||||
id: roomId,
|
||||
OR: [{ ownerId: user.id }, { members: { some: { userId: user.id } } }, { visibility: "PUBLIC" }]
|
||||
},
|
||||
select: { id: true, slug: true }
|
||||
});
|
||||
|
||||
if (!room) return;
|
||||
|
||||
const media = normalizeMediaUrl(sourceUrl);
|
||||
await prisma.mediaSource.create({
|
||||
data: {
|
||||
roomId: room.id,
|
||||
submitterId: user.id,
|
||||
provider: media.provider,
|
||||
originalUrl: media.originalUrl,
|
||||
playbackUrl: media.playbackUrl,
|
||||
title: media.originalUrl
|
||||
}
|
||||
});
|
||||
|
||||
await prisma.room.update({
|
||||
where: { id: room.id },
|
||||
data: {
|
||||
currentState: {
|
||||
provider: media.provider,
|
||||
originalUrl: media.originalUrl,
|
||||
playbackUrl: media.playbackUrl,
|
||||
updatedBy: user.username,
|
||||
updatedAt: Date.now()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
revalidatePath(`/rooms/${encodeURIComponent(room.slug)}`);
|
||||
revalidatePath("/dashboard");
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
export const dashboardStats = [
|
||||
{ label: "Online", value: "12", tone: "good" },
|
||||
{ label: "Active rooms", value: "5", tone: "info" },
|
||||
{ label: "Pending friends", value: "3", tone: "warn" },
|
||||
{ label: "Queue items", value: "18", tone: "neutral" }
|
||||
];
|
||||
|
||||
export const rooms = [
|
||||
{ name: "@maria", owner: "Maria", visibility: "Friends", status: "Live", source: "YouTube" },
|
||||
{ name: "@admin", owner: "Admin", visibility: "Role", status: "Idle", source: "Twitch" },
|
||||
{ name: "Friday Ops", owner: "Ops", visibility: "Public", status: "Live", source: "Direct" }
|
||||
];
|
||||
|
||||
export const friends = [
|
||||
{ name: "Maria", state: "Online", room: "@maria" },
|
||||
{ name: "Jens", state: "Away", room: "@jens" },
|
||||
{ name: "Aylin", state: "Offline", room: "@aylin" }
|
||||
];
|
||||
|
||||
export const queue = [
|
||||
{ title: "Build stream recap", provider: "YouTube", by: "Maria", duration: "12:40" },
|
||||
{ title: "Dockge deployment notes", provider: "Twitch", by: "Admin", duration: "Live" },
|
||||
{ title: "Local media sample", provider: "Direct", by: "Jens", duration: "03:20" }
|
||||
];
|
||||
|
||||
export const participants = [
|
||||
{ name: "Admin", role: "Admin", status: "Host" },
|
||||
{ name: "Maria", role: "Member", status: "Synced" },
|
||||
{ name: "Jens", role: "Member", status: "Synced" },
|
||||
{ name: "Aylin", role: "Guest", status: "Buffering" }
|
||||
];
|
||||
|
||||
export const activity = [
|
||||
"Maria set a YouTube source",
|
||||
"Admin seeked to 01:22",
|
||||
"Jens joined @admin",
|
||||
"Aylin requested friendship"
|
||||
];
|
||||
Reference in New Issue
Block a user