omnivore/packages/web/components/patterns/HighlightBar.tsx

207 lines
5.7 KiB
TypeScript
Raw Permalink Normal View History

2022-06-22 18:49:35 +00:00
import { isAndroid } from '../../lib/deviceType'
2022-02-11 17:24:33 +00:00
import { styled, theme } from '../tokens/stitches.config'
2022-06-22 18:49:35 +00:00
import { Button } from '../elements/Button'
import { HStack, Box } from '../elements/LayoutPrimitives'
2024-06-10 09:34:38 +00:00
import { Circle, CheckCircle } from '@phosphor-icons/react'
2023-08-01 04:31:12 +00:00
import { LabelIcon } from '../elements/icons/LabelIcon'
2023-08-24 04:00:35 +00:00
import { NotebookIcon } from '../elements/icons/NotebookIcon'
import { highlightColor, highlightColors } from '../../lib/themeUpdater'
import { useState } from 'react'
import { CopyIcon } from '../elements/icons/CopyIcon'
2022-02-11 17:24:33 +00:00
type PageCoordinates = {
pageX: number
pageY: number
}
export type HighlightAction =
| 'delete'
| 'create'
| 'comment'
| 'share'
| 'post'
| 'unshare'
| 'setHighlightLabels'
| 'copy'
2023-08-24 04:00:35 +00:00
| 'updateColor'
2022-02-11 17:24:33 +00:00
type HighlightBarProps = {
anchorCoordinates: PageCoordinates
isNewHighlight: boolean
isSharedToFeed: boolean
displayAtBottom: boolean
2023-08-24 04:00:35 +00:00
highlightColor?: string
handleButtonClick: (action: HighlightAction, param?: string) => void
2022-02-11 17:24:33 +00:00
}
export function HighlightBar(props: HighlightBarProps): JSX.Element {
return (
<Box
css={{
2023-08-24 04:00:35 +00:00
// width: '295px',
// height: '50px',
position: props.displayAtBottom ? 'fixed' : 'absolute',
2023-08-24 04:00:35 +00:00
background: '$thBackground2',
borderRadius: '5px',
border: '1px solid $thHighlightBar',
boxShadow: `0px 4px 4px 0px rgba(0, 0, 0, 0.15)`,
Improving Self-Hosting and Removing 3rd Party dependencies. (#4513) * fix: Library Header layout shift * Bump Github Actions versions. * Self-Hosting Changes * Fix Minio Environment Variable * Just make pdfs successful, due to lack of PDFHandler * Fix issue where flag was set wrong * Added an NGINX Example file * Add some documentation for self-hosting via Docker Compose * Make some adjustments to Puppeteer due to failing sites. * adjust timings * Add start of Mail Service * Fix Docker Files * More email service stuff * Add Guide to use Zapier for Email-Importing. * Ensure that if no env is provided it uses the old email settings * Add some instructions for self-hosted email * Add SNS Endpoints for Mail Watcher * Add steps and functionality for using SES and SNS for email * Uncomment a few jobs. * Added option for Firefox for parser. Was having issues with Chromium on Docker. * Add missing space. Co-authored-by: Russ Taylor <729694+russtaylor@users.noreply.github.com> * Fix some wording on the Guide * update browser extension to handle self-hosted instances * add slight documentation to options page * Fix MV * Do raw handlers for Medium * Fix images in Medium * Update self-hosting/GUIDE.md Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> * Update Guide with other variables * Add The Verge to JS-less handlers * Update regex and image-proxy * Update self-hosting/nginx/nginx.conf Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> * Update regex and image-proxy * Update self-hosting/docker-compose/docker-compose.yml Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> * Fix Minio for Export * Merge to main * Update GUIDE with newer NGINX * Update nginx config to include api/save route * Enable Native PDF View for PDFS * Enable Native PDF View for PDFS * feat:lover packages test * feat:working build * feat:alpine build * docs:api dockerfile docs * Write a PDF.js wrapper to replace pspdfkit * Revert changes for replication, set settings to have default mode * build folder got removed due to gitignore on pdf * Add Box shadow to pdf pages * Add Toggle for Progress in PDFS, enabled native viewer toggle * Update node version to LTS * Update node version to LTS * Fix Linting issues * Fix Linting issues * Make env variable nullable * Add touchend listener for mobile * Make changes to PDF for mobile * fix(android): change serverUrl to selfhosted first * feat:2 stage alpine content fetch * feat:separated start script * fix:changed to node 22 * Add back youtube functionality and add guide * trigger build * Fix cache issue on YouTube * Allow empty AWS_S3_ENDPOINT * Allow empty AWS_S3_ENDPOINT * Add GCHR for all images * Add GCHR For self hosting. * Add GCHR For self hosting. * Test prebuilt. * Test prebuilt * Test prebuilt... * Fix web image * Remove Web Image (For now) * Move docker-compose to images * Move docker-compose files to correct locations * Remove the need for ARGS * Update packages, and Typescript versions * Fix * Fix issues with build on Web * Correct push * Fix Linting issues * Fix Trace import * Add missing types * Fix Tasks * Add information into guide about self-build * Fix issues with PDF Viewer --------- Co-authored-by: keumky2 <keumky2@woowahan.com> Co-authored-by: William Theaker <wtheaker@nvidia.com> Co-authored-by: Russ Taylor <729694+russtaylor@users.noreply.github.com> Co-authored-by: David Adams <david@dadams2.com> Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> Co-authored-by: m1xxos <66390094+m1xxos@users.noreply.github.com> Co-authored-by: Adil <mr.adil777@gmail.com>
2025-01-27 12:33:16 +00:00
zIndex: 999,
...(props.displayAtBottom && {
bottom: 'calc(38px + env(safe-area-inset-bottom, 40px))',
Improving Self-Hosting and Removing 3rd Party dependencies. (#4513) * fix: Library Header layout shift * Bump Github Actions versions. * Self-Hosting Changes * Fix Minio Environment Variable * Just make pdfs successful, due to lack of PDFHandler * Fix issue where flag was set wrong * Added an NGINX Example file * Add some documentation for self-hosting via Docker Compose * Make some adjustments to Puppeteer due to failing sites. * adjust timings * Add start of Mail Service * Fix Docker Files * More email service stuff * Add Guide to use Zapier for Email-Importing. * Ensure that if no env is provided it uses the old email settings * Add some instructions for self-hosted email * Add SNS Endpoints for Mail Watcher * Add steps and functionality for using SES and SNS for email * Uncomment a few jobs. * Added option for Firefox for parser. Was having issues with Chromium on Docker. * Add missing space. Co-authored-by: Russ Taylor <729694+russtaylor@users.noreply.github.com> * Fix some wording on the Guide * update browser extension to handle self-hosted instances * add slight documentation to options page * Fix MV * Do raw handlers for Medium * Fix images in Medium * Update self-hosting/GUIDE.md Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> * Update Guide with other variables * Add The Verge to JS-less handlers * Update regex and image-proxy * Update self-hosting/nginx/nginx.conf Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> * Update regex and image-proxy * Update self-hosting/docker-compose/docker-compose.yml Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> * Fix Minio for Export * Merge to main * Update GUIDE with newer NGINX * Update nginx config to include api/save route * Enable Native PDF View for PDFS * Enable Native PDF View for PDFS * feat:lover packages test * feat:working build * feat:alpine build * docs:api dockerfile docs * Write a PDF.js wrapper to replace pspdfkit * Revert changes for replication, set settings to have default mode * build folder got removed due to gitignore on pdf * Add Box shadow to pdf pages * Add Toggle for Progress in PDFS, enabled native viewer toggle * Update node version to LTS * Update node version to LTS * Fix Linting issues * Fix Linting issues * Make env variable nullable * Add touchend listener for mobile * Make changes to PDF for mobile * fix(android): change serverUrl to selfhosted first * feat:2 stage alpine content fetch * feat:separated start script * fix:changed to node 22 * Add back youtube functionality and add guide * trigger build * Fix cache issue on YouTube * Allow empty AWS_S3_ENDPOINT * Allow empty AWS_S3_ENDPOINT * Add GCHR for all images * Add GCHR For self hosting. * Add GCHR For self hosting. * Test prebuilt. * Test prebuilt * Test prebuilt... * Fix web image * Remove Web Image (For now) * Move docker-compose to images * Move docker-compose files to correct locations * Remove the need for ARGS * Update packages, and Typescript versions * Fix * Fix issues with build on Web * Correct push * Fix Linting issues * Fix Trace import * Add missing types * Fix Tasks * Add information into guide about self-build * Fix issues with PDF Viewer --------- Co-authored-by: keumky2 <keumky2@woowahan.com> Co-authored-by: William Theaker <wtheaker@nvidia.com> Co-authored-by: Russ Taylor <729694+russtaylor@users.noreply.github.com> Co-authored-by: David Adams <david@dadams2.com> Co-authored-by: Mike Baker <1426795+mbaker3@users.noreply.github.com> Co-authored-by: m1xxos <66390094+m1xxos@users.noreply.github.com> Co-authored-by: Adil <mr.adil777@gmail.com>
2025-01-27 12:33:16 +00:00
left: `calc(50% - ${(props.isNewHighlight ? 295 : 323) / 2}px)`
}),
...(props.displayAtBottom && {
'@smDown': {
maxWidth: '90vw',
bottom: `calc(28px + ${
isAndroid() ? 30 : 0
}px + env(safe-area-inset-bottom, 40px))`,
},
}),
...(!props.displayAtBottom && { left: props.anchorCoordinates.pageX }),
...(!props.displayAtBottom && { top: props.anchorCoordinates.pageY }),
}}
>
<BarContent {...props} />
</Box>
)
}
2023-08-24 04:00:35 +00:00
const Separator = styled('div', {
width: '1px',
height: '20px',
mx: '5px',
background: '$thHighlightBar',
})
2022-02-11 17:24:33 +00:00
function BarContent(props: HighlightBarProps): JSX.Element {
2023-08-24 04:00:35 +00:00
const [hovered, setHovered] = useState<string | undefined>(undefined)
const size = props.displayAtBottom ? 35 : 25
2022-02-11 17:24:33 +00:00
return (
<HStack
2023-08-24 04:00:35 +00:00
distribution="start"
2022-02-11 17:24:33 +00:00
alignment="center"
css={{
2023-08-24 04:00:35 +00:00
display: 'flex',
2023-08-24 06:06:30 +00:00
gap: '5px',
maxWidth: '100%',
width: props.displayAtBottom ? '100%' : 'auto',
2023-08-24 06:06:30 +00:00
padding: props.displayAtBottom ? '10px 15px' : '5px 10px',
2022-02-11 17:24:33 +00:00
}}
>
2023-08-24 04:00:35 +00:00
{highlightColors.map((color) => {
return (
<Button
key={`color-${color}`}
style="highlightBarIcon"
2023-11-01 07:16:05 +00:00
title={`Create highlight (${color})`}
2023-08-24 04:00:35 +00:00
onClick={() => {
if (!props.isNewHighlight && props.highlightColor != color) {
props.handleButtonClick('updateColor', color)
} else if (
!props.isNewHighlight &&
props.highlightColor == color
) {
props.handleButtonClick('delete')
} else {
props.handleButtonClick('create', color)
}
}}
onMouseEnter={() => {
setHovered(color)
}}
onMouseLeave={() => {
setHovered(undefined)
}}
>
{props.isNewHighlight || props.highlightColor != color ? (
<Circle
key={color}
width={size}
height={size}
2023-08-24 04:00:35 +00:00
color={highlightColor(color)}
weight="fill"
/>
) : (
<CheckCircle
key={color}
width={size}
height={size}
2023-08-24 04:00:35 +00:00
color={highlightColor(color)}
weight="fill"
2023-08-01 04:31:12 +00:00
/>
2023-08-24 04:00:35 +00:00
)}
</Button>
)
})}
<Separator />
{!props.isNewHighlight && (
<>
<Button
2023-11-01 07:16:05 +00:00
title={`Set labels`}
2023-08-24 04:00:35 +00:00
style="highlightBarIcon"
onClick={() => props.handleButtonClick('setHighlightLabels')}
2023-08-24 04:00:35 +00:00
onMouseEnter={() => {
setHovered('labels')
}}
onMouseLeave={() => {
setHovered(undefined)
}}
>
<LabelIcon
size={size}
2023-08-24 04:00:35 +00:00
color={
hovered == 'labels'
? theme.colors.thTextContrast.toString()
: theme.colors.thHighlightBar.toString()
}
/>
</Button>
</>
2022-02-11 17:24:33 +00:00
)}
2023-08-24 04:00:35 +00:00
<Button
2023-11-01 07:16:05 +00:00
title={props.isNewHighlight ? `Create highlight w/note` : 'Add note'}
2023-08-24 04:00:35 +00:00
style="highlightBarIcon"
onClick={() => props.handleButtonClick('comment')}
2023-08-24 04:00:35 +00:00
onMouseEnter={() => {
setHovered('note')
}}
onMouseLeave={() => {
setHovered(undefined)
}}
>
<NotebookIcon
size={size}
2023-08-24 04:00:35 +00:00
color={
hovered == 'note'
? theme.colors.thTextContrast.toString()
: theme.colors.thHighlightBar.toString()
}
/>
</Button>
<Button
title={`Copy`}
style="highlightBarIcon"
onClick={() => props.handleButtonClick('copy')}
2023-08-24 04:00:35 +00:00
onMouseEnter={() => {
setHovered('copy')
}}
onMouseLeave={() => {
setHovered(undefined)
}}
>
<CopyIcon
size={size}
2023-08-24 04:00:35 +00:00
color={
hovered == 'copy'
? theme.colors.thTextContrast.toString()
: theme.colors.thHighlightBar.toString()
}
/>
</Button>
2022-02-11 17:24:33 +00:00
</HStack>
)
}