Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor feed to use links; add dark mode etc #81

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 114 additions & 26 deletions newswires/client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import {
EuiButton,
EuiButtonIcon,
EuiContextMenu,
EuiEmptyPrompt,
EuiFlexGroup,
EuiFlexItem,
EuiHeader,
EuiHeaderLinks,
EuiHeaderSection,
EuiHeaderSectionItem,
EuiPageTemplate,
EuiPopover,
EuiProvider,
EuiResizableContainer,
EuiShowFor,
EuiSpacer,
EuiSwitch,
EuiTitle,
useGeneratedHtmlId,
} from '@elastic/eui';
import { css } from '@emotion/react';
import { useState } from 'react';
import { Feed } from './Feed';
import { Item } from './Item';
import { SideNav } from './SideNav';
Expand All @@ -33,13 +36,73 @@ export function App() {
toggleAutoUpdate,
} = useSearch();

const [colourMode, setColourMode] = useState<'light' | 'dark'>('light');

const toggleColourMode = () => {
setColourMode(colourMode === 'light' ? 'dark' : 'light');
};
const contextMenuPopoverId = useGeneratedHtmlId();
const panels = [
{
id: 0,
title: 'Options',
items: [
{
name: 'Dark mode',
icon: (
<EuiSwitch
checked={colourMode === 'dark'}
onChange={toggleColourMode}
label={undefined}
/>
),
},
{
name: 'Auto update',
icon: (
<EuiSwitch
checked={state.autoUpdate}
onChange={toggleAutoUpdate}
label={undefined}
/>
),
},
],
},
];
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

const button = (
<EuiButtonIcon
aria-label="settings"
iconType="gear"
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
color="primary"
display="base"
size="m"
/>
);

const { view, itemId: selectedItemId } = config;
const { status } = state;

const isPoppedOut = !!window.opener;

