Open platform to collect and prioritize feedback
More layout for the show post page
Matt Robertse52c7d073997
diff --git a/public/assets/images/heroicons-pluscircle.svg b/public/assets/images/heroicons-pluscircle.svgnew file mode 100644index 000000000..72131e2bf--- /dev/null+++ b/public/assets/images/heroicons-pluscircle.svg@@ -0,0 +1,3 @@+<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v6m3-3H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" />+</svg>diff --git a/public/pages/ShowPost/ShowPost.page.tsx b/public/pages/ShowPost/ShowPost.page.tsxindex 3ebc67ce6..253720145 100644--- a/public/pages/ShowPost/ShowPost.page.tsx+++ b/public/pages/ShowPost/ShowPost.page.tsx@@ -33,6 +33,7 @@ import IconPencilAlt from "@fider/assets/images/heroicons-pencil-alt.svg"import IconThumbsUp from "@fider/assets/images/heroicons-thumbsup.svg"import { HStack, VStack } from "@fider/components/layout"import { Trans } from "@lingui/macro"+import { TagsPanel2 } from "./components/TagsPanel2"interface ShowPostPageProps {post: Post@@ -149,33 +150,34 @@ export default class ShowPostPage extends React.Component<ShowPostPageProps, Sho<div className="p-show-post__main-col"><div className="p-show-post__header-col"><VStack spacing={6}>- <HStack>- {/* <VoteCounter post={this.props.post} /> */}+ {/* <VoteCounter post={this.props.post} /> */}- <div className="flex-grow">- {this.state.editMode ? (- <Form error={this.state.error}>- <Input field="title" maxLength={100} value={this.state.newTitle} onChange={this.setNewTitle} />- </Form>- ) : (- <h1 className="text-large">{this.props.post.title}</h1>- )}+ <div className="flex-grow">+ {this.state.editMode ? (+ <Form error={this.state.error}>+ <Input field="title" maxLength={100} value={this.state.newTitle} onChange={this.setNewTitle} />+ </Form>+ ) : (+ <h1 className="text-large">{this.props.post.title}</h1>+ )}+ <div className="mt-2">+ <TagsPanel2 post={this.props.post} tags={this.props.tags} />+ </div>+ </div>- <HStack spacing={4} className="my-3 mt-4">- <Avatar user={this.props.post.user} />- <VStack spacing={1}>- <UserName user={this.props.post.user} />- <Moment className="text-muted" locale={Fider.currentLocale} date={this.props.post.createdAt} />- </VStack>- </HStack>+ <HStack spacing={4}>+ <Avatar user={this.props.post.user} />+ <VStack spacing={1}>+ <UserName user={this.props.post.user} />+ <Moment className="text-muted" locale={Fider.currentLocale} date={this.props.post.createdAt} />+ </VStack>+ </HStack>- {/* <span className="text-muted">+ {/* <span className="text-muted"><Trans id="showpost.label.author">Posted by <UserName user={this.props.post.user} /> · <Moment locale={Fider.currentLocale} date={this.props.post.createdAt} /></Trans></span> */}- </div>- </HStack><VStack className="flex-items-start">{/* <span className="text-category"><Trans id="label.description">Description</Trans>diff --git a/public/pages/ShowPost/components/TagsPanel.tsx b/public/pages/ShowPost/components/TagsPanel.tsxindex 0a23df773..c58873541 100644--- a/public/pages/ShowPost/components/TagsPanel.tsx+++ b/public/pages/ShowPost/components/TagsPanel.tsx@@ -10,7 +10,7 @@ import IconCheckCircle from "@fider/assets/images/heroicons-check-circle.svg"import { HStack, VStack } from "@fider/components/layout"import { Trans } from "@lingui/macro"-interface TagsPanelProps {+export interface TagsPanelProps {post: Posttags: Tag[]}diff --git a/public/pages/ShowPost/components/TagsPanel2.tsx b/public/pages/ShowPost/components/TagsPanel2.tsxnew file mode 100644index 000000000..0c12c1bbf--- /dev/null+++ b/public/pages/ShowPost/components/TagsPanel2.tsx@@ -0,0 +1,91 @@+import React, { useState } from "react"+import { Tag } from "@fider/models"+import { actions } from "@fider/services"+import { ShowTag, Icon } from "@fider/components"+import { TagListItem } from "./TagListItem"+import { useFider } from "@fider/hooks"++import IconCheckCircle from "@fider/assets/images/heroicons-check-circle.svg"+import IconPlusCircle from "@fider/assets/images/heroicons-pluscircle.svg"+import { HStack, VStack } from "@fider/components/layout"+import { Trans } from "@lingui/macro"+import { TagsPanelProps } from "./TagsPanel"++export const TagsPanel2 = (props: TagsPanelProps) => {+ const fider = useFider()+ const canEdit = fider.session.isAuthenticated && fider.session.user.isCollaborator && props.tags.length > 0++ const [isEditing, setIsEditing] = useState(false)+ const [assignedTags, setAssignedTags] = useState(props.tags.filter((t) => props.post.tags.indexOf(t.slug) >= 0))++ const assignOrUnassignTag = async (tag: Tag) => {+ const idx = assignedTags.indexOf(tag)+ let nextAssignedTags: Tag[] = []++ if (idx >= 0) {+ const response = await actions.unassignTag(tag.slug, props.post.number)+ if (response.ok) {+ nextAssignedTags = [...assignedTags]+ nextAssignedTags.splice(idx, 1)+ }+ } else {+ const response = await actions.assignTag(tag.slug, props.post.number)+ if (response.ok) {+ nextAssignedTags = [...assignedTags, tag]+ }+ }++ setAssignedTags(nextAssignedTags)+ }++ const onSubtitleClick = () => {+ if (canEdit) {+ setIsEditing(!isEditing)+ }+ }++ if (!canEdit && assignedTags.length === 0) {+ return null+ }++ const tagsList = assignedTags.length > 0 && (+ <VStack spacing={2} className="flex-items-baseline">+ {assignedTags.map((tag) => (+ <ShowTag key={tag.id} tag={tag} link />+ ))}+ </VStack>+ )+ const editTagsList = props.tags.length > 0 && (+ <VStack>+ {props.tags.map((tag) => (+ <TagListItem key={tag.id} tag={tag} assigned={assignedTags.indexOf(tag) >= 0} onClick={assignOrUnassignTag} />+ ))}+ </VStack>+ )++ const icon = canEdit && (isEditing ? <Icon sprite={IconCheckCircle} className="h-4" /> : <Icon sprite={IconPlusCircle} className="h-5 text-primary" />)++ if (fider.isReadOnly) {+ return (+ <VStack>+ <HStack spacing={2} className="text-category">+ <Trans id="label.tags">Tags</Trans>+ </HStack>+ {tagsList}+ </VStack>+ )+ }++ return (+ <VStack>+ <HStack spacing={2} center={true} className="text-primary-base text-xs">+ {!isEditing && tagsList}+ {isEditing && editTagsList}+ <HStack spacing={1} className="clickable" onClick={onSubtitleClick}>+ {icon}+ <span>Edit Tags</span>+ </HStack>+ </HStack>+ </VStack>+ )+}