Skip to content

Commit

Permalink
feat(updater): add markdown display (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangvu12 authored Nov 29, 2023
1 parent f973289 commit 15ab722
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 20 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@bacons/link-assets": "^1.1.0",
"@gorhom/bottom-sheet": "^4.4.5",
"@graphql-typed-document-node/core": "^3.2.0",
"@jonasmerlin/react-native-markdown-display": "github:jonasmerlin/react-native-markdown-display",
"@plussub/srt-vtt-parser": "^1.1.0",
"@react-native-community/viewpager": "^5.0.11",
"@react-native-picker/picker": "2.4.10",
Expand Down Expand Up @@ -144,4 +145,4 @@
"osMetadata": {
"initVersion": "4.2.2"
}
}
}
56 changes: 56 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/ui/core/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const Button = ({
buttonVariants[variant].indicator,
indicatorClassName
)}
color="white"
{...loadingProps}
/>
) : (
Expand Down
236 changes: 217 additions & 19 deletions src/ui/updater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import type { BottomSheetModal } from '@gorhom/bottom-sheet';
import axios from 'axios';
import * as FileSystem from 'expo-file-system';
import * as IntentLauncher from 'expo-intent-launcher';
import { useCallback, useEffect, useRef, useState } from 'react';
import React from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Platform } from 'react-native';
import Markdown from 'react-native-markdown-display';

Check failure on line 7 in src/ui/updater.tsx

View workflow job for this annotation

GitHub Actions / Type Check (tsc)

Cannot find module 'react-native-markdown-display' or its corresponding type declarations.

import { Env } from '@/core/env';

import { Button, Text } from './core';
import { Button, Text, View } from './core';
import BottomSheet from './core/bottom-sheet';

export interface Release {
Expand Down Expand Up @@ -170,28 +171,225 @@ const Updater = () => {

return (
<BottomSheet ref={bottomSheetRef} snapPoints={['80%']}>
<Text className="mb-2 text-xl" weight="bold">
New update available:{' '}
<Text className="text-xl text-primary-300" weight="bold">
{release.name}
<View className="pb-12">
<Text className="mb-4 text-xl" weight="bold">
New update available:{' '}
<Text className="text-xl text-primary-300" weight="bold">
{release.name}
</Text>
</Text>
</Text>

<Text className="mb-4 text-lg">Changelog:</Text>
{/* @ts-expect-error */}

Check failure on line 182 in src/ui/updater.tsx

View workflow job for this annotation

GitHub Actions / Type Check (tsc)

Unused '@ts-expect-error' directive.
<Markdown style={markdownStyles}>{release.body}</Markdown>

<Text className="mb-8 bg-thunder-800 p-4">{release.body}</Text>
<Button loading={isLoading} onPress={handleUpdate}>
<Text>Update now</Text>
</Button>

<Button loading={isLoading} onPress={handleUpdate}>
<Text>Update now</Text>
</Button>

{errorMessage ? (
<Text className="mt-4 text-red-300" weight="semibold">
Error: {errorMessage}
</Text>
) : null}
{errorMessage ? (
<Text className="mt-4 text-red-300" weight="semibold">
Error: {errorMessage}
</Text>
) : null}
</View>
</BottomSheet>
);
};

const markdownStyles = {
// The main container
body: {},

// Headings
heading1: {
flexDirection: 'row',
fontSize: 32,
fontFamily: 'Outfit-Bold',
},
heading2: {
flexDirection: 'row',
fontSize: 24,
},
heading3: {
flexDirection: 'row',
fontSize: 18,
},
heading4: {
flexDirection: 'row',
fontSize: 16,
},
heading5: {
flexDirection: 'row',
fontSize: 13,
},
heading6: {
flexDirection: 'row',
fontSize: 11,
},

// Horizontal Rule
hr: {
backgroundColor: '#000000',
height: 1,
},

// Emphasis
strong: {
fontWeight: 'bold',
},
em: {
fontStyle: 'italic',
},
s: {
textDecorationLine: 'line-through',
},

// Blockquotes
blockquote: {
backgroundColor: '#F5F5F5',
borderColor: '#CCC',
borderLeftWidth: 4,
marginLeft: 5,
paddingHorizontal: 5,
},

// Lists
bullet_list: {},
ordered_list: {},
list_item: {
marginTop: 8,
flexDirection: 'row',
justifyContent: 'flex-start',
},
// @pseudo class, does not have a unique render rule
bullet_list_icon: {
marginLeft: 10,
marginRight: 10,
color: 'white',
},
// @pseudo class, does not have a unique render rule
bullet_list_content: {
flex: 1,
},
// @pseudo class, does not have a unique render rule
ordered_list_icon: {
marginLeft: 10,
marginRight: 10,
},
// @pseudo class, does not have a unique render rule
ordered_list_content: {
flex: 1,
},

// Code
code_inline: {
borderWidth: 1,
borderColor: '#CCCCCC',
backgroundColor: '#f5f5f5',
padding: 10,
borderRadius: 4,
...Platform.select({
['ios']: {
fontFamily: 'Courier',
},
['android']: {
fontFamily: 'monospace',
},
}),
},
code_block: {
borderWidth: 1,
borderColor: '#CCCCCC',
backgroundColor: '#f5f5f5',
padding: 10,
borderRadius: 4,
...Platform.select({
['ios']: {
fontFamily: 'Courier',
},
['android']: {
fontFamily: 'monospace',
},
}),
},
fence: {
borderWidth: 1,
borderColor: '#CCCCCC',
backgroundColor: '#f5f5f5',
padding: 10,
borderRadius: 4,
...Platform.select({
['ios']: {
fontFamily: 'Courier',
},
['android']: {
fontFamily: 'monospace',
},
}),
},

// Tables
table: {
borderWidth: 1,
borderColor: '#000000',
borderRadius: 3,
},
thead: {},
tbody: {},
th: {
flex: 1,
padding: 5,
},
tr: {
borderBottomWidth: 1,
borderColor: '#000000',
flexDirection: 'row',
},
td: {
flex: 1,
padding: 5,
},

// Links
link: {
textDecorationLine: 'underline',
},
blocklink: {
flex: 1,
borderColor: '#000000',
borderBottomWidth: 1,
},

// Images
image: {
flex: 1,
},

// Text Output
text: {
color: 'white',
fontFamily: 'Outfit-Medium',
},
textgroup: {},
paragraph: {
marginTop: 24,
marginBottom: 24,
flexWrap: 'wrap',
flexDirection: 'row',
alignItems: 'flex-start',
justifyContent: 'flex-start',
width: '100%',
},
hardbreak: {
width: '100%',
height: 1,
},
softbreak: {},

// Believe these are never used but retained for completeness
pre: {},
inline: {},
span: {},
};

export default Updater;

0 comments on commit 15ab722

Please sign in to comment.