From 83e6b16a9d16374c102426387c65954e318c2b9e Mon Sep 17 00:00:00 2001 From: alvaro lorente Date: Tue, 27 Aug 2024 22:27:03 +0200 Subject: [PATCH] fix: navigation --- app.config.js | 10 +-- src/app/Home/index.tsx | 61 ----------------- .../helpers/observersfromLinkParser.ts | 52 -------------- src/app/Settings/helpers/storage.ts | 9 --- src/app/_layout.tsx | 9 +++ src/app/index.tsx | 68 ++++++++++++++++--- src/app/{Settings/helpers => }/mutations.ts | 0 src/app/{Settings/index.tsx => settings.tsx} | 6 +- 8 files changed, 74 insertions(+), 141 deletions(-) delete mode 100644 src/app/Home/index.tsx delete mode 100644 src/app/Settings/helpers/observersfromLinkParser.ts delete mode 100644 src/app/Settings/helpers/storage.ts rename src/app/{Settings/helpers => }/mutations.ts (100%) rename src/app/{Settings/index.tsx => settings.tsx} (89%) diff --git a/app.config.js b/app.config.js index f7fb02e..7ba2f9e 100644 --- a/app.config.js +++ b/app.config.js @@ -42,14 +42,14 @@ export default { typedRoutes: true, }, updates: { - url: "https://u.expo.dev/6002db10-a1bc-4c3a-9332-f42d17dbd6a2" + url: 'https://u.expo.dev/6002db10-a1bc-4c3a-9332-f42d17dbd6a2', }, runtimeVersion: { - policy: "appVersion" + policy: 'appVersion', }, extra: { eas: { - "projectId": "6002db10-a1bc-4c3a-9332-f42d17dbd6a2" - } - } + projectId: '6002db10-a1bc-4c3a-9332-f42d17dbd6a2', + }, + }, }; diff --git a/src/app/Home/index.tsx b/src/app/Home/index.tsx deleted file mode 100644 index 03d81f4..0000000 --- a/src/app/Home/index.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import React, { useState, useEffect, useContext } from 'react'; -import { ScrollView, Image } from 'react-native'; -import { Card } from 'react-native-paper'; -import { State } from '@/src/types/State'; -import { Status } from '@/src/types/Status'; -import { ObserverContext } from '@/src/app/_layout'; -import { ObserverManager } from '@/src/domain/observers/ObserverManager'; - -export default function Home() { - const observerManager = useContext(ObserverContext) as ObserverManager; - const [observablesState, setObservablesState] = useState([]); - const imageSelector = (status: Status) => { - switch (status) { - case Status.SUCCESS: - return require('@/src/assets/images/ok_icon_big.png'); - case Status.CHECKING: - return require('@/src/assets/images/running_icon_big.png'); - case Status.NA: - return require('@/src/assets/images/na_icon_big.png'); - case Status.FAILURE: - return require('@/src/assets/images/fail_icon_big.png'); - } - }; - useEffect(() => { - (async () => { - await observerManager.refershObservers(); - setObservablesState((await observerManager.getStates()) as any); - const MINUTES_MS = 300000; - const interval = setInterval(async () => { - setObservablesState((await observerManager.getStates()) as any); - }, MINUTES_MS); - return () => clearInterval(interval); - })(); - }, []); - return ( - <> - - {observablesState.map((state: State, index: number) => ( - - ( - - )} - /> - - ))} - - - ); -} diff --git a/src/app/Settings/helpers/observersfromLinkParser.ts b/src/app/Settings/helpers/observersfromLinkParser.ts deleted file mode 100644 index 26ba9a0..0000000 --- a/src/app/Settings/helpers/observersfromLinkParser.ts +++ /dev/null @@ -1,52 +0,0 @@ -type strategy = { - canApply: (text: string) => boolean; - apply: (text: string) => any; -}; -const githubRegex = /https:\/\/github.com\/(.+)\/(.+)\/actions\/workflows\/(.+)/; -const ccTrayRegex = /cc.xml/; -const datadogRegex = /https:\/\/app.(.*datadog.*)\/monitors\/(.+)/; -const sentryRegex = /https:\/\/sentry.io\/organizations\/(.+)\/projects\/(.+)\//; - -export const observersfromLinkParser: strategy[] = [ - { - canApply: (text: string) => githubRegex.test(text), - apply: (text: string) => { - const match = text.match(githubRegex); - return { - type: 'githubAction', - owner: match[1], - repo: match[2], - workflowId: match[3], - }; - }, - }, - { - canApply: (text: string) => ccTrayRegex.test(text), - apply: (text: string) => ({ - type: 'ccTray', - url: text, - }), - }, - { - canApply: (text: string) => datadogRegex.test(text), - apply: (text: string) => { - const match = text.match(datadogRegex); - return { - type: 'datadogMonitor', - site: match[1], - monitorId: match[2], - }; - }, - }, - { - canApply: (text: string) => sentryRegex.test(text), - apply: (text: string) => { - const match = text.match(sentryRegex); - return { - type: 'sentry', - organization: match[1], - project: match[2], - }; - }, - }, -]; diff --git a/src/app/Settings/helpers/storage.ts b/src/app/Settings/helpers/storage.ts deleted file mode 100644 index 2dbb023..0000000 --- a/src/app/Settings/helpers/storage.ts +++ /dev/null @@ -1,9 +0,0 @@ -export const storage = (electron: any) => ({ - saveObservers: (observables: any[]): void => { - electron.store.set('observables', observables); - electron.app.refreshObservers(); - }, - getObservers: (): any[] => { - return electron.store.get('observables') || []; - }, -}); diff --git a/src/app/_layout.tsx b/src/app/_layout.tsx index da36f72..fc407ad 100644 --- a/src/app/_layout.tsx +++ b/src/app/_layout.tsx @@ -30,6 +30,15 @@ export default function RootLayout() { tabBarIcon: ({ color, focused }) => , }} /> + ( + + ), + }} + /> diff --git a/src/app/index.tsx b/src/app/index.tsx index f4a2a49..03d81f4 100644 --- a/src/app/index.tsx +++ b/src/app/index.tsx @@ -1,15 +1,61 @@ -import { Text, View } from 'react-native'; +import React, { useState, useEffect, useContext } from 'react'; +import { ScrollView, Image } from 'react-native'; +import { Card } from 'react-native-paper'; +import { State } from '@/src/types/State'; +import { Status } from '@/src/types/Status'; +import { ObserverContext } from '@/src/app/_layout'; +import { ObserverManager } from '@/src/domain/observers/ObserverManager'; -export default function Index() { +export default function Home() { + const observerManager = useContext(ObserverContext) as ObserverManager; + const [observablesState, setObservablesState] = useState([]); + const imageSelector = (status: Status) => { + switch (status) { + case Status.SUCCESS: + return require('@/src/assets/images/ok_icon_big.png'); + case Status.CHECKING: + return require('@/src/assets/images/running_icon_big.png'); + case Status.NA: + return require('@/src/assets/images/na_icon_big.png'); + case Status.FAILURE: + return require('@/src/assets/images/fail_icon_big.png'); + } + }; + useEffect(() => { + (async () => { + await observerManager.refershObservers(); + setObservablesState((await observerManager.getStates()) as any); + const MINUTES_MS = 300000; + const interval = setInterval(async () => { + setObservablesState((await observerManager.getStates()) as any); + }, MINUTES_MS); + return () => clearInterval(interval); + })(); + }, []); return ( - - Edit app/index.tsx to edit this screen. - + <> + + {observablesState.map((state: State, index: number) => ( + + ( + + )} + /> + + ))} + + ); } diff --git a/src/app/Settings/helpers/mutations.ts b/src/app/mutations.ts similarity index 100% rename from src/app/Settings/helpers/mutations.ts rename to src/app/mutations.ts diff --git a/src/app/Settings/index.tsx b/src/app/settings.tsx similarity index 89% rename from src/app/Settings/index.tsx rename to src/app/settings.tsx index 9b017b2..79976d0 100644 --- a/src/app/Settings/index.tsx +++ b/src/app/settings.tsx @@ -1,10 +1,10 @@ import React, { useState, useEffect, useContext } from 'react'; import { Platform, ScrollView } from 'react-native'; import { Portal } from 'react-native-paper'; -import { Observers as ObserversComponent } from '../../components/Observers'; -import { mutations } from './helpers/mutations'; +import { Observers as ObserversComponent } from '../components/Observers'; +import { mutations } from './mutations'; import * as SecureStore from 'expo-secure-store'; -import { ObserverContext } from '../_layout'; +import { ObserverContext } from './_layout'; import { ObserverManager } from '@/src/domain/observers/ObserverManager'; export default function Settings() {