forked from open-eats/openeats-web
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
355 additions
and
139 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
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 |
---|---|---|
|
@@ -201,4 +201,7 @@ | |
th.visible-sm, td.visible-sm { | ||
display: table-cell !important; | ||
} | ||
a.headerlink { | ||
display: none !important; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Link } from 'react-router-dom'; | ||
|
||
import '../css/header_link.css'; | ||
import PageScroller from './PageScroller'; | ||
|
||
export interface IHeaderLinkProps { | ||
linkFor: string; | ||
} | ||
|
||
const HeaderLink: React.FC<IHeaderLinkProps> = ({ linkFor }: IHeaderLinkProps) => ( | ||
<> | ||
<Link className='headerlink' to={`#${linkFor}`} title='Permalink to this headline'>¶</Link> | ||
<PageScroller uriFragmentId={linkFor} /> | ||
</> | ||
); | ||
|
||
export default HeaderLink; |
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,41 @@ | ||
import { useEffect } from 'react'; | ||
import { useLocation } from 'react-router'; | ||
import { scrollToElement } from '../utility'; | ||
|
||
export interface IPageScrollerProps { | ||
uriFragmentId?: string; | ||
} | ||
|
||
const PageScroller: React.FC<IPageScrollerProps> = ({ uriFragmentId }: IPageScrollerProps) => { | ||
const { pathname, hash, key } = useLocation(); | ||
|
||
useEffect(() => { | ||
if (hash === '') { | ||
if (!uriFragmentId) { | ||
setTimeout(() => { | ||
// console.log('[PageScroller] No hash, scroll to top.'); | ||
window.scrollTo(0, 0); | ||
}, 0); | ||
} | ||
} else { | ||
setTimeout(() => { | ||
const mainContainerId = 'main-container'; | ||
const mainContainerElem = document.getElementById(mainContainerId); | ||
const mainContainerOffset = ((mainContainerElem?.getBoundingClientRect?.().top ?? 0) + window.scrollY) ?? 0; | ||
|
||
const id = hash.replace('#', ''); | ||
if (uriFragmentId && id !== uriFragmentId) return; | ||
const elem = document.getElementById(id); | ||
|
||
if (elem) { | ||
// console.log(`[PageScroller] Scroll to elem "${id}".`); | ||
scrollToElement(elem, mainContainerOffset + 50); | ||
} | ||
}, 0); | ||
} | ||
}, [pathname, hash, key]); | ||
|
||
return null; | ||
}; | ||
|
||
export default PageScroller; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
a.headerlink { | ||
visibility: hidden; | ||
padding: 0 4px; | ||
color: inherit; | ||
text-decoration: none; | ||
text-decoration-color: currentColor; | ||
} | ||
|
||
h1:hover > a.headerlink, h2:hover > a.headerlink, h3:hover > a.headerlink, h4:hover > a.headerlink, h5:hover > a.headerlink, h6:hover > a.headerlink, dt:hover > a.headerlink, caption:hover > a.headerlink, p.caption:hover > a.headerlink, div.code-block-caption:hover > a.headerlink { | ||
visibility: visible; | ||
} | ||
|
||
a.headerlink:hover { | ||
background-color: var(--hoverBg); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { useState } from 'react'; | ||
import { defineMessages, useIntl } from 'react-intl'; | ||
import { Button, Col, Row } from 'react-bootstrap'; | ||
|
||
import { Rating } from '../store/types'; | ||
import Icon from '../../common/components/Icon'; | ||
import P from '../../common/components/P'; | ||
import Modal from '../../common/components/Modal'; | ||
import Ratings from './Ratings'; | ||
import { Link } from 'react-router-dom'; | ||
import PageScroller from '../../common/components/PageScroller'; | ||
import { useLocation } from 'react-router'; | ||
import classNames from 'classnames'; | ||
|
||
export interface IRatingCommentProps { | ||
rating: Rating; | ||
onDelete?: (ratingId: number) => void; | ||
} | ||
|
||
interface IRatingTimestampProps { | ||
rating: Rating; | ||
} | ||
|
||
const RatingTimestamp: React.FC<IRatingTimestampProps> = ({ rating }: IRatingTimestampProps) => { | ||
const intl = useIntl(); | ||
if (rating.updateDate && new Date(rating.updateDate).getTime() > 0) { | ||
return <Link className='rating-timestamp' to={`#rating-${rating.id}`}>{new Date(rating.updateDate).toLocaleString(intl.locale)}</Link>; | ||
} else if (rating.pubDate && new Date(rating.pubDate).getTime() > 0) { | ||
return <Link className='rating-timestamp' to={`#rating-${rating.id}`}>{new Date(rating.pubDate).toLocaleString(intl.locale)}</Link>; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
interface IRatingCommentCommentProps { | ||
rating: Rating; | ||
} | ||
|
||
const RatingCommentComment: React.FC<IRatingCommentCommentProps> = ({ rating }: IRatingCommentCommentProps) => ( | ||
<P> | ||
{rating.comment} | ||
</P> | ||
); | ||
|
||
const RatingComment: React.FC<IRatingCommentProps> = ({ | ||
rating, onDelete }: IRatingCommentProps) => { | ||
const intl = useIntl(); | ||
|
||
const messages = defineMessages({ | ||
confirm_delete_message: { | ||
id: 'rating_comments.confirm_delete', | ||
description: 'Are you sure you want to delete this comment?', | ||
defaultMessage: 'Are you sure you want to delete this comment?', | ||
}, | ||
}); | ||
|
||
const { hash } = useLocation(); | ||
const hashId = (hash ?? '').replace('#', ''); | ||
|
||
const [showDeleteConfirm, setShowDeleteConfirm] = useState<number | undefined>(); | ||
const handleDeleteClick = (ratingId: number) => { setShowDeleteConfirm(ratingId); }; | ||
const handleDeleteAccept = () => { onDelete?.(showDeleteConfirm ?? 0); }; | ||
const handleDeleteClose = () => { setShowDeleteConfirm(undefined); }; | ||
|
||
const ratingContainerId = `rating-${rating.id}`; | ||
|
||
return ( | ||
<div id={ratingContainerId} className={classNames('rating-comment', { 'perma-link-active': ratingContainerId === hashId })}> | ||
<PageScroller uriFragmentId={ratingContainerId} /> | ||
<Row> | ||
<Col xs> | ||
<Ratings stars={rating.rating || 0} /> | ||
<div className='rating-username'>{rating.userName}</div> | ||
</Col> | ||
<Col xs='auto'> | ||
<RatingTimestamp rating={rating} /> | ||
{onDelete && ( | ||
<Button variant='outline-danger' className='rating-delete-button' size='sm' onClick={() => handleDeleteClick(rating.id)}> | ||
<Icon icon='trash' /> | ||
</Button> | ||
)} | ||
</Col> | ||
</Row> | ||
<Row> | ||
<Col xs={12}> | ||
<RatingCommentComment rating={rating} /> | ||
</Col> | ||
</Row> | ||
|
||
<Modal | ||
show = {showDeleteConfirm != null} | ||
title = {intl.messages['recipe.confirm_delete_title'] as string} | ||
acceptTitle = {intl.messages['recipe.confirm_delete_accept'] as string} | ||
onAccept = {handleDeleteAccept} | ||
onClose = {handleDeleteClose} | ||
acceptButtonProps = {{ variant: 'danger' }}> | ||
{intl.formatMessage(messages.confirm_delete_message)} | ||
</Modal> | ||
</div> | ||
); | ||
}; | ||
|
||
export default RatingComment; |
Oops, something went wrong.