Skip to content
Snippets Groups Projects
Commit 9f5056bb authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Added the same long text handeling to comments and projects

parent 8431efd1
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import { getUser, User } from 'adapters/user'; ...@@ -6,6 +6,7 @@ import { getUser, User } from 'adapters/user';
import { Comment as IComment } from 'adapters/comment'; import { Comment as IComment } from 'adapters/comment';
import Avatar from 'components/ui/Avatar'; import Avatar from 'components/ui/Avatar';
import LongText from 'components/ui/LongText';
import './comment.scss'; import './comment.scss';
...@@ -39,7 +40,7 @@ export default function Comment({ comment }: CommentProps) { ...@@ -39,7 +40,7 @@ export default function Comment({ comment }: CommentProps) {
</div> </div>
</div> </div>
<div className="comment"> <div className="comment">
{comment.text} <LongText text={comment.text} />
</div> </div>
</div> </div>
) )
......
import { useState } from 'react';
interface Props {
text: string;
}
export default function LongText({ text }: Props) {
const [more, setMore] = useState(false);
return (
(text.length < 300)
? <p>{text}</p>
: (more
? <>
<p>{text}</p>
<button onClick={() => setMore(false)}>less</button>
</>
: <>
<p>{text.substr(0, 300) + '... '}</p>
<button onClick={() => setMore(true)}>more</button>
</>
)
);
}
...@@ -33,6 +33,7 @@ button { ...@@ -33,6 +33,7 @@ button {
} }
a, button { a, button {
font-size: 1em;
font-weight: s.$weight-semi-bold; font-weight: s.$weight-semi-bold;
color: s.$primary; color: s.$primary;
text-decoration: none; text-decoration: none;
......
...@@ -6,6 +6,7 @@ import { StatusColors } from 'adapters/common'; ...@@ -6,6 +6,7 @@ import { StatusColors } from 'adapters/common';
import { getProject, Project } from 'adapters/project'; import { getProject, Project } from 'adapters/project';
import Tag from 'components/ui/Tag'; import Tag from 'components/ui/Tag';
import LongText from 'components/ui/LongText';
import Tabs, { Tab } from 'components/navigation/Tabs'; import Tabs, { Tab } from 'components/navigation/Tabs';
import LoadingScreen from 'components/ui/LoadingScreen'; import LoadingScreen from 'components/ui/LoadingScreen';
...@@ -55,9 +56,7 @@ export default function ProjectDetail() { ...@@ -55,9 +56,7 @@ export default function ProjectDetail() {
<Tag label={project.status} color={StatusColors.get(project.status)} /> <Tag label={project.status} color={StatusColors.get(project.status)} />
<h1>{project.name}</h1> <h1>{project.name}</h1>
<div className="description-container"> <div className="description-container">
<p> <LongText text={project.text} />
{project.text}
</p>
</div> </div>
{ {
tabs tabs
......
...@@ -9,6 +9,7 @@ import { getProject, Project } from 'adapters/project'; ...@@ -9,6 +9,7 @@ import { getProject, Project } from 'adapters/project';
import { getTask, getTaskAssignees, Task, TaskAssignment } from 'adapters/task'; import { getTask, getTaskAssignees, Task, TaskAssignment } from 'adapters/task';
import Tag from 'components/ui/Tag'; import Tag from 'components/ui/Tag';
import LongText from 'components/ui/LongText';
import Tabs from 'components/navigation/Tabs'; import Tabs from 'components/navigation/Tabs';
import DetailGrid from 'components/layout/DetailGrid'; import DetailGrid from 'components/layout/DetailGrid';
import LoadingScreen from 'components/ui/LoadingScreen'; import LoadingScreen from 'components/ui/LoadingScreen';
...@@ -25,7 +26,6 @@ export interface Params { ...@@ -25,7 +26,6 @@ export interface Params {
} }
export default function TaskDetail() { export default function TaskDetail() {
const [more, setMore] = useState(false);
const [task, setTask] = useState<Task>(); const [task, setTask] = useState<Task>();
const [project, setProject] = useState<Project>(); const [project, setProject] = useState<Project>();
const [teamNames, setTeamNames] = useState<string[]>([]); const [teamNames, setTeamNames] = useState<string[]>([]);
...@@ -49,7 +49,7 @@ export default function TaskDetail() { ...@@ -49,7 +49,7 @@ export default function TaskDetail() {
getTaskAssignees(taskId).then(setAssignees); getTaskAssignees(taskId).then(setAssignees);
setAssignment(task.assigned.find(a => a.user === userId)) setAssignment(task.assigned.find(a => a.user === userId))
}).catch(() => history.goBack()); }).catch(() => history.goBack());
}, [taskId, history]); }, [taskId, userId, history]);
if (task) { if (task) {
return ( return (
...@@ -61,20 +61,7 @@ export default function TaskDetail() { ...@@ -61,20 +61,7 @@ export default function TaskDetail() {
<Tag label={task.status} color={StatusColors.get(task.status)} /> <Tag label={task.status} color={StatusColors.get(task.status)} />
<h1>{task.name}</h1> <h1>{task.name}</h1>
<div className="description-container"> <div className="description-container">
{ <LongText text={task.text} />
(task.text.length < 300)
? <p>{task.text}</p>
: (more
? <>
<p>{task.text}</p>
<a onClick={() => setMore(false)}>less</a>
</>
: <>
<p>{task.text.substr(0, 300) + '... '}</p>
<a onClick={() => setMore(true)}>more</a>
</>
)
}
</div> </div>
<h2> <h2>
Details Details
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment