shares now open in a new tab

This commit is contained in:
polaris 2024-06-29 15:25:43 -04:00
parent c784e8808e
commit 4e3938e87e
7 changed files with 40 additions and 27 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}

View File

@ -1,11 +1,9 @@
import ChunithmData from "@/components/scoreplaylog/page";
import React from "react";
import ChunithmScorePlaylog from "@/components/scoreplaylog/page";
const ChunithmPage = async () => {
const ChunithmPage = () => {
return (
<div>
<ChunithmData />
</div>
<ChunithmScorePlaylog/>
);
};

View File

@ -11,13 +11,11 @@ import {
CardTitle,
} from "@/components/ui/card";
import { Label } from "@/components/ui/label";
import { toast, useToast } from "@/components/ui/use-toast";
import { toast } from "@/components/ui/use-toast";
import { signUp } from "./action";
import { useState } from "react";
export default function SignUpForm() {
const [error, setError] = useState<string>("");
const submit = async (data: FormData) => {
const { error } = await signUp(data);

BIN
bun.lockb

Binary file not shown.

View File

@ -68,13 +68,20 @@ export const columns: ColumnDef<Song>[] = [
const song = row.original;
const [error, setError] = useState<string>("");
const router = useRouter();
const handleGenerateShareToken = async () => {
const { token, error } = await generateShareToken(row.original.id);
if (error) {
setError(error);
} else {
router.push(`/${token}/${row.original.id}`);
const newTab = window.open(`/${token}/${row.original.id}`, '_blank');
if (newTab) {
newTab.focus();
} else {
// Handle popup blocker or inability to open new tab
router.push(`/${token}/${row.original.id}`);
}
}
};
@ -95,7 +102,7 @@ export const columns: ColumnDef<Song>[] = [
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleGenerateShareToken}>
View details
Share Song
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>

View File

@ -1,20 +1,28 @@
import { DataTable } from "./data-table";
import { getSongsWithTitles } from "@/lib/api";
import { Song, columns } from "./colums";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { getAuth } from "@/auth/queries/getauth";
import { z } from "zod";
import { columns } from "./colums";
const ChunithmData = async () => {
const userSchema = z.object({
UserId: z.number()
});
const ChunithmScorePlaylog = async () => {
const { user } = await getAuth();
let songs: Song[] = [];
if (user?.UserId !== undefined) {
songs = await getSongsWithTitles(user.UserId);
} else {
return {
error: "no user id ",
};
const TypedUser = userSchema.safeParse(user);
if (!TypedUser.success) {
return (
<div className="p-10">
<p>Failed to load user data</p>
</div>
);
}
const songs = await getSongsWithTitles(TypedUser.data.UserId);
return (
<div className="p-10">
<DataTable columns={columns} data={songs} />
@ -22,4 +30,4 @@ const ChunithmData = async () => {
);
};
export default ChunithmData;
export default ChunithmScorePlaylog;

View File

@ -85,13 +85,12 @@
"zustand": "^4.5.2"
},
"devDependencies": {
"typescript": "^5.5.2",
"@types/node": "^20.14.8",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.4",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"eslint": "^8",
"eslint-config-next": "14.2.4"
"typescript": "^5.5.2"
}
}