Skip to content

Commit

Permalink
Use capacitor store
Browse files Browse the repository at this point in the history
  • Loading branch information
FreePhoenix888 committed Sep 29, 2023
1 parent 7d1b678 commit 4ddb814
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 71 deletions.
10 changes: 1 addition & 9 deletions pages/contact.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import React from 'react';
import {
useLocalStore,
} from '@deep-foundation/store/local';
import {
DeepClient,
DeepProvider,
useDeep,
} from '@deep-foundation/deeplinks/imports/client';
import { Button, ChakraProvider, Stack, Text } from '@chakra-ui/react';
import { Provider } from '../src/provider';
import { Device } from '@capacitor/device';
import { saveAllCallHistory } from '../src/callhistory/callhistory';
import { Button, Stack } from '@chakra-ui/react';
import { saveAllContacts } from '../src/contact/contact';
import { Page } from '../src/react/components/page';
import { NavBar } from '../src/react/components/navbar';
Expand Down
6 changes: 3 additions & 3 deletions pages/device.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useEffect } from 'react';
import {
useLocalStore,
} from '@deep-foundation/store/local';
useCapacitorStore,
} from '@deep-foundation/store/capacitor';
import {
DeepClient,
DeepProvider,
useDeep,
} from '@deep-foundation/deeplinks/imports/client';
import { Button, ChakraProvider, Stack, Text } from '@chakra-ui/react';
import { Provider } from '../src/provider';

import { Device } from '@capacitor/device';
import { Page } from '../src/react/components/page';
import { CapacitorStoreKeys } from '../src/capacitor-store-keys';
Expand Down
6 changes: 3 additions & 3 deletions pages/geolocation.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useEffect } from 'react';
import {
useLocalStore,
} from '@deep-foundation/store/local';
useCapacitorStore,
} from '@deep-foundation/store/capacitor';
import {
DeepClient,
DeepProvider,
useDeep,
} from '@deep-foundation/deeplinks/imports/client';
import { Button, ChakraProvider, Stack, Text } from '@chakra-ui/react';
import { Provider } from '../src/provider';

import { Device } from '@capacitor/device';
import { Page } from '../src/react/components/page';
import { NavBar } from '../src/react/components/navbar';
Expand Down
20 changes: 10 additions & 10 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import NextLink from "next/link";
import { LinkIcon } from "@chakra-ui/icons";
import { Page } from "../src/react/components/page";
import { CapacitorStoreKeys } from "../src/capacitor-store-keys";
import { useLocalStore } from "@deep-foundation/store/local";
import { useCapacitorStore } from "@deep-foundation/store/capacitor";
import { SETTINGS_ROUTES } from "../src/settings-routes";
import { capitalCase } from "case-anything";
import debug from "debug";
Expand Down Expand Up @@ -53,32 +53,32 @@ function Content({ deep, deviceLinkId }: ContentParam) {
});
}, [deep]);

const [isContactsSyncEnabled, setIsContactsSyncEnabled] = useLocalStore<
const [isContactsSyncEnabled, setIsContactsSyncEnabled] = useCapacitorStore<
boolean | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.IsContactsSyncEnabled], undefined);
const [lastContactsSyncTime, setLastContactsSyncTime] = useLocalStore<
const [lastContactsSyncTime, setLastContactsSyncTime] = useCapacitorStore<
number | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.ContactsLastSyncTime], undefined);
const [isCallHistorySyncEnabled, setIsCallHistorySyncEnabled] = useLocalStore<
const [isCallHistorySyncEnabled, setIsCallHistorySyncEnabled] = useCapacitorStore<
boolean | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.IsCallHistorySyncEnabled], undefined);
const [lastCallHistorySyncTime, setLastCallHistorySyncTime] = useLocalStore<
const [lastCallHistorySyncTime, setLastCallHistorySyncTime] = useCapacitorStore<
number | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.CallHistoryLastSyncTime], undefined);
const [isNetworkSyncEnabled, setIsNetworkSyncEnabled] = useLocalStore<
const [isNetworkSyncEnabled, setIsNetworkSyncEnabled] = useCapacitorStore<
boolean | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.IsNetworkSubscriptionEnabled], false);
const [isVoiceRecorderEnabled, setIsVoiceRecorderEnabled] = useLocalStore<
const [isVoiceRecorderEnabled, setIsVoiceRecorderEnabled] = useCapacitorStore<
boolean | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.IsVoiceRecorderEnabled], undefined);
const [isLoggerEnabled, setIsLoggerEnabled] = useLocalStore(
const [isLoggerEnabled, setIsLoggerEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsLoggerEnabled],
undefined
);
const [isMotionSyncEnabled, setIsMotionSyncEnabled] = useLocalStore<
const [isMotionSyncEnabled, setIsMotionSyncEnabled] = useCapacitorStore<
boolean | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.IsMotionSyncEnabled], undefined);
const [isGeolocationSyncEnabled, setIsGeolocationSyncEnabled] = useLocalStore<
const [isGeolocationSyncEnabled, setIsGeolocationSyncEnabled] = useCapacitorStore<
boolean | undefined
>(CapacitorStoreKeys[CapacitorStoreKeys.IsGeolocationSyncEnabled], undefined);

