diff --git a/app/mobile/App.js b/app/mobile/App.js index 3a8f3215..0c85981e 100644 --- a/app/mobile/App.js +++ b/app/mobile/App.js @@ -5,7 +5,7 @@ import { Routes, Route } from 'react-router-dom'; import { Root } from 'src/root/Root'; import { Access } from 'src/access/Access'; import { Session } from 'src/session/Session'; -import { Admin } from 'src/admin/Admin'; +import { Dashboard } from 'src/dashboard/Dashboard'; import { StoreContextProvider } from 'context/StoreContext'; import { UploadContextProvider } from 'context/UploadContext'; import { AppContextProvider } from 'context/AppContext'; @@ -36,7 +36,8 @@ export default function App() { } /> - } /> + } /> + } /> } /> } /> } /> diff --git a/app/mobile/src/access/Access.jsx b/app/mobile/src/access/Access.jsx index d91e5bd0..29487563 100644 --- a/app/mobile/src/access/Access.jsx +++ b/app/mobile/src/access/Access.jsx @@ -4,6 +4,7 @@ import { useAccess } from './useAccess.hook'; import { Login } from './login/Login'; import { Create } from './create/Create'; import { Reset } from './reset/Reset'; +import { Admin } from './admin/Admin'; import logo from 'images/login.png'; export function Access({ mode }) { @@ -28,6 +29,9 @@ export function Access({ mode }) { { mode === 'reset' && ( )} + { mode === 'admin' && ( + + )} )} @@ -42,6 +46,9 @@ export function Access({ mode }) { { mode === 'reset' && ( )} + { mode === 'admin' && ( + + )} )} diff --git a/app/mobile/src/access/admin/Admin.jsx b/app/mobile/src/access/admin/Admin.jsx new file mode 100644 index 00000000..49cd1cbd --- /dev/null +++ b/app/mobile/src/access/admin/Admin.jsx @@ -0,0 +1,73 @@ +import { ActivityIndicator, Alert, Text, TextInput, View, TouchableOpacity } from 'react-native'; +import { styles } from './Admin.styled'; +import Ionicons from '@expo/vector-icons/AntDesign'; +import { useAdmin } from './useAdmin.hook'; + +export function Admin() { + + const { state, actions } = useAdmin(); + + const admin = async () => { + try { + await actions.access(); + } + catch (err) { + Alert.alert( + "Access Failed", + "Please check your server and token.", + ); + } + } + + return ( + + + + + + + + Databag + + Admin Acess + + + + + + + + + + + + { state.plainText && ( + + )} + { !state.plainText && ( + + )} + + + { state.enabled && ( + + { state.busy && ( + + )} + { !state.busy && ( + Access + )} + + )} + { !state.enabled && ( + + Access + + )} + + + + ); +} diff --git a/app/mobile/src/admin/prompt/Prompt.styled.js b/app/mobile/src/access/admin/Admin.styled.js similarity index 92% rename from app/mobile/src/admin/prompt/Prompt.styled.js rename to app/mobile/src/access/admin/Admin.styled.js index 7d6f7b11..e426ce3e 100644 --- a/app/mobile/src/admin/prompt/Prompt.styled.js +++ b/app/mobile/src/access/admin/Admin.styled.js @@ -72,7 +72,7 @@ export const styles = StyleSheet.create({ textAlign: 'center', padding: 8, }, - login: { + reset: { marginTop: 16, display: 'flex', alignItems: 'center', @@ -82,10 +82,10 @@ export const styles = StyleSheet.create({ backgroundColor: Colors.primary, borderRadius: 4, }, - logintext: { + resettext: { color: Colors.formFocus, }, - nologin: { + noreset: { marginTop: 16, display: 'flex', alignItems: 'center', @@ -96,8 +96,18 @@ export const styles = StyleSheet.create({ borderColor: Colors.divider, borderWidth: 1, }, + noresettext: { + color: Colors.disabled, + }, + login: { + marginTop: 16, + }, + logintext: { + fontColor: 'yellow', + }, nologintext: { color: Colors.disabled, }, + }) diff --git a/app/mobile/src/access/admin/useAdmin.hook.js b/app/mobile/src/access/admin/useAdmin.hook.js new file mode 100644 index 00000000..283cb783 --- /dev/null +++ b/app/mobile/src/access/admin/useAdmin.hook.js @@ -0,0 +1,83 @@ +import { useState, useEffect, useContext } from 'react'; +import { useWindowDimensions } from 'react-native'; +import { useNavigate } from 'react-router-dom'; +import { AppContext } from 'context/AppContext'; +import { getNodeStatus } from 'api/getNodeStatus'; +import { setNodeStatus } from 'api/setNodeStatus'; +import { getNodeConfig } from 'api/getNodeConfig'; + +export function useAdmin() { + + const navigate = useNavigate(); + const app = useContext(AppContext); + + const [state, setState] = useState({ + busy: false, + enabled: false, + server: null, + token: null, + plainText: false, + }); + + const updateState = (value) => { + setState((s) => ({ ...s, ...value })); + } + + const checkStatus = async () => { + try { + updateState({ unclaimed: status }); + } + catch (err) { + console.log("failed to check node status"); + } + }; + + useEffect(() => { + if (state.token && state.server && !state.enabled) { + updateState({ enabled: true }); + } + if ((!state.token || !state.server) && state.enabled) { + updateState({ enabled: false }); + } + }, [state.server, state.token]); + + const actions = { + setServer: (server) => { + updateState({ server }); + }, + setToken: (token) => { + updateState({ token }); + }, + login: () => { + navigate('/login'); + }, + showPass: () => { + updateState({ plainText: true }); + }, + hidePass: () => { + updateState({ plainText: false }); + }, + access: async () => { + if (!state.busy) { + try { + updateState({ busy: true }); + const unclaimed = await getNodeStatus(state.server); + if (unclaimed) { + await setNodeStatus(state.server, state.token); + } + const config = await getNodeConfig(state.server, state.token); + updateState({ busy: false }); + navigate('/dashboard'); + } + catch (err) { + console.log(err); + updateState({ busy: false }); + throw new Error("access failed"); + } + } + } + }; + + return { state, actions }; +} + diff --git a/app/mobile/src/admin/Admin.jsx b/app/mobile/src/admin/Admin.jsx deleted file mode 100644 index e88a75ed..00000000 --- a/app/mobile/src/admin/Admin.jsx +++ /dev/null @@ -1,44 +0,0 @@ -import { SafeAreaView, Image, View } from 'react-native'; -import { styles } from './Admin.styled'; -import { useAdmin } from './useAdmin.hook'; -import { Prompt } from './prompt/Prompt'; -import { Dashboard } from './dashboard/Dashboard'; -import logo from 'images/login.png'; - -export function Admin() { - - const { state, actions } = useAdmin(); - - return ( - - - { state.split === true && ( - - - - - - { state.token == null && ( - - )} - { state.token != null && ( - - )} - - - )} - { state.split === false && ( - - { state.token == null && ( - - )} - { state.token != null && ( - - )} - - )} - - - ); -} - diff --git a/app/mobile/src/admin/Admin.styled.js b/app/mobile/src/admin/Admin.styled.js deleted file mode 100644 index 4b04240a..00000000 --- a/app/mobile/src/admin/Admin.styled.js +++ /dev/null @@ -1,30 +0,0 @@ -import { StyleSheet } from 'react-native'; -import { Colors } from 'constants/Colors'; - -export const styles = StyleSheet.create({ - wrapper: { - backgroundColor: Colors.background, - width: '100%', - height: '100%', - }, - container: { - padding: 16, - display: 'flex', - flexDirection: 'row', - }, - splash: { - flex: 1, - width: null, - height: null, - resizeMode: 'contain', - }, - pane: { - width: '50%', - height: '100%', - }, - paddedPane: { - width: '50%', - height: '100%', - paddingRight: 16, - }, -}); diff --git a/app/mobile/src/admin/prompt/Prompt.jsx b/app/mobile/src/admin/prompt/Prompt.jsx deleted file mode 100644 index 660e0b94..00000000 --- a/app/mobile/src/admin/prompt/Prompt.jsx +++ /dev/null @@ -1,34 +0,0 @@ -import { ActivityIndicator, Alert, Text, TextInput, View, TouchableOpacity } from 'react-native'; -import { styles } from './Prompt.styled'; -import Ionicons from '@expo/vector-icons/AntDesign'; -import { usePrompt } from './usePrompt.hook'; - -export function Prompt({ login }) { - - const { state, actions } = usePrompt(); - - const setLogin = async () => { - try { - let config = await actions.attach(); - login(state.password, config); - } - catch(err) { - Alert.alert( - "Access Failed", - "Please check your admin token.", - ); - } - }; - - return ( - - - - - - - - - - ); -} diff --git a/app/mobile/src/admin/prompt/usePrompt.hook.js b/app/mobile/src/admin/prompt/usePrompt.hook.js deleted file mode 100644 index fe3b1118..00000000 --- a/app/mobile/src/admin/prompt/usePrompt.hook.js +++ /dev/null @@ -1,25 +0,0 @@ -import { useState, useEffect } from 'react'; -import { useNavigate } from 'react-router-dom'; - -export function usePrompt() { - - const navigate = useNavigate(); - - const [state, setState] = useState({ - }); - - const updateState = (value) => { - setState((s) => ({ ...s, ...value })); - } - - const actions = { - attach: () => { - }, - login: () => { - navigate('/login'); - } - }; - - return { state, actions }; -} - diff --git a/app/mobile/src/admin/useAdmin.hook.js b/app/mobile/src/admin/useAdmin.hook.js deleted file mode 100644 index fb6c722e..00000000 --- a/app/mobile/src/admin/useAdmin.hook.js +++ /dev/null @@ -1,29 +0,0 @@ -import { useState, useEffect } from 'react'; -import { useWindowDimensions } from 'react-native'; - -export function useAdmin() { - - const [state, setState] = useState({ - split: null, - }); - const dimensions = useWindowDimensions(); - - const updateState = (value) => { - setState((s) => ({ ...s, ...value })); - } - - useEffect(() => { - if (dimensions.width > 650) { - updateState({ split: true }); - } - else { - updateState({ split: false }); - } - }, [dimensions]); - - const actions = { - }; - - return { state, actions }; -} - diff --git a/app/mobile/src/admin/dashboard/Dashboard.jsx b/app/mobile/src/dashboard/Dashboard.jsx similarity index 97% rename from app/mobile/src/admin/dashboard/Dashboard.jsx rename to app/mobile/src/dashboard/Dashboard.jsx index d105d5d7..dea83820 100644 --- a/app/mobile/src/admin/dashboard/Dashboard.jsx +++ b/app/mobile/src/dashboard/Dashboard.jsx @@ -1,3 +1,4 @@ export function Dashboard() { return <> } + diff --git a/app/mobile/src/session/channels/addMember/AddMember.jsx b/app/mobile/src/session/channels/addMember/AddMember.jsx index 7c02bcac..fa6050b7 100644 --- a/app/mobile/src/session/channels/addMember/AddMember.jsx +++ b/app/mobile/src/session/channels/addMember/AddMember.jsx @@ -18,7 +18,7 @@ export function AddMember({ members, item, setCard, clearCard }) { }; return ( - + setMember(!state.member)}> { state.name } @@ -26,7 +26,7 @@ export function AddMember({ members, item, setCard, clearCard }) { - + ); } diff --git a/app/mobile/src/session/conversation/addTopic/AddTopic.jsx b/app/mobile/src/session/conversation/addTopic/AddTopic.jsx index 29efb23b..11f492f9 100644 --- a/app/mobile/src/session/conversation/addTopic/AddTopic.jsx +++ b/app/mobile/src/session/conversation/addTopic/AddTopic.jsx @@ -118,7 +118,8 @@ export function AddTopic() { renderItem={renderAsset} /> )} - diff --git a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js index f2e839cb..76b9c483 100644 --- a/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js +++ b/app/mobile/src/session/conversation/addTopic/useAddTopic.hook.js @@ -15,6 +15,7 @@ export function useAddTopic(cardId, channelId) { color: Colors.text, colorSet: false, busy: false, + textSize: 14, }); const assetId = useRef(0); @@ -79,7 +80,17 @@ export function useAddTopic(cardId, channelId) { updateState({ fontSize: false }); }, setFontSize: (size) => { - updateState({ size, sizeSet: true }); + let textSize; + if (size === 'large') { + textSize = 18; + } + else if (size === 'small') { + textSize = 10; + } + else { + textSize = 14; + } + updateState({ size, sizeSet: true, textSize }); }, setFontColor: (color) => { updateState({ color, colorSet: true }); @@ -95,7 +106,7 @@ export function useAddTopic(cardId, channelId) { }; await conversation.actions.addTopic(message, state.assets); updateState({ busy: false, assets: [], message: null, - size: 'medium', sizeSet: false, + size: 'medium', sizeSet: false, textSize: 14, color: Colors.text, colorSet: false, }); } diff --git a/app/mobile/src/session/details/memberItem/MemberItem.jsx b/app/mobile/src/session/details/memberItem/MemberItem.jsx index db690645..5b354e38 100644 --- a/app/mobile/src/session/details/memberItem/MemberItem.jsx +++ b/app/mobile/src/session/details/memberItem/MemberItem.jsx @@ -23,7 +23,7 @@ export function MemberItem({ hostId, editable, members, item }) { }; return ( - + setMember(!state.member)}> { state.name } @@ -36,7 +36,7 @@ export function MemberItem({ hostId, editable, members, item }) { )} - + ); }