return (
<EuiProvider colorMode="light">
<EuiProvider
colorMode={colourMode}
modify={{
colors: {
LIGHT: {
primary: '#61c3d9',
accent: '#006D67',
success: '#bdd000',
warning: '#ffb910',
danger: '#c70000',
},
},
}}
>
<EuiPageTemplate
onKeyUp={(e) => {
if (view == 'item') {
Expand All @@ -60,44 +123,67 @@ export function App() {
max-height: 100vh;
`}
>
{!isPoppedOut && (
{!isPoppedOut ? (
<EuiHeader position="fixed">
<EuiHeaderSection>
<EuiHeaderSectionItem>
<EuiTitle
size={'s'}
css={css`
padding-bottom: 3px;
padding-right: 10px;
`}
>
<h1>Newswires</h1>
</EuiTitle>
</EuiHeaderSectionItem>
<EuiHeaderSectionItem>
<SideNav />
<SideNav dockedByDefault={true} />
</EuiHeaderSectionItem>
</EuiHeaderSection>
<EuiHeaderSectionItem>
{
<EuiButton
iconType={'popout'}
onClick={() =>
window.open(
configToUrl({
...config,
view: 'feed',
itemId: undefined,
}),
'_blank',
'popout=true,width=400,height=800,top=200,location=no,menubar=no,toolbar=no',
)
}
>
New ticker
</EuiButton>
}
</EuiHeaderSectionItem>
<EuiHeaderLinks>
<EuiButtonIcon
iconType={'popout'}
onClick={() =>
window.open(
configToUrl({
...config,
view: 'feed',
itemId: undefined,
}),
'_blank',
'popout=true,width=400,height=800,top=200,location=no,menubar=no,toolbar=no',
)
}
color="primary"
display="base"
size="m"
aria-label="popout search in new ticker window"
>
New ticker
</EuiButtonIcon>
<EuiPopover
id={contextMenuPopoverId}
button={button}
isOpen={isPopoverOpen}
closePopover={() => setIsPopoverOpen(false)}
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenu initialPanelId={0} panels={panels} />
</EuiPopover>
</EuiHeaderLinks>
</EuiHeader>
) : (
<div
css={css`
position: fixed;
top: 10px;
left: 10px;
`}
>
<SideNav dockedByDefault={false} />
</div>
)}
{status !== 'error' && (
<>
Expand All @@ -113,6 +199,7 @@ export function App() {
minSize="25%"
initialSize={100}
className="eui-yScroll"
paddingSize="xs"
>
<Feed />
</EuiResizablePanel>
Expand All @@ -121,6 +208,7 @@ export function App() {
minSize="30%"
initialSize={100}
className="eui-yScroll"
paddingSize="s"
>
<Item id={selectedItemId} />
</EuiResizablePanel>
Expand Down
2 changes: 1 addition & 1 deletion newswires/client/src/Feed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const Feed = () => {
const { status, queryData } = state;

return (
<EuiPageTemplate.Section>
<EuiPageTemplate.Section paddingSize="none">
{status == 'loading' && (
<EuiEmptyPrompt
icon={<EuiLoadingLogo logo="clock" size="l" />}
Expand Down
39 changes: 19 additions & 20 deletions newswires/client/src/SideNav.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {
EuiBadge,
EuiBadgeGroup,
EuiButtonIcon,
EuiCollapsibleNav,
EuiCollapsibleNavGroup,
EuiHeaderSectionItemButton,
EuiIcon,
EuiListGroup,
EuiListGroupItem,
EuiSwitch,
EuiText,
useEuiTheme,
useIsWithinMinBreakpoint,
Expand Down Expand Up @@ -39,12 +37,12 @@
return buckets.find((bucket) => bucket.id === bucketId)?.name;
}

export const SideNav = () => {
export const SideNav = ({ dockedByDefault }: { dockedByDefault: boolean }) => {
const [navIsOpen, setNavIsOpen] = useState<boolean>(false);
const theme = useEuiTheme();
const isOnLargerScreen = useIsWithinMinBreakpoint('m');

const { state, config, handleEnterQuery, toggleAutoUpdate } = useSearch();

Check warning on line 45 in newswires/client/src/SideNav.tsx

View workflow job for this annotation

GitHub Actions / Build and upload to riffraff

'toggleAutoUpdate' is assigned a value but never used. Allowed unused vars must match /^_/u

const searchHistory = state.successfulQueryHistory;
const activeSuppliers = useMemo(
Expand Down Expand Up @@ -96,7 +94,7 @@
activeSuppliers.length === 0 ||
activeSuppliers.length === recognisedSuppliers.length,
onClick: () => handleEnterQuery({ ...config.query, supplier: [] }),
colour: 'black',
colour: theme.colorMode === 'LIGHT' ? 'black' : 'white',
},
...recognisedSuppliers.map((supplier) => ({
label: supplier,
Expand All @@ -106,7 +104,13 @@
onClick: () => toggleSupplier(supplier),
})),
],
[activeSuppliers, config.query, handleEnterQuery, toggleSupplier],
[
activeSuppliers,
config.query,
handleEnterQuery,
theme.colorMode,
toggleSupplier,
],
);

const bucketItems = useMemo(() => {
Expand All @@ -128,19 +132,21 @@
<>
<EuiCollapsibleNav
isOpen={navIsOpen}
isDocked={isOnLargerScreen}
isDocked={dockedByDefault && isOnLargerScreen}
size={300}
button={
<EuiHeaderSectionItemButton
<EuiButtonIcon
aria-label="Toggle main navigation"
onClick={() => setNavIsOpen((isOpen) => !isOpen)}
>
<EuiIcon type={'menu'} size="m" aria-hidden="true" />
</EuiHeaderSectionItemButton>
color={'primary'}
display="base"
iconType={'menu'}
/>
}
closeButtonProps={{ color: 'warning' }}
onClose={() => setNavIsOpen(false)}
>
<div style={{ height: '90%', overflowY: 'auto' }}>
<div className="eui-yScroll">
<SearchBox />
<EuiCollapsibleNavGroup title="Buckets">
<EuiListGroup
Expand Down Expand Up @@ -195,6 +201,7 @@
background-color: ${isActive
? colour
: 'transparent'};
opacity: 0.7;
`}
/>
}
Expand Down Expand Up @@ -230,14 +237,6 @@
)}
</EuiCollapsibleNavGroup>
</div>

<div style={{ padding: '20px 10px' }}>
<EuiSwitch
label="Auto-update"
checked={state.autoUpdate}
onChange={toggleAutoUpdate}
/>
</div>
</EuiCollapsibleNav>
</>
);
Expand Down
Loading