Skip to content

Commit

Permalink
Merge pull request #121 from tooot-app/main
Browse files Browse the repository at this point in the history
Candidate release v1.1
  • Loading branch information
xmflsct committed May 9, 2021
2 parents 77ab184 + 7fb7c76 commit 11b84eb
Show file tree
Hide file tree
Showing 73 changed files with 2,609 additions and 871 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: macos-latest
runs-on: macos-10.15
steps:
- name: -- Step 0 -- Extract branch name
shell: bash
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"versions": {
"native": "210317",
"major": 1,
"minor": 0,
"minor": 1,
"patch": 0,
"expo": "40.0.0"
},
Expand All @@ -20,7 +20,8 @@
"ios": "react-native run-ios",
"app:build": "bundle exec fastlane build",
"test": "jest --watchAll",
"release": "scripts/release.sh"
"release": "scripts/release.sh",
"clean": "react-native-clean-project"
},
"dependencies": {
"@expo/react-native-action-sheet": "^3.9.0",
Expand Down Expand Up @@ -114,6 +115,7 @@
"jest": "^26.6.3",
"jest-expo": "^40.0.2",
"nock": "^13.0.11",
"react-native-clean-project": "^3.6.3",
"react-navigation": "^4.4.4",
"react-navigation-stack": "^2.10.4",
"react-test-renderer": "^17.0.1",
Expand Down
4 changes: 2 additions & 2 deletions src/@types/mastodon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ declare namespace Mastodon {
moved?: Account
fields: Field[]
bot: boolean
source: Source
source?: Source
}

type Announcement = {
Expand Down Expand Up @@ -258,7 +258,7 @@ declare namespace Mastodon {
type Field = {
name: string
value: string
verified_at?: string
verified_at: string | null
}

type List = {
Expand Down
16 changes: 15 additions & 1 deletion src/@types/react-navigation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,23 @@ declare namespace Nav {
list: Mastodon.List['id']
title: Mastodon.List['title']
}
'Tab-Me-Profile': undefined
'Tab-Me-Push': undefined
'Tab-Me-Settings': undefined
'Tab-Me-Settings-Fontsize': undefined
'Tab-Me-Settings-Push': undefined
'Tab-Me-Switch': undefined
} & TabSharedStackParamList

type TabMeProfileStackParamList = {
'Tab-Me-Profile-Root': undefined
'Tab-Me-Profile-Name': {
display_name: Mastodon.Account['display_name']
}
'Tab-Me-Profile-Note': {
note: Mastodon.Source['note']
}
'Tab-Me-Profile-Fields': {
fields?: Mastodon.Source['fields']
}
}
}
11 changes: 4 additions & 7 deletions src/Screens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
options={{
stackPresentation: 'transparentModal',
stackAnimation: 'fade',
headerShown: false // Android
headerShown: false
}}
/>
<Stack.Screen
Expand All @@ -177,15 +177,15 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
options={{
stackPresentation: 'transparentModal',
stackAnimation: 'fade',
headerShown: false // Android
headerShown: false
}}
/>
<Stack.Screen
name='Screen-Compose'
component={ScreenCompose}
options={{
stackPresentation: 'fullScreenModal',
headerShown: false // Android
headerShown: false
}}
/>
<Stack.Screen
Expand All @@ -194,7 +194,7 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
options={{
stackPresentation: 'fullScreenModal',
stackAnimation: 'fade',
headerShown: false // Android
headerShown: false
}}
/>
</Stack.Navigator>
Expand All @@ -206,6 +206,3 @@ const Screens: React.FC<Props> = ({ localCorrupt }) => {
}

export default React.memo(Screens, () => true)
function toast (arg0: { type: string; content: string; autoHide: boolean }) {
throw new Error('Function not implemented.')
}
6 changes: 1 addition & 5 deletions src/api/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ctx = new chalk.Instance({ level: 3 })

export type Params = {
method: 'get' | 'post' | 'put' | 'delete'
domain?: string
domain: string
url: string
params?: {
[key: string]: string | number | boolean | string[] | number[] | boolean[]
Expand All @@ -25,10 +25,6 @@ const apiGeneral = async <T = unknown>({
body,
sentry = false
}: Params): Promise<{ body: T }> => {
if (!domain) {
return Promise.reject()
}

console.log(
ctx.bgGreen.bold(' API general ') +
' ' +
Expand Down
2 changes: 1 addition & 1 deletion src/api/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import li from 'li'
const ctx = new chalk.Instance({ level: 3 })

export type Params = {
method: 'get' | 'post' | 'put' | 'delete'
method: 'get' | 'post' | 'put' | 'delete' | 'patch'
version?: 'v1' | 'v2'
url: string
params?: {
Expand Down
20 changes: 8 additions & 12 deletions src/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Icon from '@components/Icon'
import { StyleConstants } from '@utils/styles/constants'
import layoutAnimation from '@utils/styles/layoutAnimation'
import { useTheme } from '@utils/styles/ThemeManager'
import React, { useEffect, useMemo, useRef } from 'react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
import {
AccessibilityProps,
Pressable,
Expand Down Expand Up @@ -121,9 +121,6 @@ const Button: React.FC<Props> = ({
color: mainColor,
fontSize:
StyleConstants.Font.Size[size] * (size === 'L' ? 1.25 : 1),
fontWeight: destructive
? StyleConstants.Font.Weight.Bold
: undefined,
opacity: loading ? 0 : 1
}}
children={content}
Expand All @@ -135,12 +132,7 @@ const Button: React.FC<Props> = ({
}
}, [mode, content, loading, disabled])

enum spacingMapping {
XS = 'S',
S = 'M',
M = 'L',
L = 'XL'
}
const [layoutHeight, setLayoutHeight] = useState<number | undefined>()

return (
<Pressable
Expand All @@ -161,10 +153,15 @@ const Button: React.FC<Props> = ({
backgroundColor: colorBackground,
paddingVertical: StyleConstants.Spacing[spacing],
paddingHorizontal:
StyleConstants.Spacing[round ? spacing : spacingMapping[spacing]]
StyleConstants.Spacing[spacing] + StyleConstants.Spacing.XS,
width: round && layoutHeight ? layoutHeight : undefined
},
customStyle
]}
{...(round && {
onLayout: ({ nativeEvent }) =>
setLayoutHeight(nativeEvent.layout.height)
})}
testID='base'
onPress={onPress}
children={children}
Expand All @@ -176,7 +173,6 @@ const Button: React.FC<Props> = ({
const styles = StyleSheet.create({
button: {
borderRadius: 100,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
}
Expand Down
160 changes: 160 additions & 0 deletions src/components/Emojis.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import EmojisButton from '@components/Emojis/Button'
import EmojisList from '@components/Emojis/List'
import { useAccessibility } from '@utils/accessibility/AccessibilityManager'
import { useEmojisQuery } from '@utils/queryHooks/emojis'
import { chunk, forEach, groupBy, sortBy } from 'lodash'
import React, {
createContext,
Dispatch,
MutableRefObject,
SetStateAction,
useCallback,
useEffect,
useReducer
} from 'react'
import FastImage from 'react-native-fast-image'

type EmojisState = {
enabled: boolean
active: boolean
emojis: { title: string; data: Mastodon.Emoji[][] }[]
shortcode: Mastodon.Emoji['shortcode'] | null
}

type EmojisAction =
| {
type: 'load'
payload: NonNullable<EmojisState['emojis']>
}
| {
type: 'activate'
payload: EmojisState['active']
}
| {
type: 'shortcode'
payload: EmojisState['shortcode']
}

const emojisReducer = (state: EmojisState, action: EmojisAction) => {
switch (action.type) {
case 'activate':
return { ...state, active: action.payload }
case 'load':
return { ...state, emojis: action.payload }
case 'shortcode':
return { ...state, shortcode: action.payload }
}
}

type ContextType = {
emojisState: EmojisState
emojisDispatch: Dispatch<EmojisAction>
}
const EmojisContext = createContext<ContextType>({} as ContextType)

const prefetchEmojis = (
sortedEmojis: { title: string; data: Mastodon.Emoji[][] }[],
reduceMotionEnabled: boolean
) => {
const prefetches: { uri: string }[] = []
let requestedIndex = 0
sortedEmojis.forEach(sorted => {
sorted.data.forEach(emojis =>
emojis.forEach(emoji => {
if (requestedIndex > 40) {
return
}
prefetches.push({
uri: reduceMotionEnabled ? emoji.static_url : emoji.url
})
requestedIndex++
})
)
})
try {
FastImage.preload(prefetches)
} catch {}
}

export interface Props {
enabled?: boolean
value?: string
setValue:
| Dispatch<SetStateAction<string | undefined>>
| Dispatch<SetStateAction<string>>
selectionRange: MutableRefObject<{
start: number
end: number
}>
}

const ComponentEmojis: React.FC<Props> = ({
enabled = false,
value,
setValue,
selectionRange,
children
}) => {
const { reduceMotionEnabled } = useAccessibility()

const [emojisState, emojisDispatch] = useReducer(emojisReducer, {
enabled,
active: false,
emojis: [],
shortcode: null
})

useEffect(() => {
if (emojisState.shortcode) {
addEmoji(emojisState.shortcode)
emojisDispatch({
type: 'shortcode',
payload: null
})
}
}, [emojisState.shortcode])

const addEmoji = useCallback(
(emojiShortcode: string) => {
if (value?.length) {
const contentFront = value.slice(0, selectionRange.current?.start)
const contentRear = value.slice(selectionRange.current?.end)

const whiteSpaceRear = /\s/g.test(contentRear.slice(-1))

const newTextWithSpace = ` ${emojiShortcode}${
whiteSpaceRear ? '' : ' '
}`
setValue([contentFront, newTextWithSpace, contentRear].join(''))
} else {
setValue(`${emojiShortcode} `)
}
},
[value, selectionRange.current?.start, selectionRange.current?.end]
)

const { data } = useEmojisQuery({ options: { enabled } })
useEffect(() => {
if (data && data.length) {
let sortedEmojis: { title: string; data: Mastodon.Emoji[][] }[] = []
forEach(
groupBy(sortBy(data, ['category', 'shortcode']), 'category'),
(value, key) => sortedEmojis.push({ title: key, data: chunk(value, 5) })
)
emojisDispatch({
type: 'load',
payload: sortedEmojis
})
prefetchEmojis(sortedEmojis, reduceMotionEnabled)
}
}, [data, reduceMotionEnabled])

return (
<EmojisContext.Provider
value={{ emojisState, emojisDispatch }}
children={children}
/>
)
}

export { ComponentEmojis, EmojisContext, EmojisButton, EmojisList }

0 comments on commit 11b84eb

Please sign in to comment.