This repository has been archived by the owner on Jun 15, 2022. It is now read-only.
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
14 changed files
with
498 additions
and
3 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
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 styled from 'styled-components/native'; | ||
|
||
export const Container = styled.View``; | ||
|
||
export const DateText = styled.Text` | ||
font-size: 15px; | ||
margin-top: 4px; | ||
opacity: 0.8; | ||
line-height: 21px; | ||
`; | ||
|
||
export const IosTabBarContainer = styled.View` | ||
padding-top: 10px; | ||
padding-bottom: 5px; | ||
padding-left: 12px; | ||
padding-right: 12px; | ||
`; |
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,145 @@ | ||
import SegmentedControl from '@react-native-community/segmented-control'; | ||
import { AppStackNavigationProp } from '@Root/App'; | ||
import { ApplicationContext } from '@Root/ApplicationContext'; | ||
import { SCREEN_NOTE_HISTORY } from '@Screens/screens'; | ||
import { StyleKitContext } from '@Style/StyleKit'; | ||
import React, { useCallback, useContext, useState } from 'react'; | ||
import { Dimensions, Platform } from 'react-native'; | ||
import { | ||
NavigationState, | ||
Route, | ||
SceneRendererProps, | ||
TabBar, | ||
TabView, | ||
} from 'react-native-tab-view'; | ||
import { ButtonType, ContentType, PayloadSource, SNNote } from 'snjs'; | ||
import { PayloadContent } from 'snjs/dist/@types/protocol/payloads/generator'; | ||
import { ThemeContext } from 'styled-components/native'; | ||
import { IosTabBarContainer } from './NoteHistory.styled'; | ||
import { RemoteHistory } from './RemoteHistory'; | ||
import { SessionHistory } from './SessionHistory'; | ||
|
||
const initialLayout = { width: Dimensions.get('window').width }; | ||
|
||
type Props = AppStackNavigationProp<typeof SCREEN_NOTE_HISTORY>; | ||
export const NoteHistory = (props: Props) => { | ||
// Context | ||
const application = useContext(ApplicationContext); | ||
const theme = useContext(ThemeContext); | ||
const styleKit = useContext(StyleKitContext); | ||
|
||
// State | ||
const [note] = useState<SNNote>( | ||
() => application?.findItem(props.route.params.noteUuid) as SNNote | ||
); | ||
const [routes] = React.useState([ | ||
{ key: 'session', title: 'Session' }, | ||
{ key: 'remote', title: 'Remote' }, | ||
]); | ||
const [index, setIndex] = useState(0); | ||
|
||
const restore = useCallback( | ||
async (asCopy: boolean, revisionUuid: string, content: PayloadContent) => { | ||
const run = async () => { | ||
if (asCopy) { | ||
const contentCopy = Object.assign({}, content); | ||
if (contentCopy.title) { | ||
contentCopy.title += ' (copy)'; | ||
} | ||
await application?.createManagedItem( | ||
ContentType.Note, | ||
contentCopy, | ||
true | ||
); | ||
props.navigation.popToTop(); | ||
} else { | ||
await application?.changeAndSaveItem( | ||
revisionUuid, | ||
mutator => { | ||
mutator.setContent(content); | ||
}, | ||
true, | ||
PayloadSource.RemoteActionRetrieved | ||
); | ||
props.navigation.goBack(); | ||
} | ||
}; | ||
|
||
if (!asCopy) { | ||
const confirmed = await application?.alertService?.confirm( | ||
"Are you sure you want to replace the current note's contents with what you see in this preview?", | ||
'Restore note', | ||
'Restore', | ||
ButtonType.Info | ||
); | ||
if (confirmed) { | ||
run(); | ||
} | ||
} else { | ||
run(); | ||
} | ||
}, | ||
[application, props.navigation] | ||
); | ||
|
||
const renderScene = ({ | ||
route, | ||
}: { | ||
route: { key: string; title: string }; | ||
}) => { | ||
switch (route.key) { | ||
case 'session': | ||
return <SessionHistory restoreNote={restore} note={note} />; | ||
case 'remote': | ||
return <RemoteHistory restoreNote={restore} note={note} />; | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
const renderTabBar = ( | ||
tabBarProps: SceneRendererProps & { | ||
navigationState: NavigationState<Route>; | ||
} | ||
) => { | ||
return Platform.OS === 'ios' && | ||
parseInt(Platform.Version as string, 10) >= 13 ? ( | ||
<IosTabBarContainer> | ||
<SegmentedControl | ||
backgroundColor={theme.stylekitContrastBackgroundColor} | ||
appearance={styleKit?.keyboardColorForActiveTheme()} | ||
fontStyle={{ | ||
color: theme.stylekitForegroundColor, | ||
}} | ||
values={routes.map(route => route.title)} | ||
selectedIndex={tabBarProps.navigationState.index} | ||
onChange={event => { | ||
setIndex(event.nativeEvent.selectedSegmentIndex); | ||
}} | ||
/> | ||
</IosTabBarContainer> | ||
) : ( | ||
<TabBar | ||
{...tabBarProps} | ||
indicatorStyle={{ backgroundColor: theme.stylekitInfoColor }} | ||
inactiveColor={theme.stylekitBorderColor} | ||
activeColor={theme.stylekitInfoColor} | ||
style={{ | ||
backgroundColor: theme.stylekitBackgroundColor, | ||
shadowColor: theme.stylekitShadowColor, | ||
}} | ||
labelStyle={{ color: theme.stylekitInfoColor }} | ||
/> | ||
); | ||
}; | ||
|
||
return ( | ||
<TabView | ||
renderTabBar={renderTabBar} | ||
navigationState={{ index, routes }} | ||
renderScene={renderScene} | ||
onIndexChange={setIndex} | ||
initialLayout={initialLayout} | ||
/> | ||
); | ||
}; |
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,64 @@ | ||
import { | ||
Props as TableCellProps, | ||
SectionedTableCellTouchableHighlight, | ||
} from '@Components/SectionedTableCell'; | ||
import React from 'react'; | ||
import styled, { css } from 'styled-components/native'; | ||
|
||
type Props = { | ||
testID?: string; | ||
disabled?: boolean; | ||
onPress: () => void; | ||
first?: boolean; | ||
last?: boolean; | ||
title: string; | ||
subTitle?: string; | ||
}; | ||
|
||
const Container = styled(SectionedTableCellTouchableHighlight).attrs(props => ({ | ||
underlayColor: props.theme.stylekitBorderColor, | ||
}))<TableCellProps>` | ||
padding-top: ${12}px; | ||
justify-content: center; | ||
`; | ||
const ButtonContainer = styled.View``; | ||
|
||
type ButtonLabelProps = Pick<Props, 'disabled'>; | ||
const ButtonLabel = styled.Text<ButtonLabelProps>` | ||
color: ${props => { | ||
let color = props.theme.stylekitForegroundColor; | ||
if (props.disabled) { | ||
color = 'gray'; | ||
} | ||
return color; | ||
}}; | ||
font-weight: bold; | ||
font-size: ${props => props.theme.mainTextFontSize}px; | ||
${({ disabled }) => | ||
disabled && | ||
css` | ||
opacity: 0.6; | ||
`} | ||
`; | ||
export const SubTitleText = styled.Text` | ||
font-size: 14px; | ||
margin-top: 4px; | ||
color: ${({ theme }) => theme.stylekitForegroundColor}; | ||
opacity: 0.8; | ||
line-height: 21px; | ||
`; | ||
|
||
export const NoteHistoryCell: React.FC<Props> = props => ( | ||
<Container | ||
first={props.first} | ||
last={props.last} | ||
testID={props.testID} | ||
disabled={props.disabled} | ||
onPress={props.onPress} | ||
> | ||
<ButtonContainer> | ||
<ButtonLabel disabled={props.disabled}>{props.title}</ButtonLabel> | ||
{props.subTitle && <SubTitleText>{props.subTitle}</SubTitleText>} | ||
</ButtonContainer> | ||
</Container> | ||
); |
Oops, something went wrong.