Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

More functionality working

Matt Roberts2f602f34aaa9
diff --git a/public/components/VoteCounter.tsx b/public/components/VoteCounter.tsx
index 22f17cf1e..88f658570 100644
--- a/public/components/VoteCounter.tsx
+++ b/public/components/VoteCounter.tsx
@@ -7,7 +7,7 @@ import { Icon, SignInModal } from "@fider/components"
import { useFider } from "@fider/hooks"
import FaCaretUp from "@fider/assets/images/fa-caretup.svg"
-interface VoteCounterProps {
+export interface VoteCounterProps {
post: Post
}
diff --git a/public/components/VoteCounter2.tsx b/public/components/VoteCounter2.tsx
new file mode 100644
index 000000000..48554254a
--- /dev/null
+++ b/public/components/VoteCounter2.tsx
@@ -0,0 +1,63 @@
+import "./VoteCounter.scss"
+
+import React, { useState } from "react"
+import { Post, PostStatus } from "@fider/models"
+import { actions, classSet } from "@fider/services"
+import { Icon, SignInModal } from "@fider/components"
+import { useFider } from "@fider/hooks"
+import FaCaretUp from "@fider/assets/images/fa-caretup.svg"
+import { VoteCounterProps } from "@fider/components"
+
+export const VoteCounter2 = (props: VoteCounterProps) => {
+ const fider = useFider()
+ const [hasVoted, setHasVoted] = useState(props.post.hasVoted)
+ const [votesCount, setVotesCount] = useState(props.post.votesCount)
+ const [isSignInModalOpen, setIsSignInModalOpen] = useState(false)
+
+ const voteOrUndo = async () => {
+ if (!fider.session.isAuthenticated) {
+ setIsSignInModalOpen(true)
+ return
+ }
+
+ const action = hasVoted ? actions.removeVote : actions.addVote
+
+ const response = await action(props.post.number)
+ if (response.ok) {
+ setVotesCount(votesCount + (hasVoted ? -1 : 1))
+ setHasVoted(!hasVoted)
+ }
+ }
+
+ const hideModal = () => setIsSignInModalOpen(false)
+
+ const status = PostStatus.Get(props.post.status)
+ const isDisabled = status.closed || fider.isReadOnly
+
+ const className = classSet({
+ "c-vote-counter__button": true,
+ "c-vote-counter__button--voted": !status.closed && hasVoted,
+ "c-vote-counter__button--disabled": isDisabled,
+ })
+
+ const vote = (
+ <button className={className} onClick={voteOrUndo}>
+ <Icon sprite={FaCaretUp} height="16" width="16" />
+ {votesCount}
+ </button>
+ )
+
+ const disabled = (
+ <button className={className}>
+ <Icon sprite={FaCaretUp} height="16" width="16" />
+ {votesCount}
+ </button>
+ )
+
+ return (
+ <>
+ <SignInModal isOpen={isSignInModalOpen} onClose={hideModal} />
+ <div className="c-vote-counter">{isDisabled ? disabled : vote}</div>
+ </>
+ )
+}
diff --git a/public/components/common/Button.scss b/public/components/common/Button.scss
index b9dcb3f37..f8d5ba528 100644
--- a/public/components/common/Button.scss
+++ b/public/components/common/Button.scss
@@ -30,6 +30,16 @@
}
}
+ &--quaternary {
+ color: get("colors.gray.900");
+ background-color: transparent;
+ border: 1px solid get("colors.primary.base");
+
+ &:hover {
+ text-decoration: underline;
+ }
+ }
+
&--secondary {
color: get("colors.gray.900");
background-color: get("colors.gray.50");
@@ -143,3 +153,5 @@
transform: rotate(360deg);
}
}
+
+
diff --git a/public/components/common/Button.tsx b/public/components/common/Button.tsx
index 3bc6423b0..208aa5936 100644
--- a/public/components/common/Button.tsx
+++ b/public/components/common/Button.tsx
@@ -10,7 +10,7 @@ interface ButtonProps {
rel?: "nofollow"
target?: "_self" | "_blank" | "_parent" | "_top"
type?: "button" | "submit"
- variant?: "primary" | "danger" | "secondary" | "tertiary"
+ variant?: "primary" | "danger" | "secondary" | "tertiary" | "quaternary"
size?: "small" | "default" | "large"
onClick?: (event: ButtonClickEvent) => Promise<any> | void
}
diff --git a/public/pages/ShowPost/ShowPost.page.tsx b/public/pages/ShowPost/ShowPost.page.tsx
index 253720145..5e6a1a5db 100644
--- a/public/pages/ShowPost/ShowPost.page.tsx
+++ b/public/pages/ShowPost/ShowPost.page.tsx
@@ -4,6 +4,7 @@ import React from "react"
import { Comment, Post, Tag, Vote, ImageUpload, CurrentUser } from "@fider/models"
import { actions, clearUrlHash, Failure, Fider, notify, timeAgo } from "@fider/services"
+import IconDotsHorizontal from "@fider/assets/images/heroicons-dots-horizontal.svg"
import {
ShowPostResponse,
@@ -20,6 +21,7 @@ import {
Header,
PoweredByFider,
Avatar,
+ Dropdown,
} from "@fider/components"
import { ResponseForm } from "./components/ResponseForm"
import { TagsPanel } from "./components/TagsPanel"
@@ -34,6 +36,8 @@ 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"
+import { NotificationsPanel2 } from "./components/NotificationsPanel2"
+import { VoteSection } from "./components/VoteSection"
interface ShowPostPageProps {
post: Post
@@ -141,6 +145,10 @@ export default class ShowPostPage extends React.Component<ShowPostPageProps, Sho
this.setState({ highlightedComment })
}
+ public onActionSelected = (action: string) => () => {
+ console.log(action)
+ }
+
public render() {
return (
<>
@@ -152,25 +160,43 @@ export default class ShowPostPage extends React.Component<ShowPostPageProps, Sho
<VStack spacing={6}>
{/* <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="mt-2">
- <TagsPanel2 post={this.props.post} tags={this.props.tags} />
+ <HStack justify="between">
+ <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>
- </div>
-
- <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>
+ <Dropdown position="left" renderHandle={<Icon sprite={IconDotsHorizontal} width="24" height="24" />}>
+ <Dropdown.ListItem onClick={this.onActionSelected("copy")}>
+ <Trans id="action.copylink">Copy link</Trans>
+ </Dropdown.ListItem>
+ <Dropdown.ListItem onClick={this.onActionSelected("edit")}>
+ <Trans id="action.edit">Edit</Trans>
+ </Dropdown.ListItem>
+ <Dropdown.ListItem onClick={this.onActionSelected("status")}>
+ <Trans id="action.respond">Respond</Trans>
+ </Dropdown.ListItem>
+ <Dropdown.ListItem onClick={this.onActionSelected("delete")} className="text-red-700">
+ <Trans id="action.delete">Delete</Trans>
+ </Dropdown.ListItem>
+ </Dropdown>
+ </HStack>
+ <HStack spacing={4} justify="between">
+ <HStack>
+ <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>
+ <NotificationsPanel2 post={this.props.post} subscribed={this.props.subscribed} />
</HStack>
{/* <span className="text-muted">
@@ -201,7 +227,10 @@ export default class ShowPostPage extends React.Component<ShowPostPageProps, Sho
</>
)}
</VStack>
- <div className="align-self-start">
+
+ <VoteSection post={this.props.post} votes={this.props.votes} />
+
+ {/* <div className="align-self-start">
<Button variant="primary" onClick={this.saveChanges} disabled={Fider.isReadOnly}>
<Icon sprite={IconThumbsUp} />{" "}
<span>
@@ -217,7 +246,7 @@ export default class ShowPostPage extends React.Component<ShowPostPageProps, Sho
<div className="pl-4">
<VotesPanel post={this.props.post} votes={this.props.votes} hideTitle={true} />
</div>
- </HStack>
+ </HStack> */}
<div className="purple-border" />
<ShowPostResponse status={this.props.post.status} response={this.props.post.response} />
diff --git a/public/pages/ShowPost/components/NotificationsPanel.tsx b/public/pages/ShowPost/components/NotificationsPanel.tsx
index c9ee001ac..0de322a1c 100644
--- a/public/pages/ShowPost/components/NotificationsPanel.tsx
+++ b/public/pages/ShowPost/components/NotificationsPanel.tsx
@@ -8,7 +8,7 @@ import IconVolumeOff from "@fider/assets/images/heroicons-volume-off.svg"
import { VStack } from "@fider/components/layout"
import { Trans } from "@lingui/macro"
-interface NotificationsPanelProps {
+export interface NotificationsPanelProps {
post: Post
subscribed: boolean
}
diff --git a/public/pages/ShowPost/components/NotificationsPanel2.tsx b/public/pages/ShowPost/components/NotificationsPanel2.tsx
new file mode 100644
index 000000000..85776d06d
--- /dev/null
+++ b/public/pages/ShowPost/components/NotificationsPanel2.tsx
@@ -0,0 +1,45 @@
+import React, { useState } from "react"
+import { Button, Icon } from "@fider/components"
+import { actions } from "@fider/services"
+import { useFider } from "@fider/hooks"
+import IconVolumeOn from "@fider/assets/images/heroicons-volume-on.svg"
+import IconVolumeOff from "@fider/assets/images/heroicons-volume-off.svg"
+import { VStack } from "@fider/components/layout"
+import { Trans } from "@lingui/macro"
+import { NotificationsPanelProps } from "./NotificationsPanel"
+
+export const NotificationsPanel2 = (props: NotificationsPanelProps) => {
+ const fider = useFider()
+ const [subscribed, setSubscribed] = useState(props.subscribed)
+
+ const subscribeOrUnsubscribe = async () => {
+ const action = subscribed ? actions.unsubscribe : actions.subscribe
+
+ const response = await action(props.post.number)
+ if (response.ok) {
+ setSubscribed(!subscribed)
+ }
+ }
+
+ if (!fider.session.isAuthenticated) {
+ return null
+ }
+
+ const button = subscribed ? (
+ <Button variant="quaternary" className="w-full text-primary-base" onClick={subscribeOrUnsubscribe} disabled={fider.isReadOnly}>
+ <Icon sprite={IconVolumeOff} />{" "}
+ <span>
+ <Trans id="label.unfollow">Unfollow</Trans>
+ </span>
+ </Button>
+ ) : (
+ <Button variant="quaternary" className="w-full text-primary-base" onClick={subscribeOrUnsubscribe} disabled={fider.isReadOnly}>
+ <Icon sprite={IconVolumeOn} />
+ <span>
+ <Trans id="label.follow">Follow</Trans>
+ </span>
+ </Button>
+ )
+
+ return <VStack>{button}</VStack>
+}
diff --git a/public/pages/ShowPost/components/TagsPanel2.tsx b/public/pages/ShowPost/components/TagsPanel2.tsx
index 0c12c1bbf..cef41e972 100644
--- a/public/pages/ShowPost/components/TagsPanel2.tsx
+++ b/public/pages/ShowPost/components/TagsPanel2.tsx
@@ -1,11 +1,10 @@
import React, { useState } from "react"
import { Tag } from "@fider/models"
import { actions } from "@fider/services"
-import { ShowTag, Icon } from "@fider/components"
+import { ShowTag, Icon, Button } 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"
@@ -48,22 +47,27 @@ export const TagsPanel2 = (props: TagsPanelProps) => {
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 tagsList = (
+ <HStack spacing={2} center={true}>
+ {assignedTags.length > 0 && assignedTags.map((tag) => <ShowTag key={tag.id} tag={tag} link />)}
+ <HStack spacing={1} center={true} className="clickable" onClick={onSubtitleClick}>
+ <Icon sprite={IconPlusCircle} className="h-5 text-primary" />
+ <span>Edit Tags</span>
+ </HStack>
+ </HStack>
)
+
const editTagsList = props.tags.length > 0 && (
- <VStack>
+ <VStack justify="between" className="flex-items-start">
{props.tags.map((tag) => (
<TagListItem key={tag.id} tag={tag} assigned={assignedTags.indexOf(tag) >= 0} onClick={assignOrUnassignTag} />
))}
+ <Button variant="secondary" size="small" onClick={onSubtitleClick}>
+ <Trans id="action.close">Close</Trans>
+ </Button>
</VStack>
)
- const icon = canEdit && (isEditing ? <Icon sprite={IconCheckCircle} className="h-4" /> : <Icon sprite={IconPlusCircle} className="h-5 text-primary" />)
if (fider.isReadOnly) {
return (
@@ -81,10 +85,6 @@ export const TagsPanel2 = (props: TagsPanelProps) => {
<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>
)
diff --git a/public/pages/ShowPost/components/VoteSection.tsx b/public/pages/ShowPost/components/VoteSection.tsx
new file mode 100644
index 000000000..f5f6754a2
--- /dev/null
+++ b/public/pages/ShowPost/components/VoteSection.tsx
@@ -0,0 +1,70 @@
+import React, { useState } from "react"
+import { Post, PostStatus, Vote } from "@fider/models"
+import { actions } from "@fider/services"
+import { Button, Icon, SignInModal } from "@fider/components"
+import { useFider } from "@fider/hooks"
+import IconThumbsUp from "@fider/assets/images/heroicons-thumbsup.svg"
+import IconCheck from "@fider/assets/images/heroicons-check.svg"
+import { Trans } from "@lingui/macro"
+import { HStack } from "@fider/components/layout"
+import { VotesPanel } from "./VotesPanel"
+
+interface VoteSectionProps {
+ post: Post
+ votes: Vote[]
+}
+
+export const VoteSection = (props: VoteSectionProps) => {
+ const fider = useFider()
+ const [hasVoted, setHasVoted] = useState(props.post.hasVoted)
+ const [votes, setVotes] = useState(props.votes)
+ const [post, setPost] = useState(props.post)
+ const [isSignInModalOpen, setIsSignInModalOpen] = useState(false)
+
+ const voteOrUndo = async () => {
+ if (!fider.session.isAuthenticated) {
+ setIsSignInModalOpen(true)
+ return
+ }
+
+ const action = hasVoted ? actions.removeVote : actions.addVote
+
+ const response = await action(props.post.number)
+ if (response.ok) {
+ const newVotes: Vote[] = hasVoted
+ ? votes.filter((vote) => vote.user.id !== fider.session.user.id)
+ : [...votes, { user: fider.session.user, createdAt: new Date() }]
+
+ setPost({ ...post, votesCount: newVotes.length })
+ setVotes(newVotes)
+ setHasVoted(!hasVoted)
+ }
+ }
+
+ const hideModal = () => setIsSignInModalOpen(false)
+
+ const status = PostStatus.Get(props.post.status)
+ const isDisabled = status.closed || fider.isReadOnly
+
+ const buttonText = hasVoted ? <Trans id="action.voted">Voted!</Trans> : <Trans id="action.vote">Vote for this idea</Trans>
+ const icon = hasVoted ? IconCheck : IconThumbsUp
+
+ return (
+ <>
+ <SignInModal isOpen={isSignInModalOpen} onClose={hideModal} />
+ <div className="align-self-start">
+ <Button variant="primary" onClick={voteOrUndo} disabled={isDisabled}>
+ <Icon sprite={icon} /> <span>{buttonText}</span>
+ </Button>
+ </div>
+ <HStack>
+ <span className="text-display">
+ {votes.length} {votes.length === 1 ? "Vote" : "Votes"}
+ </span>
+ <div className="pl-4">
+ <VotesPanel post={post} votes={votes} hideTitle={true} />
+ </div>
+ </HStack>
+ </>
+ )
+}