Skip to content

Commit a609f60

Browse files
committed
Refactor fetch URL in ProjectCard component
1 parent 75b1d09 commit a609f60

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

client/src/components/Projects/ProjectCard.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function ProjectCard({ project, onProjectChange }: ProjectProps) {
6262
if (isStarred) return; // Prevent multiple stars
6363

6464
try {
65-
const response = await fetch(`${backendUrl}/profile/${paramsUsername}/projects/${project.projectId}/star`, {
65+
const response = await fetch(`${backendUrl}/profile/${username}/projects/${project.projectId}/star`, {
6666
method: "POST",
6767
headers: { "Content-Type": "application/json" },
6868
});
@@ -97,7 +97,9 @@ export function ProjectCard({ project, onProjectChange }: ProjectProps) {
9797
>
9898
{project.title}
9999
</CardTitle>
100-
<ReactMarkdown>{project.description}</ReactMarkdown>
100+
<ReactMarkdown>
101+
{project.description.split(' ').slice(0, 5).join(' ') + (project.description.split(' ').length > 5 ? '...' : '')}
102+
</ReactMarkdown>
101103
</div>
102104
<div className="flex items-center rounded-md bg-secondary text-secondary-foreground">
103105
<Button

client/src/pages/ProjectDisplay.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const ProjectDisplay = () => {
3434
const [isStarred, setIsStarred] = useState(false);
3535
const [starCount, setStarCount] = useState(0); // Initialize as 0
3636
const [isStarRequestInProgress, setIsStarRequestInProgress] = useState(false); // To disable button during request
37+
const loggedInUsername = localStorage.getItem("devhub_username");
3738

3839
useEffect(() => {
3940
const fetchProject = async () => {
@@ -69,7 +70,7 @@ const ProjectDisplay = () => {
6970
setIsStarRequestInProgress(true); // Disable the button while the request is in progress
7071

7172
try {
72-
const response = await fetch(`${backendUrl}/profile/${username}/projects/${project.projectId}/star`, {
73+
const response = await fetch(`${backendUrl}/profile/${loggedInUsername}/projects/${project.projectId}/star`, {
7374
method: "POST",
7475
headers: { "Content-Type": "application/json" },
7576
});

0 commit comments

Comments
 (0)