Expand Down
12 changes: 6 additions & 6 deletions pages/messanger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function Index() {
// import { ApolloClientTokenizedProvider } from '@deep-foundation/react-hasura/apollo-client-tokenized-provider';
// import { TokenProvider, useTokenController } from '@deep-foundation/deeplinks/imports/react-token';
// import { useQuery, useSubscription, gql } from '@apollo/client';
// import { LocalStoreProvider, useLocalStore } from '@deep-foundation/store/local';
// import { LocalStoreProvider, useCapacitorStore } from '@deep-foundation/store/capacitor';
// import { MinilinksLink, MinilinksResult, useMinilinksConstruct } from '@deep-foundation/deeplinks/imports/minilinks';
// import { DeepClient, parseJwt, useAuthNode, useDeep } from '@deep-foundation/deeplinks/imports/client';
// import { useDelayedInterval, useDelayRefetch } from "../imports/use-delayed-interval";
Expand All @@ -20,7 +20,7 @@ export default function Index() {

// function usePreloaded() {
// const [token, setToken] = useTokenController();
// const pr = useLocalStore('preloaded', null);
// const pr = useCapacitorStore('preloaded', null);
// const [preloaded, setPreloaded] = pr;
// const deep = useDeep();
// const p = useRef<any>();
Expand Down Expand Up @@ -225,10 +225,10 @@ export default function Index() {
// </>;
// }

// // function useGqlUrlInput() { return useLocalStore('gqlUrlInput', NEXT_PUBLIC_GQL_PATH); }
// // function useTokenInput() { return useLocalStore('tokenInput', ''); }
// // function useLinkInput() { return useLocalStore('linkInput', ''); }
// // function useGqlUrl() { return useLocalStore('gqlUrl', NEXT_PUBLIC_GQL_PATH); }
// // function useGqlUrlInput() { return useCapacitorStore('gqlUrlInput', NEXT_PUBLIC_GQL_PATH); }
// // function useTokenInput() { return useCapacitorStore('tokenInput', ''); }
// // function useLinkInput() { return useCapacitorStore('linkInput', ''); }
// // function useGqlUrl() { return useCapacitorStore('gqlUrl', NEXT_PUBLIC_GQL_PATH); }

// function Page() {
// const [linkId, setLinkId] = useAuthNode();
Expand Down
1 change: 0 additions & 1 deletion pages/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ChakraProvider, Link, Stack } from "@chakra-ui/react";
import { DeepClient, DeepProvider } from "@deep-foundation/deeplinks/imports/client";
import { Provider } from "../src/provider";
import NextLink from 'next/link';
import { Page } from "../src/react/components/page";
import { capitalCase } from "case-anything";
Expand Down
6 changes: 3 additions & 3 deletions pages/settings/call-history.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
VStack,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { DeviceInfo, Device } from '@capacitor/device';
Expand All @@ -23,7 +23,7 @@ import { RequiredPackages } from '../../src/required-packages';
import { SettingContent } from '../../src/react/components/setting-page';

function Content() {
const [isCallHistorySyncEnabled, setIsCallHistorySyncEnabled] = useLocalStore(
const [isCallHistorySyncEnabled, setIsCallHistorySyncEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsCallHistorySyncEnabled],
undefined
);
Expand Down
6 changes: 3 additions & 3 deletions pages/settings/camera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import {
useToast,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { SettingContent } from '../../src/react/components/setting-page';
import {Camera} from '@capacitor/camera'

function Content() {
const toast = useToast();
const [isCameraSyncEnabled, setIsCameraSyncEnabled] = useLocalStore(
const [isCameraSyncEnabled, setIsCameraSyncEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsCameraSyncEnabled],
undefined
);
Expand Down
6 changes: 3 additions & 3 deletions pages/settings/contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
VStack,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { SettingContent } from '../../src/react/components/setting-page';
Expand All @@ -24,7 +24,7 @@ import { RequiredPackages } from '../../src/required-packages';
import { Contacts } from '@capacitor-community/contacts';

function Content() {
const [isContactsSyncEnabled, setIsContactsSyncEnabled] = useLocalStore(
const [isContactsSyncEnabled, setIsContactsSyncEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsContactsSyncEnabled],
undefined
);
Expand Down
4 changes: 2 additions & 2 deletions pages/settings/device.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
Switch,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { SettingContent } from '../../src/react/components/setting-page';
Expand Down
6 changes: 3 additions & 3 deletions pages/settings/geolocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
Switch,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { SettingContent } from '../../src/react/components/setting-page';

function Content() {
const [isGeolocationSyncEnabled, setIsGeolocationSyncEnabled] = useLocalStore(
const [isGeolocationSyncEnabled, setIsGeolocationSyncEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsGeolocationSyncEnabled],
undefined
);
Expand Down
4 changes: 2 additions & 2 deletions pages/settings/logger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
useToast,
} from '@chakra-ui/react';
import { DeepClient } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';
import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { useState } from 'react';
Expand All @@ -30,7 +30,7 @@ export function LoggerSettingsContent(options: ContentOptions) {
const log = debug(`deep-foundation:pages:settings:logger:content`)
const toast = useToast();
const {deep,isInstalled} = options;
const [isLoggerEnabled, setIsLoggerEnabled] = useLocalStore(
const [isLoggerEnabled, setIsLoggerEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsLoggerEnabled],
undefined
);
Expand Down
6 changes: 3 additions & 3 deletions pages/settings/motion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
VStack,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { SettingContent } from '../../src/react/components/setting-page';
Expand All @@ -25,7 +25,7 @@ import { RequiredPackages } from '../../src/required-packages';
import {WithOperatingSystemChecking} from '@deep-foundation/capacitor-motion'

function Content() {
const [isMotionSyncEnabled, setIsMotionSyncEnabled] = useLocalStore(
const [isMotionSyncEnabled, setIsMotionSyncEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsMotionSyncEnabled],
undefined
);
Expand Down
6 changes: 3 additions & 3 deletions pages/settings/network.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import {
Switch,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { SettingContent } from '../../src/react/components/setting-page';
import { useEffect } from 'react';
import { Network } from '@capacitor/network';

function Content() {
const [isNetworkSyncEnabled, setIsNetworkSyncEnabled] = useLocalStore(
const [isNetworkSyncEnabled, setIsNetworkSyncEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsNetworkSyncEnabled],
undefined
);
Expand Down
6 changes: 3 additions & 3 deletions pages/settings/voice-recorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
Switch,
} from '@chakra-ui/react';
import { DeepClient, DeepProvider } from '@deep-foundation/deeplinks/imports/client';
import { useLocalStore } from '@deep-foundation/store/local';
import { Provider } from '../../src/provider';
import { useCapacitorStore } from '@deep-foundation/store/capacitor';

import { CapacitorStoreKeys } from '../../src/capacitor-store-keys';
import { Page } from '../../src/react/components/page';
import { SettingContent } from '../../src/react/components/setting-page';

function Content() {
const [isVoiceRecorderSyncEnabled, setIsVoiceRecorderSyncEnabled] = useLocalStore(
const [isVoiceRecorderSyncEnabled, setIsVoiceRecorderSyncEnabled] = useCapacitorStore(
CapacitorStoreKeys[CapacitorStoreKeys.IsVoiceRecorderSyncEnabled],
undefined
);
Expand Down
70 changes: 70 additions & 0 deletions pages/test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useEffect } from "react";
import {
Text,
Link,
Stack,
Card,
CardBody,
Heading,
CardHeader,
VStack,
Button,
FormControl,
FormLabel,
Switch,
} from "@chakra-ui/react";
import { DeepClient } from "@deep-foundation/deeplinks/imports/client";
import NextLink from "next/link";
import { LinkIcon } from "@chakra-ui/icons";
import { Page } from "../src/react/components/page";
import { CapacitorStoreKeys } from "../src/capacitor-store-keys";
import { useCapacitorStore } from "@deep-foundation/store/capacitor";
import { SETTINGS_ROUTES } from "../src/settings-routes";
import { capitalCase } from "case-anything";
import debug from "debug";
import { ErrorAlert } from "../src/react/components/error-alert";
import { WithPackagesInstalled } from "@deep-foundation/react-with-packages-installed";
import { OptionalPackages } from "../src/optional-packages";
import { DecoratedDeep } from "../src/react/components/with-decorated-deep";
import { WithSubscriptions } from "../src/react/components/with-subscriptions";
import { NavBar } from "../src/react/components/navbar";
import { Monitoring } from "../src/react/components/monitoring";
import { setAllDataSync } from "../src/set-all-data-sync";
import { useIsAllDataSyncEnabled } from "../src/react/hooks/use-is-all-data-sync-enabled";

interface ContentParam {
deep: DecoratedDeep;
deviceLinkId: number;
}

function Content({ deep, deviceLinkId }: ContentParam) {
const [value, setValue] = useCapacitorStore("myValue", undefined)
console.log({ value, setValue })
useEffect(() => {
self['value'] = value;
self['setValue'] = setValue;
}, []);
return null;
}

export default function IndexPage() {
return (
<Page
renderChildren={({ deep, deviceLinkId }) => (
<Content deep={deep} deviceLinkId={deviceLinkId} />
)}
/>
);
}

function Pages() {
return (
<Stack>
{Object.entries(SETTINGS_ROUTES).map(([name, route]) => (
<Link as={NextLink} href={route}>
{capitalCase(name)} <LinkIcon mx="2px" />
</Link>
))}
</Stack>
);
}
2 changes: 1 addition & 1 deletion src/react/components/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
VStack,
useToast,
} from "@chakra-ui/react";
import { useLocalStore } from "@deep-foundation/store/local";
import { useCapacitorStore } from "@deep-foundation/store/capacitor";
import { CapacitorStoreKeys } from "../../capacitor-store-keys";
import {
DeepClient,
Expand Down
Loading

0 comments on commit 4ddb814

Please sign in to comment.