Skip to content

Commit

Permalink
💄 Tidy up Expo page
Browse files Browse the repository at this point in the history
Move truncate function to util file since now used on
multiple pages/components
  • Loading branch information
tameTNT committed Oct 28, 2024
1 parent cb60ba6 commit 1bc7312
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 1 addition & 7 deletions client/src/components/judge/ProjectEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { twMerge } from 'tailwind-merge';
import DragHamburger from './dnd/DragHamburger';
import {truncate} from "../../util";

interface ProjectEntryProps {
project: SortableJudgedProject;
Expand All @@ -11,13 +12,6 @@ const ProjectEntry = ({ project, ranking }: ProjectEntryProps) => {
return null;
}

// Will truncate a string to width characters exactly,
// adding a dot at the end if the length is > than width chars
const truncate = (s: string, width: number = 8) => {
if (s.length <= width) return s;
return s.substring(0, width-1) + '.';
};

let rankColor = 'text-lightest';
switch (ranking) {
case 1:
Expand Down
8 changes: 4 additions & 4 deletions client/src/pages/Expo.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import Container from '../components/Container';
import { getRequest } from '../api';
import { errorAlert } from '../util';
import {errorAlert, truncate} from '../util';

const Expo = () => {
const [rawProjects, setRawProjects] = useState<PublicProject[]>([]);
Expand Down Expand Up @@ -40,7 +40,7 @@ const Expo = () => {
<Container noCenter>
<h1 className="mt-4 text-4xl text-center font-bold">Project Expo</h1>
<h2 className="text-2xl text-center font-bold text-primary">
{import.meta.env.VITE_JURY_NAME}
<a href="/">{import.meta.env.VITE_JURY_NAME}</a>
</h2>
<table className="mb-4">
<thead>
Expand All @@ -59,7 +59,7 @@ const Expo = () => {
'px-4 py-2 cursor-pointer text-left ' + (!nameSort && 'underline')
}
>
Table
Location
</th>
</tr>
</thead>
Expand All @@ -68,7 +68,7 @@ const Expo = () => {
<tr key={idx}>
<td className="px-4 py-2">
<a href={project.url} target="_blank" rel="noopener noreferrer">
{project.name}
{truncate(project.name, 20)}
</a>
</td>
<td className="px-4 py-2">{project.location}</td>
Expand Down
9 changes: 8 additions & 1 deletion client/src/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,11 @@ function errorAlert<T>(res: FetchResponse<T>) {
console.error(err);
}

export { timeSince, arrow, fixIfFloat, fixIfFloatDigits, errorAlert, showTopFive };
// Will truncate a string to width characters exactly,
// adding a dot at the end if the length is > than width chars
function truncate(s: string, width: number = 8) {
if (s.length <= width) return s;
return s.substring(0, width-1) + '.';
}

export { timeSince, arrow, fixIfFloat, fixIfFloatDigits, errorAlert, showTopFive, truncate };

0 comments on commit 1bc7312

Please sign in to comment.