mirror of
https://github.com/Stef-00012/Zipline-Android-App.git
synced 2025-05-11 18:35:58 +02:00
finish sidebar, some fixes
This commit is contained in:
parent
3c0909c1ab
commit
fdb827a1f1
18 changed files with 507 additions and 135 deletions
|
@ -15,6 +15,7 @@ import React from "react";
|
|||
import { createTag, deleteTag, editTag, getTags } from "@/functions/zipline/tags";
|
||||
import Popup from "@/components/Popup";
|
||||
import { isLightColor } from "@/functions/color";
|
||||
import { colorHash } from "@/functions/util";
|
||||
|
||||
export default function Files() {
|
||||
const router = useRouter();
|
||||
|
@ -63,7 +64,7 @@ export default function Files() {
|
|||
(async () => {
|
||||
const tags = await getTags()
|
||||
|
||||
setTags(typeof tags === "string" ? tags : null)
|
||||
setTags(typeof tags === "string" ? null : tags)
|
||||
|
||||
if (searchParams.folderId) {
|
||||
const folder = await getFolder(searchParams.folderId)
|
||||
|
@ -103,7 +104,7 @@ export default function Files() {
|
|||
|
||||
const files = await getFiles(fetchPage, fetchOptions);
|
||||
|
||||
if ((files?.pages || 1) > 1) setAllPageDisabled(false);
|
||||
if (typeof files !== "string" && (files?.pages || 1) > 1) setAllPageDisabled(false);
|
||||
|
||||
setFiles(typeof files === "string" ? null : files);
|
||||
})();
|
||||
|
@ -183,7 +184,7 @@ export default function Files() {
|
|||
|
||||
const success = await deleteTag(tagId)
|
||||
|
||||
if (typeof success === string) return ToastAndroid.show(
|
||||
if (typeof success === "string") return ToastAndroid.show(
|
||||
`Failed to delete the tag "${tag.name}"`,
|
||||
ToastAndroid.SHORT
|
||||
)
|
||||
|
@ -243,34 +244,52 @@ export default function Files() {
|
|||
placeholderTextColor="#222c47"
|
||||
/>
|
||||
|
||||
<Pressable
|
||||
style={styles.button}
|
||||
onPress={async () => {
|
||||
setNewTagError(null);
|
||||
<View style={styles.manageTagButtonsContainer}>
|
||||
<Pressable
|
||||
style={{
|
||||
...styles.button,
|
||||
...styles.manageTagButton,
|
||||
...styles.guessButton
|
||||
}}
|
||||
onPress={async () => {
|
||||
const guess = colorHash(newTagName || "")
|
||||
|
||||
if (!newTagName) return setNewTagError("Please insert a name");
|
||||
if (!hexRegex.test(newTagColor)) return setNewTagError("Please insert a valid HEX color");
|
||||
setNewTagColor(guess)
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>Guess Color</Text>
|
||||
</Pressable>
|
||||
|
||||
<Pressable
|
||||
style={{
|
||||
...styles.button,
|
||||
...styles.manageTagButton
|
||||
}}
|
||||
onPress={async () => {
|
||||
setNewTagError(null);
|
||||
|
||||
if (!newTagName) return setNewTagError("Please insert a name");
|
||||
if (!hexRegex.test(newTagColor)) return setNewTagError("Please insert a valid HEX color");
|
||||
|
||||
const newTagData = await createTag(newTagName, newTagColor)
|
||||
const newTagData = await createTag(newTagName, newTagColor)
|
||||
|
||||
if (typeof newTagData === "string")
|
||||
return setNewTagError(newTagData);
|
||||
if (typeof newTagData === "string")
|
||||
return setNewTagError(newTagData);
|
||||
|
||||
setNewTagName(null);
|
||||
setNewTagColor("#ffffff");
|
||||
setNewTagName(null);
|
||||
setNewTagColor("#ffffff");
|
||||
|
||||
const newTags = await getTags()
|
||||
const newTags = await getTags()
|
||||
|
||||
setTags(typeof newTags === "string" ? null : newTags)
|
||||
setTags(typeof newTags === "string" ? null : newTags)
|
||||
|
||||
setCreateNewTag(false);
|
||||
setTagsMenuOpen(true)
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>Create</Text>
|
||||
</Pressable>
|
||||
setCreateNewTag(false);
|
||||
setTagsMenuOpen(true)
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>Create</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
<Text
|
||||
style={styles.popupSubHeaderText}
|
||||
|
@ -313,37 +332,57 @@ export default function Files() {
|
|||
placeholderTextColor="#222c47"
|
||||
/>
|
||||
|
||||
<Pressable
|
||||
style={styles.button}
|
||||
onPress={async () => {
|
||||
setEditTagError(null);
|
||||
<View style={styles.manageTagButtonsContainer}>
|
||||
<Pressable
|
||||
style={{
|
||||
...styles.button,
|
||||
...styles.manageTagButton,
|
||||
...styles.guessButton
|
||||
}}
|
||||
onPress={async () => {
|
||||
const guess = colorHash(editTagName || "")
|
||||
|
||||
if (!editTagName) return setEditTagError("Please insert a name");
|
||||
if (!hexRegex.test(editTagColor)) return setEditTagError("Please insert a valid HEX color");
|
||||
setEditTagColor(guess)
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>Guess Color</Text>
|
||||
</Pressable>
|
||||
|
||||
<Pressable
|
||||
style={{
|
||||
...styles.button,
|
||||
...styles.manageTagButton
|
||||
}}
|
||||
onPress={async () => {
|
||||
setEditTagError(null);
|
||||
|
||||
if (!editTagName) return setEditTagError("Please insert a name");
|
||||
if (!hexRegex.test(editTagColor)) return setEditTagError("Please insert a valid HEX color");
|
||||
|
||||
|
||||
|
||||
const editedTagData = await editTag(tagToEdit.id, {
|
||||
name: editTagName,
|
||||
color: editTagColor
|
||||
})
|
||||
const editedTagData = await editTag(tagToEdit.id, {
|
||||
name: editTagName === tagToEdit.name ? undefined : editTagName,
|
||||
color: editTagColor
|
||||
})
|
||||
|
||||
if (typeof editedTagData === "string")
|
||||
return setEditTagError(editedTagData);
|
||||
if (typeof editedTagData === "string")
|
||||
return setEditTagError(editedTagData);
|
||||
|
||||
setEditTagName(null);
|
||||
setEditTagColor("#ffffff");
|
||||
setEditTagName(null);
|
||||
setEditTagColor("#ffffff");
|
||||
|
||||
const newTags = await getTags()
|
||||
const newTags = await getTags()
|
||||
|
||||
setTags(typeof newTags === "string" ? null : newTags)
|
||||
setTags(typeof newTags === "string" ? null : newTags)
|
||||
|
||||
setTagToEdit(null);
|
||||
setTagsMenuOpen(true)
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>Edit</Text>
|
||||
</Pressable>
|
||||
setTagToEdit(null);
|
||||
setTagsMenuOpen(true)
|
||||
}}
|
||||
>
|
||||
<Text style={styles.buttonText}>Edit</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
|
||||
<Text
|
||||
style={styles.popupSubHeaderText}
|
||||
|
|
|
@ -161,7 +161,7 @@ export default function Folders() {
|
|||
>
|
||||
<Table>
|
||||
{folders.map((folder, index) => {
|
||||
const name = folder.public ? (
|
||||
const name = folder.public ? (
|
||||
<Link
|
||||
key={folder.id}
|
||||
href={
|
||||
|
@ -269,11 +269,6 @@ export default function Folders() {
|
|||
ToastAndroid.SHORT
|
||||
)
|
||||
|
||||
ToastAndroid.show(
|
||||
`Failed to delete the folder "${folder.name}"'s visibility`,
|
||||
ToastAndroid.SHORT
|
||||
)
|
||||
|
||||
const folderIndex = folders.findIndex((fold) => folder.id === fold.id)
|
||||
|
||||
const newFolders = [...folders];
|
||||
|
|
|
@ -6,7 +6,7 @@ import { View, Text, Pressable, Image } from "react-native";
|
|||
import type { APISelfUser } from "@/types/zipline";
|
||||
import { styles } from "@/styles/components/header";
|
||||
import type React from "react";
|
||||
import Sidebar from "@/components/Sidebar.tsx"
|
||||
import Sidebar from "@/components/Sidebar"
|
||||
|
||||
export default function Header({ children }: PropsWithChildren) {
|
||||
const [avatar, setAvatar] = useState<string | null>(null);
|
||||
|
|
|
@ -14,8 +14,6 @@ interface Props {
|
|||
export default function LargeFileDisplay({ file, hidden, onClose }: Props) {
|
||||
const dashUrl = db.get("url") as DashURL | null;
|
||||
|
||||
console.log("aagdrgf")
|
||||
|
||||
return (
|
||||
<Pressable
|
||||
style={{
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import React, { useEffect, useRef, useState } from "react";
|
||||
import { Animated, StyleSheet, View, Dimensions, Text, Pressable } from "react-native";
|
||||
import React, { type Dispatch, type SetStateAction, useEffect, useRef, useState } from "react";
|
||||
import { Animated, View, Dimensions, Text, Pressable } from "react-native";
|
||||
import { styles } from "@/styles/components/sidebar";
|
||||
import { usePathname } from "expo-router"
|
||||
import { type RelativePathString, usePathname } from "expo-router"
|
||||
import { getSettings } from "@/functions/zipline/settings";
|
||||
import { getCurrentUser } from "@/functions/zipline/user";
|
||||
import { sidebarOptions } from "@/constants/sidebar"
|
||||
import { type SidebarOption, sidebarOptions } from "@/constants/sidebar"
|
||||
import MaterialIcons from "@expo/vector-icons/MaterialIcons";
|
||||
import { useRouter } from "expo-router"
|
||||
|
||||
|
@ -17,6 +17,8 @@ interface Props {
|
|||
export default function Sidebar({ open = false, paddingTop = 0, setOpen }: Props) {
|
||||
const router = useRouter()
|
||||
|
||||
const [openStates, setOpenStates] = useState<Record<string, boolean>>({})
|
||||
|
||||
const screenWidth = Dimensions.get("window").width;
|
||||
const translateX = useRef(new Animated.Value(-screenWidth)).current;
|
||||
|
||||
|
@ -28,13 +30,14 @@ export default function Sidebar({ open = false, paddingTop = 0, setOpen }: Props
|
|||
const settings = await getSettings()
|
||||
const user = await getCurrentUser()
|
||||
|
||||
if (user && ["ADMIN", "SUPERADMIN"].includes(user.role)) setIsAdmin(true)
|
||||
if (settings && settings.invitesEnabled) setInvitesEnabled(true)
|
||||
if (typeof user !== "string" && ["ADMIN", "SUPERADMIN"].includes(user.role)) setIsAdmin(true)
|
||||
if (typeof settings !== "string" && settings.invitesEnabled) setInvitesEnabled(true)
|
||||
})()
|
||||
})
|
||||
|
||||
const pathname = usePathname()
|
||||
|
||||
// biome-ignore lint/correctness/useExhaustiveDependencies:.
|
||||
useEffect(() => {
|
||||
Animated.timing(translateX, {
|
||||
toValue: open ? 0 : -screenWidth,
|
||||
|
@ -44,29 +47,77 @@ export default function Sidebar({ open = false, paddingTop = 0, setOpen }: Props
|
|||
}, [open, screenWidth]);
|
||||
|
||||
return (
|
||||
<Animated.View style={[styles.sidebar, { transform: [{ translateX }], width: screenWidth, paddingTop }]}>
|
||||
{/* Your sidebar content goes here */}
|
||||
<View style={styles.sidebarContent}>
|
||||
{sidebarOptions.map((option) => {
|
||||
const isActive = pathname === option.route;
|
||||
|
||||
if (option.type === "button") return (
|
||||
<Pressable key={option.route} onPress={() => {
|
||||
setOpen(false)
|
||||
router.replace(option.route)
|
||||
}} href={option.route} style={{
|
||||
...styles.sidebarOption,
|
||||
...(isActive && styles.sidebarOptionActive)
|
||||
}}>
|
||||
<MaterialIcons name={option.icon} size={20} color={isActive ? styles.sidebarOptionTextActive.color : styles.sidebarOptionText.color} />
|
||||
<Text style={{
|
||||
...styles.sidebarOptionText,
|
||||
...(isActive && styles.sidebarOptionTextActive)
|
||||
}}>{option.name}</Text>
|
||||
</Pressable>
|
||||
)
|
||||
})}
|
||||
<Animated.View style={[
|
||||
styles.sidebar,
|
||||
{
|
||||
transform: [{
|
||||
translateX
|
||||
}],
|
||||
width: screenWidth,
|
||||
paddingTop
|
||||
}]}>
|
||||
<View>
|
||||
{sidebarOptions.map(renderSidebarOptions)}
|
||||
</View>
|
||||
</Animated.View>
|
||||
);
|
||||
|
||||
function renderSidebarOptions(option: SidebarOption) {
|
||||
if (option.adminOnly && !isAdmin) return (
|
||||
<View key={option.route || option.name} />
|
||||
)
|
||||
|
||||
if (option.invitesRoute && !invitesEnabled) return (
|
||||
<View key={option.route || option.name} />
|
||||
)
|
||||
|
||||
if (option.type === "button") {
|
||||
const isActive = pathname === option.route;
|
||||
|
||||
const route = option.route as RelativePathString
|
||||
|
||||
return (
|
||||
<Pressable key={route} onPress={() => {
|
||||
setOpen(false)
|
||||
|
||||
if (isActive) return;
|
||||
|
||||
router.replace(route)
|
||||
}} style={{
|
||||
...styles.sidebarOption,
|
||||
...(isActive && styles.sidebarOptionActive)
|
||||
}}>
|
||||
<MaterialIcons name={option.icon} size={20} color={isActive ? styles.sidebarOptionTextActive.color : styles.sidebarOptionText.color} />
|
||||
<Text style={{
|
||||
...styles.sidebarOptionText,
|
||||
...(isActive && styles.sidebarOptionTextActive)
|
||||
}}>{option.name}</Text>
|
||||
</Pressable>
|
||||
)
|
||||
}
|
||||
|
||||
if (option.type === "select") {
|
||||
const open = openStates[option.name] ?? false
|
||||
|
||||
return (
|
||||
<View key={option.name}>
|
||||
<Pressable onPress={() => setOpenStates((prev) => {
|
||||
return {
|
||||
...prev,
|
||||
[option.name]: !prev[option.name]
|
||||
}
|
||||
})} style={styles.sidebarOption}>
|
||||
<MaterialIcons name={option.icon} size={20} color={styles.sidebarOptionText.color} />
|
||||
<Text style={styles.sidebarOptionText}>{option.name}</Text>
|
||||
<MaterialIcons name={open ? "expand-more" : "expand-less"} size={20} color={styles.sidebarOptionText.color} />
|
||||
</Pressable>
|
||||
{open && (
|
||||
<View style={{ paddingLeft: 20 }}>
|
||||
{option.subMenus.map(renderSidebarOptions)}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
0
components/tmp.tsx
Normal file
0
components/tmp.tsx
Normal file
|
@ -1,7 +1,10 @@
|
|||
import type { IconProps } from "@react-native-material/core";
|
||||
import type MaterialIcons from "@expo/vector-icons/MaterialIcons";
|
||||
|
||||
interface SidebarOptionButton {
|
||||
route: string;
|
||||
name: string;
|
||||
icon: string;
|
||||
icon: keyof typeof MaterialIcons.glyphMap;
|
||||
adminOnly: boolean;
|
||||
invitesRoute: boolean;
|
||||
subMenus: [];
|
||||
|
@ -11,14 +14,14 @@ interface SidebarOptionButton {
|
|||
interface SidebarOptionSelect {
|
||||
route: null;
|
||||
name: string;
|
||||
icon: string;
|
||||
icon: keyof typeof MaterialIcons.glyphMap;
|
||||
adminOnly: boolean;
|
||||
invitesRoute: boolean;
|
||||
subMenus: Array<SidebarOption>;
|
||||
type: "select";
|
||||
}
|
||||
|
||||
type SidebarOption = SidebarOptionButton | SidebarOptionSelect;
|
||||
export type SidebarOption = SidebarOptionButton | SidebarOptionSelect;
|
||||
|
||||
export const sidebarOptions: Array<SidebarOption> = [
|
||||
{
|
||||
|
@ -102,7 +105,7 @@ export const sidebarOptions: Array<SidebarOption> = [
|
|||
invitesRoute: false,
|
||||
subMenus: [
|
||||
{
|
||||
route: "/administrator/settings",
|
||||
route: "/settings",
|
||||
name: "Settings",
|
||||
icon: "settings",
|
||||
adminOnly: true,
|
||||
|
@ -111,7 +114,7 @@ export const sidebarOptions: Array<SidebarOption> = [
|
|||
type: "button"
|
||||
},
|
||||
{
|
||||
route: "/administrator/users",
|
||||
route: "/users",
|
||||
name: "Users",
|
||||
icon: "people",
|
||||
adminOnly: true,
|
||||
|
@ -120,7 +123,7 @@ export const sidebarOptions: Array<SidebarOption> = [
|
|||
type: "button"
|
||||
},
|
||||
{
|
||||
route: "/administrator/invites",
|
||||
route: "/invites",
|
||||
name: "Invites",
|
||||
icon: "mail-outline",
|
||||
adminOnly: true,
|
||||
|
|
|
@ -20,7 +20,14 @@ export async function getUserExports(): Promise<APIExports | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +49,14 @@ export async function createUserExport(): Promise<{ running: boolean } | string>
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,6 +80,13 @@ export async function deleteUserExport(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,14 @@ export async function getFiles(page: string, options: GetFilesOptions = {}): Pro
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +66,14 @@ export async function getFile(id: string): Promise<APIFile | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +95,14 @@ export async function deleteFile(id: string): Promise<APIFile | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,6 +123,8 @@ export async function updateFileTags(
|
|||
try {
|
||||
const file = await getFile(id);
|
||||
|
||||
if (typeof file === "string") return file;
|
||||
|
||||
let newTags = (file?.tags || []).map((tag) => tag.id);
|
||||
|
||||
if (options.remove)
|
||||
|
@ -124,7 +147,14 @@ export async function updateFileTags(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -156,7 +186,14 @@ export async function editFile(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -220,6 +257,13 @@ export async function uploadFiles(
|
|||
} catch(e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ import axios, { type AxiosError } from "axios";
|
|||
// GET /api/user/folders
|
||||
export async function getFolders<T extends boolean | undefined = undefined>(
|
||||
noIncl?: T,
|
||||
): Promise<T extends true ? APIFoldersNoIncl | null : APIFolders | string> {
|
||||
): Promise<T extends true ? APIFoldersNoIncl | string : APIFolders | string> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
|
@ -26,7 +26,14 @@ export async function getFolders<T extends boolean | undefined = undefined>(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +55,14 @@ export async function getFolder(id: string): Promise<APIFolder | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +94,14 @@ export async function createFolder(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +132,14 @@ export async function editFolder(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +164,14 @@ export async function deleteFolder(id: string): Promise<APIFolder | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +200,14 @@ export async function removeFileFromFolder(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,6 +238,13 @@ export async function addFileToFolder(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,14 @@ export async function getInvites(): Promise<APIInvites | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,7 +55,14 @@ export async function createInvite(expiresAt?: string, maxUses?: number): Promis
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,6 +86,13 @@ export async function deleteInvite(code: string): Promise<APIInvite | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
|
@ -20,7 +20,14 @@ export async function getSettings(): Promise<APISettings | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +51,13 @@ export async function updateSettings(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,14 @@ export async function getStats(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,6 +57,13 @@ export async function getUserStats(): Promise<APIUserStats | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,14 @@ export async function getTags(): Promise<APITags | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +59,14 @@ export async function createTag(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +88,14 @@ export async function deleteTag(id: string): Promise<APITag | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,6 +127,13 @@ export async function editTag(id: string, options: EditTagOptions = {}) {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,14 @@ export async function getURLs(): Promise<APIURLs | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +49,14 @@ export async function getURL(id: string): Promise<APIURL | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,7 +104,14 @@ export async function createURL({
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -112,7 +133,14 @@ export async function deleteURL(id: string): Promise<APIURL | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,6 +171,13 @@ export async function editURL(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,14 @@ export async function getCurrentUser(): Promise<APISelfUser | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +49,14 @@ export async function getRecentFiles(): Promise<APIRecentFiles | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import type {
|
|||
// GET /api/users(?noincl=true)
|
||||
export async function getUsers<T extends boolean | undefined = undefined>(
|
||||
noIncl?: T,
|
||||
): Promise<T extends true ? APIUsersNoIncl | null : APIUsers | string> {
|
||||
): Promise<T extends true ? APIUsersNoIncl | string : APIUsers | string> {
|
||||
const token = db.get("token");
|
||||
const url = db.get("url");
|
||||
|
||||
|
@ -31,7 +31,14 @@ export async function getUsers<T extends boolean | undefined = undefined>(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +59,14 @@ export async function getUser(id: string): Promise<APIUser | string> {
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,7 +102,14 @@ export async function createUser(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +137,14 @@ export async function deleteUser(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,6 +195,13 @@ export async function editUser(
|
|||
} catch (e) {
|
||||
const error = e as AxiosError;
|
||||
|
||||
return error.response.error;
|
||||
const data = error.response?.data as {
|
||||
error: string;
|
||||
statusCode: number;
|
||||
} | undefined;
|
||||
|
||||
if (data) return data.error
|
||||
|
||||
return "Something went wrong..."
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,5 +187,16 @@ export const styles = StyleSheet.create({
|
|||
tagFilesText: {
|
||||
color: "gray",
|
||||
marginLeft: 10
|
||||
},
|
||||
manageTagButton: {
|
||||
width: "45%",
|
||||
marginHorizontal: "2.5%",
|
||||
},
|
||||
manageTagButtonsContainer: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "space-between",
|
||||
},
|
||||
guessButton: {
|
||||
backgroundColor: "#616060"
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue