-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
geolocation and position packages #37
Open
suenot
wants to merge
26
commits into
deep-foundation:main
Choose a base branch
from
suenot:geolocation-suenot
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ff7e759
init work on geolocation package
suenot 545ed7b
fix init pakages, add save position (need to continue)
suenot e62ce09
fix naming, fix adding coordintas to history
suenot b0ee622
fix types for geolocation/position
suenot 0a0724c
add ios
suenot d71dd5c
save links with coordinates only if them are existing
suenot 2e26760
getPositionsFromDeep
suenot 99bfa75
button: get positions from deep
suenot 71fdce4
geolocation: add ios, try to unsubscribe to watch geolocations
suenot 7f98941
geolocation: watchPositionAndUnwatch
suenot 01f4396
wrong way: setState fn as args, but need used callback fn
suenot 2518d9c
refactoring
suenot ab1182a
merge main to geolocation-suenot
suenot e63f769
merge
suenot b3d583a
fixes: earth to Earth, permissionStatus to permissionState, callback …
suenot 1fa9b7f
remove init device in geolocation package
suenot 17f925a
Merge branch 'main' into geolocation-suenot
suenot bc09a61
add tree, save multiple positions with one transaction
suenot e3e4754
change buttons order to init first geolocation package, the second p…
suenot a10599d
change package name
suenot 16db108
comment trees, revert numbers to string values
suenot 22967bc
add console logs
suenot ed211ba
merge
suenot 61d46aa
new packages names
suenot f4cf8fe
merge
suenot 4253bf6
reinstall packages
suenot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { DeepClient } from "@deep-foundation/deeplinks/imports/client"; | ||
import { PACKAGE_NAME } from "./package-name"; | ||
|
||
export async function initializePackage(deep: DeepClient) { | ||
console.log(`initializePackage ${PACKAGE_NAME}`) | ||
|
||
const typeTypeLinkId = await deep.id("@deep-foundation/core", "Type"); | ||
const anyTypeLinkId = await deep.id("@deep-foundation/core", "Any"); | ||
const containTypeLinkId = await deep.id("@deep-foundation/core", "Contain"); | ||
const packageTypeLinkId = await deep.id("@deep-foundation/core", "Package"); | ||
const joinTypeLinkId = await deep.id("@deep-foundation/core", "Join"); | ||
const valueTypeLinkId = await deep.id("@deep-foundation/core", "Value"); | ||
const stringTypeLinkId = await deep.id("@deep-foundation/core", "String"); | ||
const numberTypeLinkId = await deep.id("@deep-foundation/core", "Number"); | ||
|
||
const { data: [{ id: packageLinkId }] } = await deep.insert({ | ||
type_id: packageTypeLinkId, | ||
string: { data: { value: PACKAGE_NAME } }, | ||
in: { data: [ | ||
{ | ||
type_id: containTypeLinkId, | ||
from_id: deep.linkId | ||
}, | ||
] }, | ||
out: { data: [ | ||
{ | ||
type_id: joinTypeLinkId, | ||
to_id: await deep.id('deep', 'users', 'packages'), | ||
}, | ||
{ | ||
type_id: joinTypeLinkId, | ||
to_id: await deep.id('deep', 'admin'), | ||
}, | ||
] }, | ||
}); | ||
|
||
const { data: [{ id: spaceTypeLinkId }] } = await deep.insert({ | ||
type_id: typeTypeLinkId, | ||
from_id: anyTypeLinkId, | ||
to_id: anyTypeLinkId, | ||
in: { data: { | ||
type_id: containTypeLinkId, | ||
from_id: packageLinkId, | ||
string: { data: { value: 'Space' } }, | ||
} }, | ||
}); | ||
|
||
const { data: [{ id: earthLinkId }] } = await deep.insert({ | ||
type_id: spaceTypeLinkId, | ||
from_id: anyTypeLinkId, | ||
to_id: anyTypeLinkId, | ||
in: { data: { | ||
type_id: containTypeLinkId, | ||
from_id: packageLinkId, | ||
string: { data: { value: 'Earth' } }, | ||
} }, | ||
}); | ||
|
||
} |
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 @@ | ||
export const PACKAGE_NAME=`@deep-foundation/capacitor-geolocation` |
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,14 @@ | ||
import { Geolocation, PermissionStatus } from '@capacitor/geolocation'; | ||
import { PermissionState } from '@capacitor/core'; | ||
|
||
export const checkPermissions = async ({callback}: {callback?: ({newPermissionState}: {newPermissionState: PermissionState}) => any}) => { | ||
try { | ||
const permissionStatus: PermissionStatus = await Geolocation.checkPermissions(); | ||
console.log({permissionStatus}); | ||
callback?.({newPermissionState: permissionStatus?.location}); | ||
return permissionStatus?.location; | ||
} catch { | ||
callback?.({newPermissionState: null}); | ||
return null; | ||
} | ||
}; |
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,13 @@ | ||
|
||
import { Geolocation } from '@capacitor/geolocation'; | ||
// import { Dispatch } from 'react'; | ||
|
||
export const clearWatch = async ({watchId, callback}: { watchId: string, callback?: ({ result, error }: { result?: string, error?: any }) => void} ) => { | ||
try { | ||
await Geolocation.clearWatch({id: watchId}); | ||
callback?.({result: 'success'}); | ||
} catch (error) { | ||
console.error(error); | ||
callback?.({error}) | ||
} | ||
}; |
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,13 @@ | ||
import { Geolocation, Position } from '@capacitor/geolocation'; | ||
|
||
export const getCurrentPosition = async ({callback}: {callback?: ({coordinates}: {coordinates: Position}) => void}) => { | ||
try { | ||
const coordinates = await Geolocation.getCurrentPosition(); | ||
callback?.({coordinates}); | ||
return coordinates; | ||
} catch (error) { | ||
console.log(error); | ||
callback?.({coordinates: null}); | ||
return null; | ||
} | ||
}; |
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,48 @@ | ||
import { DeepClient, DeepClientResult } from "@deep-foundation/deeplinks/imports/client"; | ||
import { PACKAGE_NAME } from "./package-name"; | ||
import { PACKAGE_NAME as PACKAGE_NAME_GEOLOCATION } from "../geolocation/package-name"; | ||
|
||
export async function getPositions({deep, deviceLinkId, space, callback}: {deep: DeepClient, deviceLinkId: number, space?: string, callback?: (positions: DeepClientResult<any>) => any}) { | ||
try { | ||
const geolocationSpaceTypeLinkId = await deep.id(PACKAGE_NAME_GEOLOCATION, space || "Earth"); | ||
|
||
if(!deviceLinkId) { | ||
throw new Error("deviceLinkId must not be 0"); | ||
} | ||
|
||
const xTypeLinkId = await deep.id(PACKAGE_NAME, 'X'); | ||
const yTypeLinkId = await deep.id(PACKAGE_NAME, 'Y'); | ||
const zTypeLinkId = await deep.id(PACKAGE_NAME, 'Z'); | ||
// const positionTreeLinkId = await deep.id(PACKAGE_NAME, 'PositionTree'); | ||
|
||
const positions = await deep.select({ | ||
type_id: { | ||
_in: [xTypeLinkId, yTypeLinkId, zTypeLinkId] | ||
}, | ||
from_id: deviceLinkId, | ||
to_id: geolocationSpaceTypeLinkId, | ||
}); | ||
|
||
// const linksDownToEarthMp = await deep.select({ | ||
// up: { | ||
// parent_id: { _eq: geolocationSpaceTypeLinkId }, | ||
// tree_id: { _eq: positionTreeLinkId } | ||
// } | ||
// }, | ||
// { | ||
// returning: `type_id id from_id to_id | ||
// to { | ||
// value | ||
// } | ||
// ` | ||
// }); | ||
// console.log({linksDownToEarthMp}); | ||
|
||
callback?.(positions); | ||
return positions; | ||
} catch (error) { | ||
console.error(error); | ||
callback?.(null); | ||
return null; | ||
} | ||
} |
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,225 @@ | ||
import { DeepClient } from "@deep-foundation/deeplinks/imports/client"; | ||
import { PACKAGE_NAME } from "./package-name"; | ||
import { PACKAGE_NAME as PACKAGE_NAME_GEOLOCATION } from "../geolocation/package-name"; | ||
|
||
export async function initializePackage(deep: DeepClient) { | ||
|
||
const typeTypeLinkId = await deep.id("@deep-foundation/core", "Type"); | ||
const containTypeLinkId = await deep.id("@deep-foundation/core", "Contain"); | ||
const packageTypeLinkId = await deep.id("@deep-foundation/core", "Package"); | ||
const joinTypeLinkId = await deep.id("@deep-foundation/core", "Join"); | ||
const valueTypeLinkId = await deep.id("@deep-foundation/core", "Value"); | ||
const numberTypeLinkId = await deep.id("@deep-foundation/core", "Number"); | ||
const stringTypeLinkId = await deep.id("@deep-foundation/core", "String"); | ||
const objectTypeLinkId = await deep.id("@deep-foundation/core", "Object"); | ||
const deviceTypeLinkId = await deep.id("@deep-foundation/device", "Device"); | ||
const treeTypeLinkId = await deep.id('@deep-foundation/core', 'Tree'); | ||
const userTypeLinkId = await deep.id('@deep-foundation/core', 'User'); | ||
const geolocationSpaceTypeLinkId = await deep.id(PACKAGE_NAME_GEOLOCATION, "Space"); | ||
// const treeIncludeNodeTypeLinkId = await deep.id("@deep-foundation/core", "TreeIncludeNode"); | ||
// const treeIncludeDownTypeLinkId = await deep.id("@deep-foundation/core", "TreeIncludeDown"); | ||
|
||
const { data: [{ id: packageLinkId }] } = await deep.insert({ | ||
type_id: packageTypeLinkId, | ||
string: { data: { value: PACKAGE_NAME } }, | ||
in: { data: [ | ||
{ | ||
type_id: containTypeLinkId, | ||
from_id: deep.linkId, | ||
string: { data: { value: 'Package' } }, | ||
}, | ||
] }, | ||
out: { data: [ | ||
{ | ||
type_id: joinTypeLinkId, | ||
to_id: await deep.id('deep', 'users', 'packages'), | ||
}, | ||
{ | ||
type_id: joinTypeLinkId, | ||
to_id: await deep.id('deep', 'admin'), | ||
}, | ||
] }, | ||
}); | ||
|
||
// const { data: [{ id: positionTreeLinkId }] } = await deep.insert({ | ||
// type_id: treeTypeLinkId, | ||
// in: { | ||
// data: { | ||
// type_id: containTypeLinkId, | ||
// from_id: packageLinkId, | ||
// string: { data: { value: 'PositionTree' } }, | ||
// }, | ||
// }, | ||
// out: { data: [ | ||
// { | ||
// type_id: treeIncludeNodeTypeLinkId, | ||
// to_id: geolocationSpaceTypeLinkId, | ||
// }, | ||
// { | ||
// type_id: treeIncludeNodeTypeLinkId, | ||
// to_id: deviceTypeLinkId, | ||
// }, | ||
// ]} | ||
// }) | ||
|
||
const { data: [{ id: xTypeLinkId }] } = await deep.insert({ | ||
type_id: typeTypeLinkId, | ||
from_id: deviceTypeLinkId, | ||
to_id: geolocationSpaceTypeLinkId, | ||
in: { data: [ | ||
{ | ||
type_id: containTypeLinkId, | ||
from_id: packageLinkId, | ||
string: { data: { value: 'X' } }, | ||
}, | ||
// { | ||
// type_id: treeIncludeDownTypeLinkId, | ||
// from_id: positionTreeLinkId, | ||
// in: { | ||
// data: [ | ||
// { | ||
// type_id: containTypeLinkId, | ||
// from_id: packageLinkId, | ||
// string: { data: { value: 'TreeIncludeDownToX' } }, | ||
// }, | ||
// ], | ||
// }, | ||
// } | ||
]}, | ||
out: { | ||
data: { | ||
type_id: valueTypeLinkId, | ||
to_id: stringTypeLinkId | ||
}, | ||
}, | ||
}); | ||
|
||
const { data: [{ id: yTypeLinkId }] } = await deep.insert({ | ||
type_id: typeTypeLinkId, | ||
from_id: deviceTypeLinkId, | ||
to_id: geolocationSpaceTypeLinkId, | ||
in: { data: [ | ||
{ | ||
type_id: containTypeLinkId, | ||
from_id: packageLinkId, | ||
string: { data: { value: 'Y' } }, | ||
}, | ||
// { | ||
// type_id: treeIncludeDownTypeLinkId, | ||
// from_id: positionTreeLinkId, | ||
// in: { | ||
// data: [ | ||
// { | ||
// type_id: containTypeLinkId, | ||
// from_id: packageLinkId, | ||
// string: { data: { value: 'TreeIncludeDownToY' } }, | ||
// }, | ||
// ], | ||
// }, | ||
// } | ||
]}, | ||
out: { | ||
data: { | ||
type_id: valueTypeLinkId, | ||
to_id: stringTypeLinkId | ||
}, | ||
}, | ||
}); | ||
|
||
const { data: [{ id: zTypeLinkId }] } = await deep.insert({ | ||
type_id: typeTypeLinkId, | ||
from_id: deviceTypeLinkId, | ||
to_id: geolocationSpaceTypeLinkId, | ||
in: { data: [ | ||
{ | ||
type_id: containTypeLinkId, | ||
from_id: packageLinkId, | ||
string: { data: { value: 'Z' } }, | ||
}, | ||
// { | ||
// type_id: treeIncludeDownTypeLinkId, | ||
// from_id: positionTreeLinkId, | ||
// in: { | ||
// data: [ | ||
// { | ||
// type_id: containTypeLinkId, | ||
// from_id: packageLinkId, | ||
// string: { data: { value: 'TreeIncludeDownToZ' } }, | ||
// }, | ||
// ], | ||
// }, | ||
// } | ||
]}, | ||
out: { | ||
data: { | ||
type_id: valueTypeLinkId, | ||
to_id: stringTypeLinkId | ||
}, | ||
}, | ||
}); | ||
|
||
const { data: [{ id: timestampTypeLinkId }] } = await deep.insert({ | ||
type_id: typeTypeLinkId, | ||
from_id: deviceTypeLinkId, | ||
to_id: geolocationSpaceTypeLinkId, | ||
in: { data: [ | ||
{ | ||
type_id: containTypeLinkId, | ||
from_id: packageLinkId, | ||
string: { data: { value: 'Timestamp' } }, | ||
}, | ||
// { | ||
// type_id: treeIncludeDownTypeLinkId, | ||
// from_id: positionTreeLinkId, | ||
// in: { | ||
// data: [ | ||
// { | ||
// type_id: containTypeLinkId, | ||
// from_id: packageLinkId, | ||
// string: { data: { value: 'TreeIncludeDownToTimestamp' } }, | ||
// }, | ||
// ], | ||
// }, | ||
// } | ||
]}, | ||
out: { | ||
data: { | ||
type_id: valueTypeLinkId, | ||
to_id: stringTypeLinkId | ||
}, | ||
}, | ||
}); | ||
|
||
const { data: [{ id: optionsTypeLinkId }] } = await deep.insert({ | ||
type_id: typeTypeLinkId, | ||
from_id: userTypeLinkId, | ||
to_id: deviceTypeLinkId, | ||
in: { data: [ | ||
{ | ||
type_id: containTypeLinkId, | ||
from_id: packageLinkId, | ||
string: { data: { value: 'Options' } }, | ||
}, | ||
// { | ||
// type_id: treeIncludeDownTypeLinkId, | ||
// from_id: positionTreeLinkId, | ||
// in: { | ||
// data: [ | ||
// { | ||
// type_id: containTypeLinkId, | ||
// from_id: packageLinkId, | ||
// string: { data: { value: 'TreeIncludeDownToOptions' } }, | ||
// }, | ||
// ], | ||
// }, | ||
// } | ||
]}, | ||
out: { | ||
data: { | ||
type_id: valueTypeLinkId, | ||
to_id: objectTypeLinkId | ||
}, | ||
}, | ||
}); | ||
|
||
} |
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 @@ | ||
export const PACKAGE_NAME=`@deep-foundation/capacitor-position` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tree https://discord.com/channels/739430470345031692/997089753356845117/1083364263067914272