Skip to content

Commit 5469edf

Browse files
committed
Add ShowMore button
1 parent aebd41b commit 5469edf

File tree

9 files changed

+97
-19
lines changed

9 files changed

+97
-19
lines changed

src/app/(authenticated)/companies/[id]/page.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { SessionTile } from "@/components/session";
1313
import EventDayButton from "@/components/EventDayButton";
1414
import { Scan } from "lucide-react";
1515
import Link from "next/link";
16+
import { SocialNetwork } from "@/components/SocialNetwork";
1617

1718
interface CompanyParams {
1819
id: string;
@@ -56,12 +57,12 @@ export default async function Company({ params }: { params: CompanyParams }) {
5657
src={company.img}
5758
alt={`${company.name} logo`}
5859
/>
59-
{/* TODO: Add contacts to company */}
6060
{hereToday && (
6161
<span className="bg-sinfo-primary text-white rounded-md px-3 py-1 text-lg font-bold uppercase">
6262
Here Today
6363
</span>
6464
)}
65+
{company.site && <SocialNetwork type="website" text={company.site} />}
6566
</div>
6667
{/* Members section */}
6768
{user && isMember(user.role) && (

src/app/(authenticated)/companies/[id]/promote/CompanyPromoteScanner.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ export default function CompanyPromoteScanner({
3131
if (
3232
await UserService.promote(cannonToken, scannedUser.id, {
3333
role: "company",
34-
company: {
35-
company: company.id,
36-
edition: "32", // FIXME: Use dynamic value
37-
},
34+
company: { company: company.id },
3835
})
3936
) {
4037
setStatusCard(

src/app/(authenticated)/sessions/[id]/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { hackyPeeking } from "@/assets/images";
33
import List from "@/components/List";
44
import ListCard from "@/components/ListCard";
55
import MessageCard from "@/components/MessageCard";
6+
import { ShowMore } from "@/components/ShowMore";
67
import { PrizeTile } from "@/components/prize";
78
import AddToCalendarButton from "@/components/session/AddToCalendarButton";
89
import { CalendarButton } from "@/components/session/CalendarButton";
@@ -60,7 +61,9 @@ export default async function Session({ params }: { params: SessionParams }) {
6061
<span className="bg-sinfo-secondary text-white rounded-md px-3 py-1 font-bold uppercase">
6162
{sinfoSession.kind}
6263
</span>
63-
<p className="font-light">{sinfoSession.description}</p>
64+
<ShowMore lines={5} className="font-light">
65+
{sinfoSession.description}
66+
</ShowMore>
6467
</div>
6568
{/* Members section */}
6669
{user && isMember(user.role) && (

src/app/(authenticated)/speakers/[id]/page.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import List from "@/components/List";
2+
import { ShowMore } from "@/components/ShowMore";
23
import { SessionTile } from "@/components/session";
34
import { SpeakerService } from "@/services/SpeakerService";
45
import Image from "next/image";
@@ -41,7 +42,9 @@ export default async function Speaker({ params }: { params: SpeakerParams }) {
4142
alt={`${speaker.company.name} logo`}
4243
/>
4344
)}
44-
<p className="text-sm font-light">{speaker.description}</p>
45+
<ShowMore lines={5} className="text-sm font-light">
46+
{speaker.description}
47+
</ShowMore>
4548
</div>
4649
{/* Company Sessions */}
4750
{speakerSessions?.length ? (

src/components/EventDayButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function EventDayButton({
1818
}: EventDayButtonProps) {
1919
return (
2020
<button
21-
className="flex flex-col items-center text-center gap-y-1 py-2"
21+
className="flex flex-col items-center text-center gap-y-1 py-1"
2222
title={getEventFullDate(date)}
2323
onClick={onClick}
2424
disabled={!onClick}

src/components/GridCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ export default function GridCard({
2525
return (
2626
<Link href={link || "#"} {...linkProps}>
2727
<div className="w-[160px] min-h-[240px] flex flex-col items-center justify-between px-4 py-4 gap-y-2 text-sm bg-white rounded-md shadow-md text-center overflow-hidden hover:bg-slate-50 hover:shadow-sm active:bg-gray-200 active:shadow-none">
28-
{/* TODO: Fix large names! Truncate is not working */}
2928
<span title={title} className="h-12 w-full line-clamp-2">
3029
{title}
3130
</span>

src/components/ShowMore.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"use client";
2+
3+
import { ReactNode, useEffect, useRef, useState } from "react";
4+
import { useWindowSize } from "react-use";
5+
6+
interface ShowMoreProps {
7+
lines: 1 | 2 | 3 | 4 | 5 | 6;
8+
children: ReactNode;
9+
className?: string;
10+
}
11+
12+
const lineClamps = [
13+
"line-clamp-1",
14+
"line-clamp-2",
15+
"line-clamp-3",
16+
"line-clamp-4",
17+
"line-clamp-5",
18+
"line-clamp-6",
19+
];
20+
21+
export function ShowMore({ lines, children, className }: ShowMoreProps) {
22+
const textRef = useRef<HTMLParagraphElement>(null);
23+
const [showButton, setShowButton] = useState<boolean>(true);
24+
const [showMore, setShowMore] = useState<boolean>(false);
25+
const { width: windowWidth } = useWindowSize();
26+
27+
useEffect(() => {
28+
setShowButton(
29+
(textRef.current?.clientHeight ?? 0) <
30+
(textRef.current?.scrollHeight ?? 1),
31+
);
32+
}, [lines, windowWidth]);
33+
34+
return (
35+
<span className={className}>
36+
<p
37+
ref={textRef}
38+
className={`w-full ${showMore ? "" : lineClamps[lines - 1]}`}
39+
>
40+
{children}
41+
</p>
42+
{showButton && (
43+
<label
44+
role="button"
45+
className="font-semibold hover:cursor-pointer hover:underline"
46+
onClick={() => setShowMore((s) => !s)}
47+
>
48+
{showMore ? "Show less" : "Show more"}
49+
</label>
50+
)}
51+
</span>
52+
);
53+
}

src/components/SocialNetwork.tsx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SocialIcon } from "react-social-icons";
1+
import { SocialIcon, SocialIconProps } from "react-social-icons";
22

33
type SocialNetworkType =
44
| "linkedin"
@@ -12,15 +12,37 @@ interface SocialNetworkProps {
1212
type: SocialNetworkType;
1313
}
1414

15-
const baseHref: Record<SocialNetworkType, string> = {
16-
linkedin: "https://linkedin.com/in/",
17-
linkedinCompany: "https://linkdein.com/company/",
18-
email: "mailto:",
19-
github: "https://github.com/",
20-
website: "",
15+
type SocialNetwork = {
16+
baseHref: string;
17+
extraProps?: SocialIconProps;
18+
transform?(t: string, baseHref: string): string;
19+
};
20+
21+
const socialNetworks: Record<SocialNetworkType, SocialNetwork> = {
22+
linkedin: { baseHref: "https://linkedin.com/in/" },
23+
linkedinCompany: { baseHref: "https://linkdein.com/company/" },
24+
email: { baseHref: "mailto:" },
25+
github: { baseHref: "https://github.com/" },
26+
website: {
27+
baseHref: "",
28+
transform: (text) => {
29+
if (!text.startsWith("http")) return `https://${text}`;
30+
return text;
31+
},
32+
extraProps: { bgColor: "#323363" },
33+
},
2134
};
2235

2336
export function SocialNetwork({ text, type }: SocialNetworkProps) {
24-
const url = `${baseHref[type]}${text}`;
25-
return <SocialIcon url={url} style={{ height: 32, width: 32 }} />;
37+
const socialNetwork = socialNetworks[type];
38+
const url = socialNetwork.transform
39+
? socialNetwork.transform(text, socialNetwork.baseHref)
40+
: `${socialNetwork.baseHref}${text}`;
41+
return (
42+
<SocialIcon
43+
url={url}
44+
style={{ height: 32, width: 32 }}
45+
{...(socialNetwork.extraProps ?? {})}
46+
/>
47+
);
2648
}

src/services/UserService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export const UserService = (() => {
162162
role: "company";
163163
company: {
164164
company: string;
165-
edition: string;
165+
edition?: string;
166166
};
167167
}
168168
| {

0 commit comments

Comments
 (0)