File size: 1,160 Bytes
30cc31a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use client";

import { useEffect, useState } from "react";
import Link from "next/link";
import { ensureDefaultProject } from "@/lib/api";

/** Sidebar link to the project Files page. Resolves the default project on mount. */
export default function FilesNavLink() {
  const [projectId, setProjectId] = useState<string | null>(null);

  useEffect(() => {
    let cancelled = false;
    ensureDefaultProject()
      .then((p) => {
        if (!cancelled) setProjectId(p.id);
      })
      .catch(() => {});
    return () => {
      cancelled = true;
    };
  }, []);

  if (!projectId) return null;

  return (
    <Link
      href={`/projects/${projectId}/files`}
      className="flex items-center gap-2.5 px-3 py-2 rounded-lg text-sm text-foreground-dim hover:bg-muted hover:text-foreground transition-colors"
    >
      <svg
        className="w-4 h-4 shrink-0"
        viewBox="0 0 24 24"
        fill="none"
        stroke="currentColor"
        strokeWidth={1.5}
      >
        <path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z" />
        <polyline points="14 2 14 8 20 8" />
      </svg>
      Files
    </Link>
  );
}