-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/where-find-us
- Loading branch information
Showing
15 changed files
with
215 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
packages/frontend/components/blocks/Feedbacks/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { useFixedColorScheme } from "@/utils/hooks" | ||
import { ActionIcon, Box, Button, Popover, TextInput } from "@mantine/core" | ||
import { IconMessage, IconThumbDown, IconThumbUp } from "@tabler/icons-react" | ||
import { useState } from "react" | ||
import { Feedback } from "shared" | ||
|
||
function getColor(color: string) { | ||
const scheme = useFixedColorScheme() | ||
return scheme === "light" ? `var(--mantine-color-${color}-5)` : color | ||
} | ||
|
||
export default function Feedbacks({ | ||
feedback, | ||
updateFeedback, | ||
}: { | ||
feedback: Feedback | ||
updateFeedback: (...props: any) => any | ||
}) { | ||
if (!feedback) { | ||
feedback = { comment: null, thumb: null } | ||
} | ||
|
||
if (feedback?.thumbs) { | ||
feedback.thumb = feedback.thumbs // legacy key name | ||
} | ||
|
||
if (feedback?.thumbs && feedback.thumb) { | ||
delete feedback.thumbs | ||
} | ||
|
||
function ThumbFeedback({ value }: { value?: "up" | "down" | null }) { | ||
console.log(value) | ||
function ThumbUp() { | ||
const color = getColor(value === "up" ? "green" : "gray") | ||
return <IconThumbUp color={color} fill={color} fillOpacity={0.2} /> | ||
} | ||
|
||
function ThumbDown() { | ||
const color = getColor(value === "down" ? "red" : "gray") | ||
return <IconThumbDown color={color} fill={color} fillOpacity={0.2} /> | ||
} | ||
|
||
return ( | ||
<Box> | ||
<ActionIcon | ||
variant="transparent" | ||
onClick={() => { | ||
if (feedback.thumb === "down") { | ||
feedback.thumb = null | ||
} else { | ||
feedback.thumb = "down" | ||
} | ||
updateFeedback(feedback) | ||
}} | ||
> | ||
<ThumbDown /> | ||
</ActionIcon> | ||
<ActionIcon | ||
variant="transparent" | ||
onClick={() => { | ||
if (feedback.thumb === "up") { | ||
feedback.thumb = null | ||
} else { | ||
feedback.thumb = "up" | ||
} | ||
updateFeedback(feedback) | ||
}} | ||
> | ||
<ThumbUp /> | ||
</ActionIcon> | ||
</Box> | ||
) | ||
} | ||
|
||
function CommentFeedback({ value }) { | ||
const [comment, setComment] = useState(value) | ||
return ( | ||
<Popover width={300} trapFocus position="bottom" withArrow shadow="md"> | ||
<Popover.Target> | ||
<ActionIcon variant="transparent"> | ||
<IconMessage color={value ? "green" : "gray"} /> | ||
</ActionIcon> | ||
</Popover.Target> | ||
<Popover.Dropdown> | ||
<TextInput | ||
value={comment} | ||
size="xs" | ||
mt="xs" | ||
onChange={(e) => setComment(e.target.value)} | ||
/> | ||
<Button | ||
mt="md" | ||
size="xs" | ||
style={{ float: "right" }} | ||
onClick={() => { | ||
feedback.comment = comment | ||
updateFeedback(feedback) | ||
}} | ||
> | ||
Save | ||
</Button> | ||
</Popover.Dropdown> | ||
</Popover> | ||
) | ||
} | ||
|
||
console.log(feedback) | ||
return ( | ||
<> | ||
<CommentFeedback value={feedback?.comment} /> | ||
<ThumbFeedback value={feedback?.thumb} /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.