-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(das-dui-tool): Add chat file preview support and small refactor (#…
…34)
- Loading branch information
1 parent
a4377e8
commit 3fd6e72
Showing
5 changed files
with
275 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { FC, PropsWithChildren } from "react" | ||
|
||
import { Link } from "expo-router" | ||
|
||
import { CloudResponse } from "@das-dui/api-client" | ||
|
||
type FileLinkProps = Pick< | ||
CloudResponse.CloudFile, | ||
"uuid" | "cloud_id" | "path" | "name" | "file_type" | ||
> | ||
|
||
const FileLink: FC<PropsWithChildren<FileLinkProps>> = ({ | ||
children, | ||
cloud_id, | ||
file_type, | ||
name, | ||
path, | ||
uuid, | ||
}) => { | ||
const params = new URLSearchParams({ | ||
name: name, | ||
}) | ||
const nameParam = params | ||
.toString() | ||
.split("&")[0] | ||
.split("=")[1] | ||
.replaceAll("+", " ") | ||
|
||
return ( | ||
<Link | ||
push | ||
href={ | ||
file_type === "DIR" | ||
? { | ||
pathname: "/(auth)/(app)/chats/cloud/file/[fileId]", | ||
params: { | ||
fileId: uuid, | ||
cloudId: cloud_id, | ||
path: path, | ||
}, | ||
} | ||
: { | ||
pathname: | ||
"/(auth)/(app)/chats/cloud/open_file/[fileId]", | ||
params: { | ||
fileId: uuid, | ||
cloudId: cloud_id, | ||
name: nameParam, | ||
}, | ||
} | ||
} | ||
asChild | ||
> | ||
{children} | ||
</Link> | ||
) | ||
} | ||
|
||
FileLink.displayName = "FileLink" | ||
|
||
export default FileLink |
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,63 @@ | ||
import { FC } from "react" | ||
import { TouchableOpacity } from "react-native" | ||
|
||
import * as WebBrowser from "expo-web-browser" | ||
|
||
import { ListItem, useTheme } from "tamagui" | ||
|
||
import { ChatMessagesResponse, CloudResponse } from "@das-dui/api-client" | ||
|
||
import GenericIcon from "@/components/ui/GenericIcon" | ||
import { iconNameBasedOnFileExtension } from "@/utils/iconNameBasedOnFileExtension" | ||
|
||
type FileListItemProps = Pick< | ||
CloudResponse.CloudFile | ChatMessagesResponse.File, | ||
"name" | "meta" | "file_type" | "extension" | ||
> | ||
|
||
const FileListItem: FC<FileListItemProps> = ({ | ||
name, | ||
meta, | ||
extension, | ||
file_type, | ||
}) => { | ||
const theme = useTheme() | ||
|
||
return ( | ||
<ListItem | ||
title={name} | ||
subTitle={meta.subtitle} | ||
icon={ | ||
<GenericIcon | ||
name={ | ||
file_type === "DIR" | ||
? meta.files_count > 0 | ||
? "folder" | ||
: "folder-open" | ||
: iconNameBasedOnFileExtension(extension) | ||
} | ||
size={30} | ||
color={theme.color10.val} | ||
/> | ||
} | ||
iconAfter={ | ||
<TouchableOpacity | ||
onPress={() => | ||
WebBrowser.openBrowserAsync(meta.download_uri) | ||
} | ||
> | ||
<GenericIcon name="download" color={theme.color9.val} /> | ||
</TouchableOpacity> | ||
} | ||
bordered | ||
pressTheme | ||
hoverTheme | ||
br={"$4"} | ||
my="$2" | ||
/> | ||
) | ||
} | ||
|
||
FileListItem.displayName = "FileListItem" | ||
|
||
export default FileListItem |
Oops, something went wrong.