-
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Pals screen and related components
- Loading branch information
1 parent
bf3e88b
commit 302e3a3
Showing
73 changed files
with
3,182 additions
and
236 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {makeAutoObservable} from 'mobx'; | ||
import {v4 as uuidv4} from 'uuid'; | ||
import { | ||
AssistantFormData, | ||
RoleplayFormData, | ||
} from '../../src/components/PalsSheets/types'; | ||
import {Pal} from '../../src/store/PalStore'; | ||
|
||
class MockPalStore { | ||
pals: Pal[] = []; | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
} | ||
|
||
addPal = jest.fn((data: AssistantFormData | RoleplayFormData) => { | ||
const newPal = { | ||
id: uuidv4(), | ||
...data, | ||
} as Pal; | ||
this.pals.push(newPal); | ||
}); | ||
|
||
updatePal = jest.fn( | ||
(id: string, data: Partial<AssistantFormData | RoleplayFormData>) => { | ||
const palIndex = this.pals.findIndex(p => p.id === id); | ||
if (palIndex !== -1) { | ||
const currentPal = this.pals[palIndex]; | ||
this.pals[palIndex] = { | ||
...currentPal, | ||
...data, | ||
palType: currentPal.palType, | ||
} as Pal; | ||
} | ||
}, | ||
); | ||
|
||
deletePal = jest.fn((id: string) => { | ||
const palIndex = this.pals.findIndex(p => p.id === id); | ||
if (palIndex !== -1) { | ||
this.pals.splice(palIndex, 1); | ||
} | ||
}); | ||
|
||
getPals = jest.fn(() => { | ||
return this.pals; | ||
}); | ||
} | ||
|
||
export const mockPalStore = new MockPalStore(); |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions
68
src/components/ChatEmptyPlaceholder/ChatEmptyPlaceholder.tsx
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,68 @@ | ||
import React from 'react'; | ||
import {Image, View} from 'react-native'; | ||
import {Button, Text} from 'react-native-paper'; | ||
import {observer} from 'mobx-react'; | ||
|
||
import {useTheme} from '../../hooks'; | ||
import {createStyles} from './styles'; | ||
import {modelStore} from '../../store'; | ||
|
||
interface ChatEmptyPlaceholderProps { | ||
onSelectModel: () => void; | ||
bottomComponentHeight: number; | ||
} | ||
|
||
export const ChatEmptyPlaceholder = observer( | ||
({onSelectModel, bottomComponentHeight}: ChatEmptyPlaceholderProps) => { | ||
const theme = useTheme(); | ||
const styles = createStyles({theme}); | ||
|
||
const hasAvailableModels = modelStore.availableModels.length > 0; | ||
const hasActiveModel = modelStore.activeModelId !== undefined; | ||
|
||
const getContent = () => { | ||
if (!hasAvailableModels) { | ||
return { | ||
title: 'No Models Available', | ||
description: 'Download a model to start chatting with PocketPal', | ||
buttonText: 'Download Model', | ||
}; | ||
} | ||
|
||
return { | ||
title: 'Activate Model To Get Started', | ||
description: | ||
'Select the model and download it. After downloading, tap Load next to the model and start chatting.', | ||
buttonText: 'Select Model', | ||
}; | ||
}; | ||
|
||
const {title, description, buttonText} = getContent(); | ||
|
||
if (hasActiveModel) { | ||
return null; | ||
} | ||
return ( | ||
<View | ||
style={[styles.container, {marginBottom: bottomComponentHeight + 100}]}> | ||
<Image | ||
source={require('../../assets/pocketpal-dark-v2.png')} | ||
style={styles.logo} | ||
resizeMode="contain" | ||
/> | ||
<View> | ||
<Text style={styles.title}>{title}</Text> | ||
<Text style={styles.description}>{description}</Text> | ||
</View> | ||
<Button | ||
mode="contained" | ||
onPress={onSelectModel} | ||
style={styles.button} | ||
loading={modelStore.isContextLoading} | ||
disabled={hasActiveModel}> | ||
{modelStore.isContextLoading ? 'Loading...' : buttonText} | ||
</Button> | ||
</View> | ||
); | ||
}, | ||
); |
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 @@ | ||
export {ChatEmptyPlaceholder} from './ChatEmptyPlaceholder'; |
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,32 @@ | ||
import {StyleSheet} from 'react-native'; | ||
import {Theme} from '../../utils/types'; | ||
|
||
export const createStyles = ({theme}: {theme: Theme}) => | ||
StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
paddingHorizontal: 32, | ||
gap: theme.spacing.default, | ||
}, | ||
title: { | ||
color: theme.colors.onSurface, | ||
textAlign: 'center', | ||
marginBottom: 8, | ||
...theme.fonts.titleMedium, | ||
}, | ||
description: { | ||
color: theme.colors.onSurfaceVariant, | ||
textAlign: 'center', | ||
...theme.fonts.bodyMedium, | ||
}, | ||
button: { | ||
minWidth: 200, | ||
}, | ||
logo: { | ||
width: 112, | ||
height: 112, | ||
borderRadius: 30, | ||
}, | ||
}); |
Oops, something went wrong.