mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-02 14:38:46 +00:00
Compare commits
267
Commits
sql-adjustment
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a60164faf | ||
|
|
381f298ad4 | ||
|
|
8461c1acd2 | ||
|
|
dce079222a | ||
|
|
13952fa318 | ||
|
|
95c3aea1d9 | ||
|
|
1583789341 | ||
|
|
04f9195444 | ||
|
|
d0419b067a | ||
|
|
858bd1cf78 | ||
|
|
a87b1afe2a | ||
|
|
aa294e749e | ||
|
|
2cbd3c934d | ||
|
|
98358e54eb | ||
|
|
96aa7107ba | ||
|
|
5dcb654516 | ||
|
|
1253c76aef | ||
|
|
7ed5f54709 | ||
|
|
553e04ef3c | ||
|
|
c644d177f1 | ||
|
|
5263a83d1f | ||
|
|
60b9e35ae8 | ||
|
|
bdc79aeff9 | ||
|
|
7cf1e20e8f | ||
|
|
71e9908f35 | ||
|
|
929663af0c | ||
|
|
a06ef07902 | ||
|
|
b433c2bda0 | ||
|
|
334a79b68b | ||
|
|
e2f03f411d | ||
|
|
be4323f337 | ||
|
|
af6e291368 | ||
|
|
10c5e97088 | ||
|
|
36d1e993bd | ||
|
|
92b687b130 | ||
|
|
b45ad53bc6 | ||
|
|
d648b21d3b | ||
|
|
fc939885a8 | ||
|
|
b00bee0217 | ||
|
|
16626db5bd | ||
|
|
83ec915926 | ||
|
|
05343d0540 | ||
|
|
35eb0ee698 | ||
|
|
d2d13200ca | ||
|
|
1b8755049d | ||
|
|
dd99f7e241 | ||
|
|
02f0abd761 | ||
|
|
4b724dfa73 | ||
|
|
44599c882d | ||
|
|
eaae3c7211 | ||
|
|
3b7326dac8 | ||
|
|
908a393451 | ||
|
|
68d2e66d16 | ||
|
|
4e8c57492b | ||
|
|
1566bb0fdb | ||
|
|
9d7ddbca6f | ||
|
|
c073965dff | ||
|
|
4dd075a537 | ||
|
|
8498f91a1f | ||
|
|
2e714ccb0f | ||
|
|
f474bd0148 | ||
|
|
fcae80b785 | ||
|
|
80da6a0af1 | ||
|
|
33c58e9931 | ||
|
|
14f44a63d1 | ||
|
|
4ce98e29d3 | ||
|
|
0a2ba225cd | ||
|
|
ad57768745 | ||
|
|
5b017b6892 | ||
|
|
029e221a98 | ||
|
|
dc1677675b | ||
|
|
b932a0924f | ||
|
|
a562ea776a | ||
|
|
1b9ac61d1d | ||
|
|
69e5cdf326 | ||
|
|
d2e223ca39 | ||
|
|
f9956a15a8 | ||
|
|
833d2f282b | ||
|
|
e288e5b50e | ||
|
|
104fda2c11 | ||
|
|
f6395e4b8e | ||
|
|
398bfa2092 | ||
|
|
4ef89f679f | ||
|
|
eb5b907091 | ||
|
|
b1b412b81e | ||
|
|
ee8a8b62cc | ||
|
|
b033eae51e | ||
|
|
4029e8c7a1 | ||
|
|
b173f0ae48 | ||
|
|
9404a6dd26 | ||
|
|
865a8e44de | ||
|
|
94633e53a6 | ||
|
|
6a3bef1e34 | ||
|
|
44a9595463 | ||
|
|
bb81ab6fe2 | ||
|
|
e76e6c5296 | ||
|
|
2c9f260417 | ||
|
|
c59137d598 | ||
|
|
28fd09ce53 | ||
|
|
5493a3de76 | ||
|
|
f0acadbf98 | ||
|
|
52ac061a3c | ||
|
|
ecb71cc359 | ||
|
|
5e225ca736 | ||
|
|
10639260e0 | ||
|
|
3df2f88759 | ||
|
|
4afa9c691b | ||
|
|
2d1e192892 | ||
|
|
51d8aa6322 | ||
|
|
be8e9bfa39 | ||
|
|
d036243d64 | ||
|
|
1940833f56 | ||
|
|
54d456cc8a | ||
|
|
42b2970428 | ||
|
|
f1012958e2 | ||
|
|
457926263d | ||
|
|
dcb7556edc | ||
|
|
f54dc974a2 | ||
|
|
908e467011 | ||
|
|
478c5ffc63 | ||
|
|
44a0d941b9 | ||
|
|
3446de488e | ||
|
|
be70534108 | ||
|
|
0e9f8bc574 | ||
|
|
aa185224e7 | ||
|
|
871b9e0f1d | ||
|
|
b257f5bc73 | ||
|
|
fed042aea7 | ||
|
|
99fa476124 | ||
|
|
ebe8c67369 | ||
|
|
c48b7333e2 | ||
|
|
4f380a56e1 | ||
|
|
870aeda3c3 | ||
|
|
f10369a4e9 | ||
|
|
d95062d771 | ||
|
|
0e1d7f40b5 | ||
|
|
e05f543cb0 | ||
|
|
a103ef9b2f | ||
|
|
fb32aaef15 | ||
|
|
2411c39b95 | ||
|
|
488c8df5cb | ||
|
|
054f89c03d | ||
|
|
2f0f83a17e | ||
|
|
d279b31b8f | ||
|
|
2bd4f4dc96 | ||
|
|
346d194e97 | ||
|
|
f89ffc3060 | ||
|
|
c5aaf32e5d | ||
|
|
7d447c118c | ||
|
|
0134b9052c | ||
|
|
46484be9bc | ||
|
|
951ed914d5 | ||
|
|
d5aaa67c6c | ||
|
|
d18ebc066b | ||
|
|
aa8648c408 | ||
|
|
aa5eb4be2d | ||
|
|
b92cf0d6fa | ||
|
|
ea69ba4667 | ||
|
|
4c3d018751 | ||
|
|
1fe8541476 | ||
|
|
fd6afa927c | ||
|
|
f53117971e | ||
|
|
4b705da072 | ||
|
|
532a554b77 | ||
|
|
1ac4b6dd8d | ||
|
|
ba8f722c35 | ||
|
|
faf4edfbc6 | ||
|
|
34b177e827 | ||
|
|
1030ae158c | ||
|
|
4f658181d2 | ||
|
|
000151e756 | ||
|
|
80d2d5476a | ||
|
|
95ed68dff6 | ||
|
|
10e28b911e | ||
|
|
3470700fc1 | ||
|
|
8efcf2e5b5 | ||
|
|
ed05ebd6a8 | ||
|
|
cd4f7e73a6 | ||
|
|
4803753cfa | ||
|
|
85d4ab3c36 | ||
|
|
3304ae9a83 | ||
|
|
53fbf07984 | ||
|
|
9724014a9a | ||
|
|
8988ea9b26 | ||
|
|
a0c80a0e9a | ||
|
|
048753f6d2 | ||
|
|
4687635988 | ||
|
|
93fd955ae9 | ||
|
|
25a629a59b | ||
|
|
f8f722c8d2 | ||
|
|
16471ed1df | ||
|
|
feb9e8a5d3 | ||
|
|
0f8923058f | ||
|
|
06a67f14cd | ||
|
|
cb9c490cb5 | ||
|
|
33a02bb203 | ||
|
|
19e4ba0543 | ||
|
|
85eb58948d | ||
|
|
558f2388fc | ||
|
|
222070eeea | ||
|
|
6be602c95b | ||
|
|
3e01fc456c | ||
|
|
4b7a6280fd | ||
|
|
ec4ebdc54d | ||
|
|
0df1c123b0 | ||
|
|
6c9e2aef04 | ||
|
|
478d4d4519 | ||
|
|
046aeffb76 | ||
|
|
0de2495bfa | ||
|
|
ad7adcdeb6 | ||
|
|
af9ff9c92f | ||
|
|
8af7530f18 | ||
|
|
635dc907ce | ||
|
|
caf42c9c8a | ||
|
|
2dafbcc13f | ||
|
|
51b5620866 | ||
|
|
c94c69c646 | ||
|
|
b684656379 | ||
|
|
0bb20fff31 | ||
|
|
d93bdd20d8 | ||
|
|
b051ae9fac | ||
|
|
bf95ccb06b | ||
|
|
bb7d938b07 | ||
|
|
e01fa0ab0a | ||
|
|
949ea4ba4b | ||
|
|
268bd4f4a4 | ||
|
|
2ec049ca12 | ||
|
|
db03394487 | ||
|
|
8861f4e503 | ||
|
|
6a46711a51 | ||
|
|
1c69cd5e2e | ||
|
|
b14562eb9d | ||
|
|
af2b7519b6 | ||
|
|
dd3eac4a0e | ||
|
|
8ce6ec7559 | ||
|
|
60e38c9e5c | ||
|
|
71bb73b54e | ||
|
|
8dc59c47bd | ||
|
|
4fceb3750b | ||
|
|
771483b7b5 | ||
|
|
1ef01f291b | ||
|
|
6154dfc7a3 | ||
|
|
ecd7689742 | ||
|
|
2b4752dc89 | ||
|
|
bd5f3016d0 | ||
|
|
fad2ff14fa | ||
|
|
390319deda | ||
|
|
b5fca6b35b | ||
|
|
1f20b980da | ||
|
|
a880ae66ea | ||
|
|
1a3d02f1e3 | ||
|
|
b97cc4102d | ||
|
|
e1e6e8440d | ||
|
|
404d526863 | ||
|
|
e70c540ce8 | ||
|
|
62038aa5fe | ||
|
|
8e79eb1345 | ||
|
|
0cf5bc2bc7 | ||
|
|
8ef1a0aa9a | ||
|
|
2a8230e505 | ||
|
|
fcecd2aa89 | ||
|
|
d8dc5b7f47 | ||
|
|
fed7b2c13a | ||
|
|
d6b561beb8 | ||
|
|
8ca8b1b5fe | ||
|
|
4bf3248168 | ||
|
|
cb1aa80f83 |
No files matched your search
+19
-11
@@ -1,6 +1,6 @@
|
|||||||
name: Test Suite
|
name: Test Suite
|
||||||
|
|
||||||
on: [push]
|
on: [push, pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
nui_preformatting_tests:
|
nui_preformatting_tests:
|
||||||
@@ -13,11 +13,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
|
||||||
# Make sure the actual branch is checked out when running on pull requests
|
|
||||||
ref: ${{ github.head_ref }}
|
|
||||||
# This is important to fetch the changes to the previous commit
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Get yarn cache directory path
|
- name: Get yarn cache directory path
|
||||||
id: yarn-cache-dir-path
|
id: yarn-cache-dir-path
|
||||||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
run: echo "::set-output name=dir::$(yarn config get cacheFolder)"
|
||||||
@@ -36,6 +31,8 @@ jobs:
|
|||||||
run: yarn --frozen-lockfile
|
run: yarn --frozen-lockfile
|
||||||
- name: Run Enzyme Tests
|
- name: Run Enzyme Tests
|
||||||
run: yarn test
|
run: yarn test
|
||||||
|
- name: Check build status
|
||||||
|
run: yarn build
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
|
||||||
@@ -49,11 +46,6 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
|
||||||
# Make sure the actual branch is checked out when running on pull requests
|
|
||||||
ref: ${{ github.head_ref }}
|
|
||||||
# This is important to fetch the changes to the previous commit
|
|
||||||
fetch-depth: 0
|
|
||||||
- name: Use Node.js
|
- name: Use Node.js
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
@@ -62,5 +54,21 @@ jobs:
|
|||||||
run: yarn --frozen-lockfile
|
run: yarn --frozen-lockfile
|
||||||
- name: Run Jest Tests
|
- name: Run Jest Tests
|
||||||
run: yarn test
|
run: yarn test
|
||||||
|
- name: Check build status
|
||||||
|
run: yarn build
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
|
||||||
|
|
||||||
|
lint:
|
||||||
|
name: Lint Lua scripts
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: resources
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Lint
|
||||||
|
uses: GoatG33k/fivem-lua-lint-action@v1
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
name: Prerelease Publisher
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
jobs:
|
||||||
|
pre-release-build:
|
||||||
|
name: 'Build & Create Pre-Release'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
|
- name: Setup Node and Yarn Cache
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '14'
|
||||||
|
cache: 'yarn'
|
||||||
|
# Get zip util
|
||||||
|
- name: Install archive tools
|
||||||
|
run: sudo apt install zip
|
||||||
|
|
||||||
|
- name: Get variables
|
||||||
|
id: get_vars
|
||||||
|
run: |
|
||||||
|
echo "::set-output name=SHORT_SHA::$(git rev-parse --short HEAD)"
|
||||||
|
echo "::set-output name=DATE::$(date +'%D')"
|
||||||
|
|
||||||
|
- name: Install Deps
|
||||||
|
run: yarn --frozen-lockfile
|
||||||
|
|
||||||
|
- name: Run build
|
||||||
|
run: yarn build
|
||||||
|
|
||||||
|
- name: Bundle and Zip files
|
||||||
|
run: |
|
||||||
|
mkdir -p ./temp/npwd/resources
|
||||||
|
cp ./{LICENSE,README.md,config.json,import.sql,fxmanifest.lua} ./temp/npwd/
|
||||||
|
cp -r ./resources/{dist,html} ./temp/npwd/resources
|
||||||
|
cd ./temp && zip -r npwd-pre-${{ steps.get_vars.outputs.SHORT_SHA }}.zip ./npwd
|
||||||
|
|
||||||
|
- name: Create Release & Changelog
|
||||||
|
uses: "marvinpinto/[email protected]"
|
||||||
|
with:
|
||||||
|
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
title: Pre-Release Build (${{ steps.get_vars.outputs.SHORT_SHA }}) | ${{ steps.get_vars.outputs.DATE }}
|
||||||
|
prerelease: true
|
||||||
|
automatic_release_tag: "unstable"
|
||||||
|
files: ./temp/npwd-pre-${{ steps.get_vars.outputs.SHORT_SHA }}.zip
|
||||||
|
|
||||||
|
env:
|
||||||
|
CI: false
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
name: Tagged Release Publisher
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "*"
|
||||||
|
jobs:
|
||||||
|
bump-version:
|
||||||
|
name: Bump Version
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
VERSION_TAG: ${{ steps.get_version_tag.outputs.VERSION_TAG }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
|
- name: Get Version Tag
|
||||||
|
id: get_version_tag
|
||||||
|
run: echo ::set-output name=VERSION_TAG::${GITHUB_REF/refs\/tags\//}
|
||||||
|
|
||||||
|
- name: Setup Node
|
||||||
|
uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 14.x
|
||||||
|
|
||||||
|
- name: Bump package shells
|
||||||
|
run: |
|
||||||
|
cd phone && npm version ${{ needs.bump-version.outputs.VERSION_TAG }}
|
||||||
|
cd resources && npm version ${{ needs.bump-version.outputs.VERSION_TAG }}
|
||||||
|
git status
|
||||||
|
|
||||||
|
- name: Commit and push
|
||||||
|
uses: EndBug/[email protected]
|
||||||
|
with:
|
||||||
|
message: Bump version to v${{ needs.bump-version.outputs.VERSION_TAG }}
|
||||||
|
default_author: github_actions
|
||||||
|
branch: master
|
||||||
|
add: |
|
||||||
|
phone/package.json
|
||||||
|
resources/package.json
|
||||||
|
|
||||||
|
create-tagged-release:
|
||||||
|
name: Build and Create Tagged Release
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: bump-version
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Install archive tools
|
||||||
|
run: sudo apt install zip
|
||||||
|
|
||||||
|
- name: Checkout source code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
ref: ${{ github.ref }}
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: yarn
|
||||||
|
|
||||||
|
- name: Run build
|
||||||
|
run: yarn build
|
||||||
|
|
||||||
|
- name: Create Sentry Release (NPWD)
|
||||||
|
uses: tclindner/[email protected]
|
||||||
|
env:
|
||||||
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||||
|
SENTRY_ORG: 'project-error'
|
||||||
|
SENTRY_PROJECT: 'npwd'
|
||||||
|
SENTRY_URL: https://sentry.projecterror.dev/
|
||||||
|
SENTRY_LOG_LEVEL: debug
|
||||||
|
with:
|
||||||
|
environment: production
|
||||||
|
tagName: ${{ needs.bump-version.outputs.VERSION_TAG }}
|
||||||
|
sourceMapOptions: './resources/html/static/js'
|
||||||
|
|
||||||
|
- name: Create Sentry Release (NodeJS)
|
||||||
|
uses: tclindner/[email protected]
|
||||||
|
env:
|
||||||
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||||
|
SENTRY_ORG: 'project-error'
|
||||||
|
SENTRY_PROJECT: 'npwd-s'
|
||||||
|
SENTRY_URL: https://sentry.projecterror.dev/
|
||||||
|
with:
|
||||||
|
environment: production
|
||||||
|
tagName: ${{ steps.get_vars.outputs.VERSION_TAG }}
|
||||||
|
sourceMapOptions: './resources/html/static/js'
|
||||||
|
|
||||||
|
- name: Bundle built files
|
||||||
|
run: |
|
||||||
|
mkdir -p ./temp/npwd/resources
|
||||||
|
cp ./{LICENSE,README.md,config.json,import.sql,fxmanifest.lua} ./temp/npwd/
|
||||||
|
cp -r ./resources/{dist,html} ./temp/npwd/resources
|
||||||
|
cd ./temp && zip -r npwd-${{ needs.bump-version.outputs.VERSION_TAG }}.zip ./npwd
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
uses: "marvinpinto/[email protected]"
|
||||||
|
id: auto_release
|
||||||
|
with:
|
||||||
|
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
title: NPWD Release | ${{ needs.bump-version.outputs.VERSION_TAG }}
|
||||||
|
prerelease: false
|
||||||
|
files: npwd-${{ needs.bump-version.outputs.VERSION_TAG }}.zip
|
||||||
|
|
||||||
|
env:
|
||||||
|
CI: false
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
+6
-1
@@ -1,6 +1,8 @@
|
|||||||
# No IDE Folders
|
# No IDE Folders
|
||||||
.idea
|
.idea
|
||||||
|
|
||||||
|
npwd_temp
|
||||||
|
|
||||||
resources/html
|
resources/html
|
||||||
|
|
||||||
phone/.eslintcache
|
phone/.eslintcache
|
||||||
@@ -19,4 +21,7 @@ yarn-error.log*
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# Debug logs
|
# Debug logs
|
||||||
sv_npwd.log
|
sv_npwd.log
|
||||||
|
|
||||||
|
# FXServer Yarn
|
||||||
|
.yarn.installed
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
if [ -z "$husky_skip_init" ]; then
|
|
||||||
debug () {
|
|
||||||
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
|
|
||||||
}
|
|
||||||
|
|
||||||
readonly hook_name="$(basename "$0")"
|
|
||||||
debug "starting $hook_name..."
|
|
||||||
|
|
||||||
if [ "$HUSKY" = "0" ]; then
|
|
||||||
debug "HUSKY env variable is set to 0, skipping hook"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -f ~/.huskyrc ]; then
|
|
||||||
debug "sourcing ~/.huskyrc"
|
|
||||||
. ~/.huskyrc
|
|
||||||
fi
|
|
||||||
|
|
||||||
export readonly husky_skip_init=1
|
|
||||||
sh -e "$0" "$@"
|
|
||||||
exitCode="$?"
|
|
||||||
|
|
||||||
if [ $exitCode != 0 ]; then
|
|
||||||
echo "husky - $hook_name hook exited with code $exitCode (error)"
|
|
||||||
exit $exitCode
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
Executable
+4
@@ -0,0 +1,4 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
. "$(dirname "$0")/_/husky.sh"
|
||||||
|
|
||||||
|
npx --no-install commitlint --edit ""
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
# New-Phone-Who-Dis (NPWD)
|
# New-Phone-Who-Dis (NPWD)
|
||||||
|
|
||||||
<img src="https://beta.iodine.gg/zVkK7.png" width="500" height="300" />
|
<img src="https://i.file.glass/zVkK7.png" width="500" height="300" />
|
||||||
|
|
||||||
|
|
||||||
NPWD is our current running project. Our team has been working on the project since August, 2020. This resource isn’t complete yet and currently has no ETA for release. Feel free to test it out in a dev environment by following the installation guide.
|
NPWD is our flagship and current running project. The team has been working on the project since August, 2020. This resource isn’t complete yet and currently has a pre-release. There is however no ETA for a stable release, yet. Feel free to test it out in a dev environment by following the installation guide.
|
||||||
|
|
||||||
Written completely by the Project Error Dev Team in [React](https://reactjs.org/) with a [TypeScript](https://www.typescriptlang.org/) client/server environment.
|
Written completely by the Project Error Dev Team in [React](https://reactjs.org/) with a [TypeScript](https://www.typescriptlang.org/) client/server environment.
|
||||||
|
|
||||||
@@ -36,13 +36,13 @@ We do not want issues opened that are due to the phone being **WIP** as this slo
|
|||||||
|
|
||||||
Most of these apps have UI that does **not** represent the final product and are subject to change.
|
Most of these apps have UI that does **not** represent the final product and are subject to change.
|
||||||
|
|
||||||
- [**Bank**](https://beta.iodine.gg/Eh53X.png)
|
- [**Bank**](https://i.file.glass/Eh53X.png)
|
||||||
- [**Calculator**](https://beta.iodine.gg/s6VQV.png)
|
- [**Calculator**](https://i.file.glass/s6VQV.png)
|
||||||
- [**Camera**](https://beta.iodine.gg/vW0y9.png)
|
- [**Camera**](https://i.file.glass/vW0y9.png)
|
||||||
- [**Contacts**](https://beta.iodine.gg/3fujR.png)
|
- [**Contacts**](https://i.file.glass/3fujR.png)
|
||||||
- [**Marketplace**](https://beta.iodine.gg/5bUa8.png)
|
- [**Marketplace**](https://i.file.glass/5bUa8.png)
|
||||||
- [**Messages**](https://beta.iodine.gg/S4Lia.png)
|
- [**Messages**](https://i.file.glass/S4Lia.png)
|
||||||
- [**Notes**](https://beta.iodine.gg/qTkBb.png)
|
- [**Notes**](https://i.file.glass/qTkBb.png)
|
||||||
- [**Phone**](https://beta.iodine.gg/z0ii9.png)
|
- [**Phone**](https://i.file.glass/z0ii9.png)
|
||||||
- [**Settings**](https://beta.iodine.gg/mZAIt.png)
|
- [**Settings**](https://i.file.glass/mZAIt.png)
|
||||||
- [**Twitter**](https://beta.iodine.gg/rQZFR.png)
|
- [**Twitter**](https://i.file.glass/rQZFR.png)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
extends: ['@commitlint/config-conventional'],
|
||||||
|
};
|
||||||
+16
-15
@@ -1,23 +1,23 @@
|
|||||||
{
|
{
|
||||||
"Locale": "en",
|
"Locale": "en",
|
||||||
"KeyTogglePhone": 288,
|
"PhoneAsItem": {
|
||||||
"KeyTakeCall": 38,
|
"enabled": false,
|
||||||
"PhoneAsItem": false,
|
"exportResource": "my-core-resource",
|
||||||
"SwimDestroy": false,
|
"exportName": "myCheckerFunction"
|
||||||
"RunRate": 10,
|
|
||||||
"DestoryChance": 100,
|
|
||||||
"DestroyPhoneReCheck": 3,
|
|
||||||
"notificationPosition": {
|
|
||||||
"horizontal": "right",
|
|
||||||
"vertical": "top"
|
|
||||||
},
|
},
|
||||||
"general": {
|
"general": {
|
||||||
"useDashNumber": true
|
"useDashNumber": true,
|
||||||
|
"enableMultiChar": false
|
||||||
|
},
|
||||||
|
"database": {
|
||||||
|
"useIdentifierPrefix": false,
|
||||||
|
"playerTable": "users",
|
||||||
|
"identifierColumn": "identifier"
|
||||||
},
|
},
|
||||||
"twitter": {
|
"twitter": {
|
||||||
"showNotifications": true,
|
"showNotifications": true,
|
||||||
"generateProfileNameFromUsers": true,
|
"generateProfileNameFromUsers": true,
|
||||||
"allowEdtiableProfileName": true,
|
"allowEditableProfileName": true,
|
||||||
"allowDeleteTweets": true,
|
"allowDeleteTweets": true,
|
||||||
"allowReportTweets": true,
|
"allowReportTweets": true,
|
||||||
"characterLimit": 160,
|
"characterLimit": 160,
|
||||||
@@ -29,13 +29,14 @@
|
|||||||
},
|
},
|
||||||
"match": {
|
"match": {
|
||||||
"generateProfileNameFromUsers": true,
|
"generateProfileNameFromUsers": true,
|
||||||
"allowEdtiableProfileName": true
|
"allowEditableProfileName": true
|
||||||
},
|
},
|
||||||
"bank": {
|
"bank": {
|
||||||
"showNotifications": true
|
"showNotifications": true
|
||||||
},
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"level": "debug",
|
"level": "silly",
|
||||||
"enabled": true
|
"enabled": true,
|
||||||
|
"sentryEnabled": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+5
-5
@@ -3,8 +3,9 @@ game "gta5"
|
|||||||
description 'js runtime monkaW'
|
description 'js runtime monkaW'
|
||||||
authors { "itschip", "erik-sn", "TasoOneAsia", "kidz", "RockySouthpaw"}
|
authors { "itschip", "erik-sn", "TasoOneAsia", "kidz", "RockySouthpaw"}
|
||||||
|
|
||||||
client_script {
|
client_scripts {
|
||||||
'resources/dist/client/*.client.js'
|
'resources/dist/client/*.client.js',
|
||||||
|
'resources/client/*.lua'
|
||||||
}
|
}
|
||||||
|
|
||||||
server_script {
|
server_script {
|
||||||
@@ -14,8 +15,7 @@ server_script {
|
|||||||
ui_page 'resources/html/index.html'
|
ui_page 'resources/html/index.html'
|
||||||
|
|
||||||
files {
|
files {
|
||||||
|
'config.json',
|
||||||
'resources/html/index.html',
|
'resources/html/index.html',
|
||||||
'resources/html/*.js',
|
'resources/html/**/*',
|
||||||
'resources/html/*.map',
|
|
||||||
'resources/html/media/**/*'
|
|
||||||
}
|
}
|
||||||
+44
-56
@@ -1,15 +1,13 @@
|
|||||||
# comment this out if your server has a different table/location for phone_number
|
# comment this out if your server has a different table/location for phone_number
|
||||||
# or if it already exists in the users table
|
# or if it already exists in the users table
|
||||||
ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) DEFAULT NULL;
|
ALTER TABLE `users` ADD COLUMN `phone_number` VARCHAR(20) DEFAULT NULL;
|
||||||
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('phone', 'Phone', 1, 0, 1);
|
|
||||||
INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES ('dphone', 'Destroyed Phone', 1, 0, 1);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_phone_contacts (
|
CREATE TABLE IF NOT EXISTS `npwd_phone_contacts` (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
identifier varchar(60) DEFAULT NULL,
|
`identifier` varchar(48) DEFAULT NULL,
|
||||||
avatar varchar(512) DEFAULT NULL,
|
`avatar` varchar(512) DEFAULT NULL,
|
||||||
number varchar(10) DEFAULT NULL,
|
`number` varchar(12) DEFAULT NULL,
|
||||||
display varchar(60) NOT NULL DEFAULT '',
|
`display` varchar(255) NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -19,7 +17,7 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_tweets` (
|
|||||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
`likes` int NOT NULL DEFAULT '0',
|
`likes` int NOT NULL DEFAULT '0',
|
||||||
`identifier` varchar(40) NOT NULL,
|
`identifier` varchar(48) NOT NULL,
|
||||||
`visible` tinyint NOT NULL DEFAULT '1',
|
`visible` tinyint NOT NULL DEFAULT '1',
|
||||||
`images` varchar(1000) DEFAULT '',
|
`images` varchar(1000) DEFAULT '',
|
||||||
`retweet` int DEFAULT NULL,
|
`retweet` int DEFAULT NULL,
|
||||||
@@ -30,9 +28,9 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_tweets` (
|
|||||||
CREATE TABLE IF NOT EXISTS `npwd_twitter_profiles` (
|
CREATE TABLE IF NOT EXISTS `npwd_twitter_profiles` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`profile_name` varchar(90) NOT NULL,
|
`profile_name` varchar(90) NOT NULL,
|
||||||
`identifier` varchar(40) NOT NULL,
|
`identifier` varchar(48) NOT NULL,
|
||||||
# Default Profile avatar can be set here
|
# Default Profile avatar can be set here
|
||||||
`avatar_url` varchar(255) DEFAULT 'https://beta.iodine.gg/QrEvq.png',
|
`avatar_url` varchar(255) DEFAULT 'https://i.file.glass/QrEvq.png',
|
||||||
`bio` varchar(512) DEFAULT NULL,
|
`bio` varchar(512) DEFAULT NULL,
|
||||||
`location` varchar(45) DEFAULT NULL,
|
`location` varchar(45) DEFAULT NULL,
|
||||||
`job` varchar(45) DEFAULT NULL,
|
`job` varchar(45) DEFAULT NULL,
|
||||||
@@ -56,7 +54,7 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_likes` (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `npwd_match_profiles` (
|
CREATE TABLE IF NOT EXISTS `npwd_match_profiles` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`identifier` varchar(255) NOT NULL,
|
`identifier` varchar(48) NOT NULL,
|
||||||
`name` varchar(90) NOT NULL,
|
`name` varchar(90) NOT NULL,
|
||||||
`image` varchar(255) NOT NULL,
|
`image` varchar(255) NOT NULL,
|
||||||
`bio` varchar(512) DEFAULT NULL,
|
`bio` varchar(512) DEFAULT NULL,
|
||||||
@@ -72,7 +70,7 @@ CREATE TABLE IF NOT EXISTS `npwd_match_profiles` (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `npwd_match_views` (
|
CREATE TABLE IF NOT EXISTS `npwd_match_views` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`identifier` varchar(40) NOT NULL,
|
`identifier` varchar(48) NOT NULL,
|
||||||
`profile` int NOT NULL,
|
`profile` int NOT NULL,
|
||||||
`liked` tinyint DEFAULT '0',
|
`liked` tinyint DEFAULT '0',
|
||||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
@@ -82,32 +80,32 @@ CREATE TABLE IF NOT EXISTS `npwd_match_views` (
|
|||||||
CONSTRAINT `match_profile` FOREIGN KEY (`profile`) REFERENCES `npwd_match_profiles` (`id`)
|
CONSTRAINT `match_profile` FOREIGN KEY (`profile`) REFERENCES `npwd_match_profiles` (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_notes (
|
CREATE TABLE IF NOT EXISTS `npwd_notes` (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
identifier varchar(255) NOT NULL,
|
`identifier` varchar(48) NOT NULL,
|
||||||
title varchar(255) NOT NULL,
|
`title` varchar(255) NOT NULL,
|
||||||
content varchar(255) NOT NULL,
|
`content` varchar(255) NOT NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_marketplace_listings (
|
CREATE TABLE IF NOT EXISTS `npwd_marketplace_listings` (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
identifier varchar(255) DEFAULT NULL,
|
`identifier` varchar(48) DEFAULT NULL,
|
||||||
username varchar(255) DEFAULT NULL,
|
`username` varchar(255) DEFAULT NULL,
|
||||||
name varchar(50) DEFAULT NULL,
|
`name` varchar(50) DEFAULT NULL,
|
||||||
number varchar(255) NOT NULL,
|
`number` varchar(255) NOT NULL,
|
||||||
title varchar(255) DEFAULT NULL,
|
`title` varchar(255) DEFAULT NULL,
|
||||||
url varchar(255) DEFAULT NULL,
|
`url` varchar(255) DEFAULT NULL,
|
||||||
description varchar(255) NOT NULL,
|
`description` varchar(255) NOT NULL,
|
||||||
createdAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updatedAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_marketplace_reports (
|
CREATE TABLE IF NOT EXISTS `npwd_marketplace_reports` (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
listing_id int(11) DEFAULT NULL,
|
`listing_id` int(11) DEFAULT NULL,
|
||||||
profile varchar(255) DEFAULT NULL,
|
`profile` varchar(255) DEFAULT NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -125,30 +123,20 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_reports` (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `npwd_messages_groups` (
|
CREATE TABLE IF NOT EXISTS `npwd_messages_groups` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`user_identifier` varchar(40) NOT NULL,
|
`user_identifier` varchar(48) NOT NULL,
|
||||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
`group_id` varchar(512) NOT NULL,
|
`group_id` varchar(512) NOT NULL,
|
||||||
`participant_identifier` varchar(40) NOT NULL,
|
`participant_identifier` varchar(48) NOT NULL,
|
||||||
`label` varchar(60) DEFAULT '',
|
`label` varchar(60) DEFAULT '',
|
||||||
`unreadCount` int(11) NOT NULL DEFAULT 0,
|
`unreadCount` int(11) NOT NULL DEFAULT 0,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `npwd_messages_labels` (
|
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
|
||||||
`user_identifier` varchar(40) NOT NULL,
|
|
||||||
`label` varchar(60) NOT NULL,
|
|
||||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
`group_id` varchar(512) NOT NULL,
|
|
||||||
PRIMARY KEY (`id`)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `npwd_messages` (
|
CREATE TABLE IF NOT EXISTS `npwd_messages` (
|
||||||
`id` int NOT NULL AUTO_INCREMENT,
|
`id` int NOT NULL AUTO_INCREMENT,
|
||||||
`message` varchar(512) NOT NULL,
|
`message` varchar(512) NOT NULL,
|
||||||
`user_identifier` varchar(40) NOT NULL,
|
`user_identifier` varchar(48) NOT NULL,
|
||||||
`group_id` varchar(512) NOT NULL,
|
`group_id` varchar(512) NOT NULL,
|
||||||
`isRead` tinyint NOT NULL DEFAULT '0',
|
`isRead` tinyint NOT NULL DEFAULT '0',
|
||||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
@@ -157,20 +145,20 @@ CREATE TABLE IF NOT EXISTS `npwd_messages` (
|
|||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_calls (
|
CREATE TABLE IF NOT EXISTS `npwd_calls` (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
identifier varchar(255) DEFAULT NULL,
|
`identifier` varchar(48) DEFAULT NULL,
|
||||||
transmitter varchar(255) NOT NULL,
|
`transmitter` varchar(255) NOT NULL,
|
||||||
receiver varchar(255) NOT NULL,
|
`receiver` varchar(255) NOT NULL,
|
||||||
is_accepted tinyint(4) DEFAULT 0,
|
`is_accepted` tinyint(4) DEFAULT 0,
|
||||||
start varchar(255) DEFAULT NULL,
|
`start` varchar(255) DEFAULT NULL,
|
||||||
end varchar(255) DEFAULT NULL,
|
end varchar(255) DEFAULT NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS npwd_phone_gallery (
|
CREATE TABLE IF NOT EXISTS npwd_phone_gallery (
|
||||||
id int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
identifier varchar(255) DEFAULT NULL,
|
`identifier` varchar(48) DEFAULT NULL,
|
||||||
image varchar(255) DEFAULT NULL,
|
`image` varchar(255) DEFAULT NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
+13
-3
@@ -1,19 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "npwd",
|
"name": "npwd",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "A FiveM phone resource, made in React & TypeScript",
|
||||||
|
"repository": "https://github.com/project-error/new-phone-who-dis",
|
||||||
|
"license": "CC-BY-NC-SA-4.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@commitlint/cli": "^12.1.1",
|
||||||
|
"@commitlint/config-conventional": "^12.1.1",
|
||||||
|
"@octokit/core": "^3.4.0",
|
||||||
"husky": "^5.1.3",
|
"husky": "^5.1.3",
|
||||||
"lerna": "^3.22.1",
|
"lerna": "^3.22.1",
|
||||||
"prettier": "^2.2.1",
|
"prettier": "^2.2.1",
|
||||||
"pretty-quick": "^3.1.0"
|
"pretty-quick": "^3.1.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "lerna run build --concurrency 1",
|
"build": "lerna run test && lerna run build",
|
||||||
"prepare": "husky install",
|
"prepare": "husky install",
|
||||||
"format": "pretty-quick"
|
"bootstrap": "lerna bootstrap",
|
||||||
|
"format:staged": "pretty-quick --staged",
|
||||||
|
"postinstall": "husky install && yarn bootstrap",
|
||||||
|
"test": "lerna run test"
|
||||||
},
|
},
|
||||||
"husky": {
|
"husky": {
|
||||||
"hooks": {
|
"hooks": {
|
||||||
"pre-commit": "pretty-quick --staged"
|
"pre-commit": "npx run format:staged"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"presets": [
|
|
||||||
[
|
|
||||||
"@babel/preset-env",
|
|
||||||
{
|
|
||||||
"modules": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"@babel/preset-react"
|
|
||||||
],
|
|
||||||
"plugins": ["@babel/plugin-proposal-class-properties", "@babel/plugin-syntax-dynamic-import"]
|
|
||||||
}
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
REACT_APP_VERSION=$npm_package_version
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
const path = require('path');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
addAfterLoader,
|
addAfterLoader,
|
||||||
removeLoaders,
|
removeLoaders,
|
||||||
@@ -52,7 +54,17 @@ module.exports = {
|
|||||||
|
|
||||||
if (!babelLoaderIsAdded) throwError('failed to add back babel-loader for non-application JS');
|
if (!babelLoaderIsAdded) throwError('failed to add back babel-loader for non-application JS');
|
||||||
|
|
||||||
|
paths.appBuild = webpackConfig.output.path = path.resolve('../resources/html');
|
||||||
|
|
||||||
|
if (webpackConfig.mode === 'development') {
|
||||||
|
webpackConfig.devtool = 'eval-source-map';
|
||||||
|
}
|
||||||
|
|
||||||
return webpackConfig;
|
return webpackConfig;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
devServer: (devServerConfig) => {
|
||||||
|
devServerConfig.writeToDisk = true;
|
||||||
|
return devServerConfig;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
@@ -4,7 +4,7 @@ console.log(args);
|
|||||||
|
|
||||||
const path = './src/locale/';
|
const path = './src/locale/';
|
||||||
|
|
||||||
const langs = ['bs', 'no', 'es', 'fr', 'pt', 'ptbr', 'sv', 'tr'];
|
const langs = ['bs', 'no', 'es', 'fr', 'pt', 'ptbr', 'sv', 'tr', "hu"];
|
||||||
|
|
||||||
const defaultLang = 'en';
|
const defaultLang = 'en';
|
||||||
|
|
||||||
|
|||||||
+27
-62
@@ -2,92 +2,57 @@
|
|||||||
"name": "npwd-nui",
|
"name": "npwd-nui",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"repository": "https://github.com/project-error/new-phone-who-dis",
|
"repository": "https://github.com/project-error/new-phone-who-dis",
|
||||||
"private": false,
|
"private": true,
|
||||||
"license": "CC-BY-NC-SA-4.0",
|
"license": "CC-BY-NC-SA-4.0",
|
||||||
|
"homepage": "/resources/html",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/polyfill": "^7.4.4",
|
"@material-ui/core": "^4.11.3",
|
||||||
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
"@material-ui/icons": "^4.11.2",
|
||||||
"@fortawesome/free-brands-svg-icons": "^5.15.1",
|
|
||||||
"@fortawesome/free-solid-svg-icons": "^5.15.1",
|
|
||||||
"@fortawesome/react-fontawesome": "^0.1.11",
|
|
||||||
"@material-ui/core": "^4.11.0",
|
|
||||||
"@material-ui/icons": "^4.9.1",
|
|
||||||
"@material-ui/lab": "^4.0.0-alpha.56",
|
"@material-ui/lab": "^4.0.0-alpha.56",
|
||||||
"@popperjs/core": "^2.5.3",
|
|
||||||
"@sentry/react": "^5.29.2",
|
|
||||||
"@sentry/tracing": "^5.29.2",
|
|
||||||
"core-js": "^3.8.3",
|
|
||||||
"dayjs": "^1.10.4",
|
"dayjs": "^1.10.4",
|
||||||
"dompurify": "^2.2.6",
|
"dompurify": "^2.2.6",
|
||||||
"emoji-mart": "^3.0.0",
|
"emoji-mart": "^3.0.1",
|
||||||
"enzyme": "^3.11.0",
|
"enzyme": "^3.11.0",
|
||||||
"enzyme-adapter-react-16": "^1.15.5",
|
"fivem-nui-react-lib": "^2.2.8",
|
||||||
"howler": "^2.2.1",
|
"howler": "^2.2.1",
|
||||||
"i18next": "^19.7.0",
|
"i18next": "^20.3.4",
|
||||||
"jsonschema": "^1.4.0",
|
"jsonschema": "^1.4.0",
|
||||||
"parse-url": "^5.0.2",
|
"parse-url": "^5.0.7",
|
||||||
"qs": "^6.9.6",
|
"qs": "^6.9.6",
|
||||||
"react": "^16.13.1",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^17.0.2",
|
||||||
"react-hotkeys": "^2.0.0",
|
|
||||||
"react-i18next": "^11.7.1",
|
"react-i18next": "^11.7.1",
|
||||||
"react-popper": "^2.2.3",
|
|
||||||
"react-router-dom": "^5.2.0",
|
"react-router-dom": "^5.2.0",
|
||||||
"react-scripts": "4.0.1",
|
"react-scripts": "4.0.3",
|
||||||
"recoil": "^0.1.2"
|
"recoil": "^0.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.4.4",
|
|
||||||
"@babel/core": "^7.4.5",
|
|
||||||
"@babel/plugin-proposal-class-properties": "^7.4.4",
|
|
||||||
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
|
|
||||||
"@babel/preset-env": "^7.4.5",
|
|
||||||
"@babel/preset-react": "^7.0.0",
|
|
||||||
"@craco/craco": "^6.1.1",
|
"@craco/craco": "^6.1.1",
|
||||||
"@testing-library/jest-dom": "^4.2.4",
|
"@sentry/integrations": "^6.10.0",
|
||||||
"@testing-library/react": "^9.5.0",
|
"@sentry/webpack-plugin": "^1.16.0",
|
||||||
"@testing-library/user-event": "^7.2.1",
|
"@sentry/react": "^5.29.2",
|
||||||
|
"@sentry/tracing": "^5.29.2",
|
||||||
"@types/enzyme": "^3.10.7",
|
"@types/enzyme": "^3.10.7",
|
||||||
"@types/howler": "^2.2.1",
|
"@types/howler": "^2.2.1",
|
||||||
"@types/jest": "^26.0.14",
|
|
||||||
"@types/node": "^14.11.5",
|
"@types/node": "^14.11.5",
|
||||||
"@types/qs": "^6.9.5",
|
"@types/qs": "^6.9.5",
|
||||||
"@types/react": "^16.9.51",
|
"@types/react": "^16.9.51",
|
||||||
"@types/react-dom": "^16.9.8",
|
"@types/react-dom": "^16.9.8",
|
||||||
"@types/react-router-dom": "^5.1.7",
|
"@types/react-router-dom": "^5.1.7",
|
||||||
"babel-eslint": "^10.0.1",
|
"@welldone-software/why-did-you-render": "^6.1.1",
|
||||||
"babel-loader": "^8.1.0",
|
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
|
||||||
"babel-plugin-styled-components": "^1.10.0",
|
"cross-env": "^7.0.3",
|
||||||
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
|
"dotenv": "^10.0.0",
|
||||||
"copy-webpack-plugin": "6.2.1",
|
"ts-loader": "^8.3.0",
|
||||||
"cp-cli": "^2.0.0",
|
"typescript": "^4.3.2"
|
||||||
"cra-build-watch": "^3.2.0",
|
|
||||||
"cross-env": "^7.0.2",
|
|
||||||
"css-loader": "^2.1.1",
|
|
||||||
"customize-cra": "^1.0.0",
|
|
||||||
"file-loader": "^3.0.1",
|
|
||||||
"html-loader": "^0.5.5",
|
|
||||||
"html-webpack-plugin": "^4.3.0",
|
|
||||||
"react-devtools": "^4.10.1",
|
|
||||||
"react-test-renderer": "^16.13.1",
|
|
||||||
"style-loader": "^0.23.1",
|
|
||||||
"svg-url-loader": "^2.3.2",
|
|
||||||
"terser-webpack-plugin": "^1.3.0",
|
|
||||||
"ts-loader": "^8.0.4",
|
|
||||||
"typescript": "3.9.7",
|
|
||||||
"url-loader": "^1.1.2",
|
|
||||||
"webpack-cli": "^3.3.12"
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"i18n:missing": "node --experimental-json-modules i18n.missingKeys.js",
|
"i18n:missing": "node --experimental-json-modules i18n.missingKeys.js",
|
||||||
"copy:config": "cp-cli ../config.json ./src/config.autogen.json",
|
"start": "cross-env PUBLIC_URL=/ craco start",
|
||||||
"start": "craco start",
|
"watch": "cross-env REACT_APP_IN_GAME=1 craco start",
|
||||||
"watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js",
|
"build:release": "cross-env SENTRY_RELEASE=true craco build",
|
||||||
"build": "yarn copy:config && cross-env NODE_ENV=production webpack --config webpack/prod.config.js --color -p --progress --hide-modules --display-optimization-bailout",
|
"build": "craco build",
|
||||||
"build:dev": "cross-env NODE_ENV=development webpack --config webpack/dev.config.js --color -p --progress --hide-modules --display-optimization-bailout --analyze",
|
"test": "craco test --watchAll=false --testMatch **/src/**/*.test.{ts,js,tsx}"
|
||||||
"test": "craco test --watchAll=false --testMatch **/src/**/*.test.{ts,js,tsx}",
|
|
||||||
"test:watch": "react-scripts test --watchAll --testMatch **/src/**/*.test.{ts,js,tsx}",
|
|
||||||
"eject": "react-scripts eject"
|
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": "react-app"
|
"extends": "react-app"
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
customElements.define(
|
||||||
|
'x-frame-bypass',
|
||||||
|
class extends HTMLIFrameElement {
|
||||||
|
static get observedAttributes() {
|
||||||
|
return ['src'];
|
||||||
|
}
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
attributeChangedCallback() {
|
||||||
|
this.load(this.src);
|
||||||
|
}
|
||||||
|
connectedCallback() {
|
||||||
|
this.sandbox =
|
||||||
|
'' + this.sandbox ||
|
||||||
|
'allow-forms allow-modals allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation-by-user-activation'; // all except allow-top-navigation
|
||||||
|
}
|
||||||
|
load(url, options) {
|
||||||
|
if (!url || !url.startsWith('http'))
|
||||||
|
throw new Error(`Unable to load src ${url} does not start with http(s)://`);
|
||||||
|
this.srcdoc = `<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
.loader {
|
||||||
|
position: absolute;
|
||||||
|
top: calc(50% - 25px);
|
||||||
|
left: calc(50% - 25px);
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
background-color: #333;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: loader 1s infinite ease-in-out;
|
||||||
|
}
|
||||||
|
@keyframes loader {
|
||||||
|
0% {
|
||||||
|
transform: scale(0);
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
transform: scale(1);
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="loader"></div>
|
||||||
|
</body>
|
||||||
|
</html>`;
|
||||||
|
this.fetchProxy(url, options, 0)
|
||||||
|
.then((res) => res.text())
|
||||||
|
.then((data) => {
|
||||||
|
if (data)
|
||||||
|
this.srcdoc = data.replace(
|
||||||
|
/<head([^>]*)>/i,
|
||||||
|
`<head$1>
|
||||||
|
<base href="${url}">
|
||||||
|
<script>
|
||||||
|
// X-Frame-Bypass navigation event handlers
|
||||||
|
document.addEventListener('click', e => {
|
||||||
|
if (frameElement && document.activeElement && document.activeElement.href) {
|
||||||
|
e.preventDefault()
|
||||||
|
frameElement.load(document.activeElement.href)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
document.addEventListener('submit', e => {
|
||||||
|
if (frameElement && document.activeElement && document.activeElement.form && document.activeElement.form.action) {
|
||||||
|
e.preventDefault()
|
||||||
|
if (document.activeElement.form.method === 'post')
|
||||||
|
frameElement.load(document.activeElement.form.action, {method: 'post', body: new FormData(document.activeElement.form)})
|
||||||
|
else
|
||||||
|
frameElement.load(document.activeElement.form.action + '?' + new URLSearchParams(new FormData(document.activeElement.form)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
</script>`,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((e) => console.error('Unable to load proxy iframe service', e));
|
||||||
|
}
|
||||||
|
fetchProxy(url, options, i) {
|
||||||
|
const proxies = (options || {}).proxies || [
|
||||||
|
'https://cors-anywhere.herokuapp.com/',
|
||||||
|
'https://api.codetabs.com/v1/proxy/?quest=',
|
||||||
|
];
|
||||||
|
return fetch(proxies[i] + url, options)
|
||||||
|
.then((res) => {
|
||||||
|
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
||||||
|
return res;
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
if (i === proxies.length - 1) throw error;
|
||||||
|
return this.fetchProxy(url, options, i + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ extends: 'iframe' },
|
||||||
|
);
|
||||||
@@ -8,6 +8,8 @@
|
|||||||
/>
|
/>
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<!-- Enable experimental proxy custom iframe webcomp -->
|
||||||
|
<!-- <script type="module" src="./iframe.webcomp.js"></script>-->
|
||||||
<title>Project Error - New Phone Who Dis</title>
|
<title>Project Error - New Phone Who Dis</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
@@ -1,12 +1,12 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RecoilRoot } from 'recoil';
|
import { RecoilRoot } from 'recoil';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
import Phone from './Phone';
|
import { PhoneProviders } from './PhoneProviders';
|
||||||
|
|
||||||
it('renders Phone', () => {
|
it('renders Phone', () => {
|
||||||
shallow(
|
shallow(
|
||||||
<RecoilRoot>
|
<RecoilRoot>
|
||||||
<Phone />
|
<PhoneProviders />
|
||||||
</RecoilRoot>,
|
</RecoilRoot>,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
+41
-82
@@ -4,35 +4,33 @@ import './i18n';
|
|||||||
import { Route } from 'react-router-dom';
|
import { Route } from 'react-router-dom';
|
||||||
import { CallModal } from './os/call/components/CallModal';
|
import { CallModal } from './os/call/components/CallModal';
|
||||||
import { HomeApp } from './apps/home/components/Home';
|
import { HomeApp } from './apps/home/components/Home';
|
||||||
import { Box, Paper, Slide, Typography } from '@material-ui/core';
|
|
||||||
import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService';
|
|
||||||
import { NotificationBar } from './os/notifications/components/NotificationBar';
|
import { NotificationBar } from './os/notifications/components/NotificationBar';
|
||||||
import { Navigation } from './os/navigation-bar/components/Navigation';
|
import { Navigation } from './os/navigation-bar/components/Navigation';
|
||||||
import { useNuiService } from './os/nui-events/hooks/useNuiService';
|
|
||||||
import { useSimcardService } from './os/simcard/hooks/useSimcardService';
|
import { useSimcardService } from './os/simcard/hooks/useSimcardService';
|
||||||
import { usePhoneService } from './os/phone/hooks/usePhoneService';
|
import { usePhoneService } from './os/phone/hooks/usePhoneService';
|
||||||
import { useApps } from './os/apps/hooks/useApps';
|
import { useApps } from './os/apps/hooks/useApps';
|
||||||
|
|
||||||
import { useContactsService } from './apps/contacts/hooks/useContactsService';
|
|
||||||
import { useTwitterService } from './apps/twitter/hooks/useTwitterService';
|
import { useTwitterService } from './apps/twitter/hooks/useTwitterService';
|
||||||
import { useMatchService } from './apps/match/hooks/useMatchService';
|
|
||||||
import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
|
import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
|
||||||
import { useBankService } from './apps/bank/hooks/useBankService';
|
import { useBankService } from './apps/bank/hooks/useBankService';
|
||||||
import { useMessagesService } from './apps/messages/hooks/useMessageService';
|
import { useMessagesService } from './apps/messages/hooks/useMessageService';
|
||||||
import { useNotesService } from './apps/notes/hooks/useNotesService';
|
|
||||||
import { usePhotoService } from './apps/camera/hooks/usePhotoService';
|
|
||||||
import { isSettingsSchemaValid, useSettings } from './apps/settings/hooks/useSettings';
|
import { isSettingsSchemaValid, useSettings } from './apps/settings/hooks/useSettings';
|
||||||
import { useCallService } from './os/call/hooks/useCallService';
|
import { useCallService } from './os/call/hooks/useCallService';
|
||||||
import { useDialService } from './apps/dialer/hooks/useDialService';
|
import { useDialService } from './apps/dialer/hooks/useDialService';
|
||||||
import InjectDebugData from './os/debug/InjectDebugData';
|
import InjectDebugData from './os/debug/InjectDebugData';
|
||||||
import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
|
|
||||||
import { PhoneSnackbar } from './ui/components/PhoneSnackbar';
|
import { PhoneSnackbar } from './ui/components/PhoneSnackbar';
|
||||||
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
import { NotificationAlert } from './os/notifications/components/NotificationAlert';
|
||||||
import { useCallModal } from './os/call/hooks/useCallModal';
|
import { useCallModal } from './os/call/hooks/useCallModal';
|
||||||
import WindowSnackbar from './ui/components/WindowSnackbar';
|
import WindowSnackbar from './ui/components/WindowSnackbar';
|
||||||
import { usePhone } from './os/phone/hooks/usePhone';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useSnackbar } from './ui/hooks/useSnackbar';
|
import { useSnackbar } from './ui/hooks/useSnackbar';
|
||||||
|
import { PhoneEvents } from '../../typings/phone';
|
||||||
|
import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService';
|
||||||
|
import PhoneWrapper from './PhoneWrapper';
|
||||||
|
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
import DefaultConfig from '../../config.json';
|
||||||
|
import { TopLevelErrorComponent } from './ui/components/TopLevelErrorComponent';
|
||||||
|
import { useConfig } from './os/phone/hooks/useConfig';
|
||||||
|
|
||||||
function Phone() {
|
function Phone() {
|
||||||
const { t, i18n } = useTranslation();
|
const { t, i18n } = useTranslation();
|
||||||
@@ -61,105 +59,66 @@ function Phone() {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useNuiService();
|
useConfig();
|
||||||
|
|
||||||
useKeyboardService();
|
useKeyboardService();
|
||||||
usePhoneService();
|
usePhoneService();
|
||||||
useSimcardService();
|
useSimcardService();
|
||||||
useContactsService();
|
|
||||||
useTwitterService();
|
useTwitterService();
|
||||||
useMatchService();
|
|
||||||
useMarketplaceService();
|
useMarketplaceService();
|
||||||
useBankService();
|
useBankService();
|
||||||
useMessagesService();
|
useMessagesService();
|
||||||
useNotesService();
|
/*usePhotoService();*/
|
||||||
usePhotoService();
|
|
||||||
useCallService();
|
useCallService();
|
||||||
useDialService();
|
useDialService();
|
||||||
|
|
||||||
const { modal: callModal } = useCallModal();
|
const { modal: callModal } = useCallModal();
|
||||||
const { bottom, visibility } = usePhoneVisibility();
|
|
||||||
const { isPhoneReady } = usePhone();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<WindowSnackbar />
|
<TopLevelErrorComponent>
|
||||||
<Slide direction="up" timeout={{ enter: 500, exit: 500 }} in={visibility}>
|
<WindowSnackbar />
|
||||||
<div className="PhoneWrapper">
|
<PhoneWrapper>
|
||||||
<div
|
<NotificationBar />
|
||||||
className="Phone"
|
<div className="PhoneAppContainer">
|
||||||
style={{
|
<>
|
||||||
position: 'fixed',
|
<Route exact path="/" component={HomeApp} />
|
||||||
transformOrigin: 'right bottom',
|
{callModal && <Route exact path="/call" component={CallModal} />}
|
||||||
transform: `scale(${settings.zoom.value}`,
|
{apps.map((App) => (
|
||||||
bottom,
|
<App.Route key={App.id} />
|
||||||
}}
|
))}
|
||||||
>
|
</>
|
||||||
<div
|
<NotificationAlert />
|
||||||
className="PhoneFrame"
|
<PhoneSnackbar />
|
||||||
style={{
|
|
||||||
backgroundImage: `url(media/frames/${settings.frame.value})`,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div
|
|
||||||
id="phone"
|
|
||||||
className="PhoneScreen"
|
|
||||||
style={{
|
|
||||||
backgroundImage: settings.customWallpaper
|
|
||||||
? `url(${settings.customWallpaper})`
|
|
||||||
: `url(media/backgrounds/${settings.wallpaper.value})`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{isPhoneReady ? (
|
|
||||||
<>
|
|
||||||
<NotificationBar />
|
|
||||||
<div className="PhoneAppContainer">
|
|
||||||
<>
|
|
||||||
<Route exact path="/" component={HomeApp} />
|
|
||||||
{callModal && <Route exact path="/call" component={CallModal} />}
|
|
||||||
{apps.map((App) => (
|
|
||||||
<App.Route key={App.id} />
|
|
||||||
))}
|
|
||||||
</>
|
|
||||||
<NotificationAlert />
|
|
||||||
<PhoneSnackbar />
|
|
||||||
</div>
|
|
||||||
<Navigation />
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<Box
|
|
||||||
component={Paper}
|
|
||||||
height="100%"
|
|
||||||
width="100%"
|
|
||||||
display="flex"
|
|
||||||
flexDirection="column"
|
|
||||||
alignItems="center"
|
|
||||||
justifyContent="center"
|
|
||||||
>
|
|
||||||
<Typography paragraph variant="h6">
|
|
||||||
NPWD {t('INITIALIZING')}
|
|
||||||
</Typography>
|
|
||||||
<Typography paragraph>{t('GENERIC_WAIT')}</Typography>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<Navigation />
|
||||||
</Slide>
|
</PhoneWrapper>
|
||||||
|
</TopLevelErrorComponent>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Phone;
|
export default Phone;
|
||||||
|
|
||||||
InjectDebugData([
|
InjectDebugData<any>([
|
||||||
{
|
{
|
||||||
app: 'PHONE',
|
app: 'PHONE',
|
||||||
method: 'setVisibility',
|
method: PhoneEvents.SET_VISIBILITY,
|
||||||
data: true,
|
data: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
app: 'PHONE',
|
app: 'PHONE',
|
||||||
method: 'setPhoneReady',
|
method: PhoneEvents.SET_PHONE_READY,
|
||||||
data: true,
|
data: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
app: 'PHONE',
|
||||||
|
method: PhoneEvents.SET_TIME,
|
||||||
|
data: dayjs().format('hh:mm'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
app: 'PHONE',
|
||||||
|
method: PhoneEvents.SET_CONFIG,
|
||||||
|
data: DefaultConfig,
|
||||||
|
},
|
||||||
]);
|
]);
|
||||||
@@ -4,19 +4,22 @@ import { NotificationsProvider } from './os/notifications/providers/Notification
|
|||||||
import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme';
|
import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme';
|
||||||
import SnackbarProvider from './ui/providers/SnackbarProvider';
|
import SnackbarProvider from './ui/providers/SnackbarProvider';
|
||||||
import Phone from './Phone';
|
import Phone from './Phone';
|
||||||
|
import { NuiProvider } from 'fivem-nui-react-lib';
|
||||||
import { SoundProvider } from './os/sound/providers/SoundProvider';
|
import { SoundProvider } from './os/sound/providers/SoundProvider';
|
||||||
|
|
||||||
export const PhoneContainer = () => {
|
export const PhoneProviders = () => {
|
||||||
const currentTheme = usePhoneTheme();
|
const currentTheme = usePhoneTheme();
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={currentTheme}>
|
<NuiProvider resource="npwd">
|
||||||
<SoundProvider>
|
<ThemeProvider theme={currentTheme}>
|
||||||
<NotificationsProvider>
|
<SoundProvider>
|
||||||
<SnackbarProvider>
|
<NotificationsProvider>
|
||||||
<Phone />
|
<SnackbarProvider>
|
||||||
</SnackbarProvider>
|
<Phone />
|
||||||
</NotificationsProvider>
|
</SnackbarProvider>
|
||||||
</SoundProvider>
|
</NotificationsProvider>
|
||||||
</ThemeProvider>
|
</SoundProvider>
|
||||||
|
</ThemeProvider>
|
||||||
|
</NuiProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { isDefaultWallpaper } from './apps/settings/utils/isDefaultWallpaper';
|
||||||
|
import { useSettings } from './apps/settings/hooks/useSettings';
|
||||||
|
import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility';
|
||||||
|
import { Slide } from '@material-ui/core';
|
||||||
|
|
||||||
|
const PhoneWrapper: React.FC = ({ children }) => {
|
||||||
|
const [settings] = useSettings();
|
||||||
|
const { bottom, visibility } = usePhoneVisibility();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Slide direction="up" timeout={{ enter: 500, exit: 500 }} in={visibility}>
|
||||||
|
<div className="PhoneWrapper">
|
||||||
|
<div
|
||||||
|
className="Phone"
|
||||||
|
style={{
|
||||||
|
position: 'fixed',
|
||||||
|
transformOrigin: 'right bottom',
|
||||||
|
transform: `scale(${settings.zoom.value}`,
|
||||||
|
bottom,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className="PhoneFrame"
|
||||||
|
style={{
|
||||||
|
backgroundImage: `url(media/frames/${settings.frame.value})`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div
|
||||||
|
id="phone"
|
||||||
|
className="PhoneScreen"
|
||||||
|
style={{
|
||||||
|
backgroundImage: !isDefaultWallpaper(settings.wallpaper.value)
|
||||||
|
? `url(${settings.wallpaper.value})`
|
||||||
|
: `url(media/backgrounds/${settings.wallpaper.value})`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Slide>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PhoneWrapper;
|
||||||
@@ -3,8 +3,7 @@ import React, { useState } from 'react';
|
|||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { Home, List, Payment } from '@material-ui/icons';
|
||||||
import { faHome, faList, faMoneyCheck } from '@fortawesome/free-solid-svg-icons';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -30,21 +29,9 @@ export const NavigationBar = () => {
|
|||||||
showLabels
|
showLabels
|
||||||
className={classes.root}
|
className={classes.root}
|
||||||
>
|
>
|
||||||
<BottomNavigationAction
|
<BottomNavigationAction component={Link} icon={<Home />} to="/bank" />
|
||||||
component={Link}
|
<BottomNavigationAction component={Link} icon={<Payment />} to="/bank/account" />
|
||||||
icon={<FontAwesomeIcon icon={faHome} />}
|
<BottomNavigationAction component={Link} icon={<List />} to="/bank/transactions" />
|
||||||
to="/bank"
|
|
||||||
/>
|
|
||||||
<BottomNavigationAction
|
|
||||||
component={Link}
|
|
||||||
icon={<FontAwesomeIcon icon={faMoneyCheck} />}
|
|
||||||
to="/bank/account"
|
|
||||||
/>
|
|
||||||
<BottomNavigationAction
|
|
||||||
component={Link}
|
|
||||||
icon={<FontAwesomeIcon icon={faList} />}
|
|
||||||
to="/bank/transactions"
|
|
||||||
/>
|
|
||||||
</BottomNavigation>
|
</BottomNavigation>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -49,16 +49,6 @@ export const TransactionList = () => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
<TablePagination
|
|
||||||
rowsPerPageOptions={[3, 5]}
|
|
||||||
className={classes.pagination}
|
|
||||||
component="div"
|
|
||||||
count={transactionList.length}
|
|
||||||
rowsPerPage={rowsPerPage}
|
|
||||||
page={page}
|
|
||||||
onChangePage={handleChangePage}
|
|
||||||
onChangeRowsPerPage={handleChangeRowsPerPage}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import Modal from '../../../../ui/components/Modal';
|
import Modal from '../../../../ui/components/Modal';
|
||||||
import { Button, List, ListItem, TextField, makeStyles } from '@material-ui/core';
|
import { Button, List, ListItem, makeStyles } from '@material-ui/core';
|
||||||
|
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
|
|
||||||
import { useBankModal } from '../../hooks/useBankModal';
|
import { useBankModal } from '../../hooks/useBankModal';
|
||||||
import { BankEvents } from '../../../../../../typings/bank';
|
import { BankEvents } from '../../../../../../typings/bank';
|
||||||
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
|
import { TextField } from '../../../../ui/components/Input';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
input: {
|
input: {
|
||||||
@@ -30,6 +29,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
export const TransferModal = () => {
|
export const TransferModal = () => {
|
||||||
|
const Nui = useNuiRequest();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
const [targetID, setTargetID] = useState('');
|
const [targetID, setTargetID] = useState('');
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||||
import { bankState } from './state';
|
import { bankState } from './state';
|
||||||
import { useTransactions } from './useTransactions';
|
import { useTransactions } from './useTransactions';
|
||||||
import { useCredentials } from './useCredentials';
|
import { useCredentials } from './useCredentials';
|
||||||
@@ -7,7 +7,6 @@ import { useBankNotification } from './useBankNotification';
|
|||||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { BankEvents } from '../../../../../typings/bank';
|
import { BankEvents } from '../../../../../typings/bank';
|
||||||
import { PhoneEvents } from '../../../../../typings/phone';
|
|
||||||
|
|
||||||
export const useBankService = () => {
|
export const useBankService = () => {
|
||||||
const setTransaction = useSetRecoilState(bankState.transactions);
|
const setTransaction = useSetRecoilState(bankState.transactions);
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
import { AppWrapper } from '../../../ui/components';
|
||||||
|
import React, { Reducer, useReducer, useRef } from 'react';
|
||||||
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
|
import { Box, makeStyles } from '@material-ui/core';
|
||||||
|
import { BrowserURLBar } from './BrowserURLBar';
|
||||||
|
import { promiseTimeout } from '../../../utils/promiseTimeout';
|
||||||
|
import { usePhoneConfig } from '../../../config/hooks/usePhoneConfig';
|
||||||
|
|
||||||
|
const useStyles = makeStyles(() => ({
|
||||||
|
iframe: {
|
||||||
|
height: '100%',
|
||||||
|
width: '100%',
|
||||||
|
zoom: 0.5,
|
||||||
|
border: 'none',
|
||||||
|
},
|
||||||
|
root: {
|
||||||
|
height: '100%',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
interface BrowserState {
|
||||||
|
browserUrl: string;
|
||||||
|
browserHistory: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ReducerAction {
|
||||||
|
payload: any;
|
||||||
|
type: ReducerActionsType;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ReducerActionsType {
|
||||||
|
SET_URL,
|
||||||
|
ADD_HISTORY,
|
||||||
|
RELOAD,
|
||||||
|
}
|
||||||
|
|
||||||
|
const browserReducer: Reducer<BrowserState, ReducerAction> = (state, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case ReducerActionsType.ADD_HISTORY:
|
||||||
|
if (action.payload === 'about:blank') return state;
|
||||||
|
return { ...state, browserHistory: state.browserHistory.concat(action.payload) };
|
||||||
|
case ReducerActionsType.SET_URL:
|
||||||
|
return { ...state, browserUrl: action.payload };
|
||||||
|
default:
|
||||||
|
throw new Error('Invalid reducer action type');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const BrowserApp: React.FC = () => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const [{ appSettings }] = usePhoneConfig();
|
||||||
|
const [browserState, dispatch] = useReducer(browserReducer, {
|
||||||
|
browserUrl: appSettings.browserHomePage,
|
||||||
|
browserHistory: [appSettings.browserHomePage],
|
||||||
|
});
|
||||||
|
|
||||||
|
const { browserHistory, browserUrl } = browserState;
|
||||||
|
|
||||||
|
const iframeRef = useRef<HTMLIFrameElement | null>(null);
|
||||||
|
const _setBrowserUrl = (newUrl: string) => {
|
||||||
|
const formattedUrl = newUrl.match(/^(http|https):\/\//) ? newUrl : 'https://' + newUrl;
|
||||||
|
dispatch({ payload: browserUrl, type: ReducerActionsType.ADD_HISTORY });
|
||||||
|
dispatch({ payload: formattedUrl, type: ReducerActionsType.SET_URL });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleGoBack = () => {
|
||||||
|
if (browserHistory.length <= 1) return;
|
||||||
|
// Get last page from history
|
||||||
|
const lastPage = browserHistory[browserHistory.length - 1];
|
||||||
|
|
||||||
|
// Bail if last page is same as current
|
||||||
|
if (lastPage === browserUrl) return;
|
||||||
|
_setBrowserUrl(lastPage);
|
||||||
|
};
|
||||||
|
|
||||||
|
const reloadPage = async () => {
|
||||||
|
const strCopy = browserUrl.slice();
|
||||||
|
dispatch({ payload: 'about:blank', type: ReducerActionsType.SET_URL });
|
||||||
|
await promiseTimeout(100);
|
||||||
|
dispatch({ payload: strCopy, type: ReducerActionsType.SET_URL });
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AppWrapper id="browser">
|
||||||
|
<AppContent className={classes.root}>
|
||||||
|
<BrowserURLBar
|
||||||
|
browserUrl={browserUrl}
|
||||||
|
browserHasHistory={browserHistory.length > 1}
|
||||||
|
setBrowser={_setBrowserUrl}
|
||||||
|
goBack={handleGoBack}
|
||||||
|
reloadPage={reloadPage}
|
||||||
|
/>
|
||||||
|
<Box flexGrow={1}>
|
||||||
|
<iframe
|
||||||
|
is="x-frame-bypass"
|
||||||
|
src={browserUrl}
|
||||||
|
// @ts-ignore
|
||||||
|
className={classes.iframe}
|
||||||
|
title="npwd-browser"
|
||||||
|
ref={iframeRef}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
</AppContent>
|
||||||
|
</AppWrapper>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import React, { FocusEventHandler, useRef, useState } from 'react';
|
||||||
|
import { makeStyles, Theme, Box, IconButton } from '@material-ui/core';
|
||||||
|
import { Cached, KeyboardArrowLeft } from '@material-ui/icons';
|
||||||
|
import { InputBase } from '../../../ui/components/Input';
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
|
urlInput: {
|
||||||
|
borderRadius: 18,
|
||||||
|
borderWidth: 1,
|
||||||
|
borderStyle: 'solid',
|
||||||
|
paddingRight: 10,
|
||||||
|
paddingLeft: 10,
|
||||||
|
marginLeft: 5,
|
||||||
|
borderColor: '#787878FF',
|
||||||
|
color: '#909090',
|
||||||
|
transition: 'color 0.1s ease',
|
||||||
|
},
|
||||||
|
urlInputFocused: {
|
||||||
|
color: '#fff',
|
||||||
|
},
|
||||||
|
root: {},
|
||||||
|
}));
|
||||||
|
|
||||||
|
interface BrowserControlsProps {
|
||||||
|
setBrowser: (url: string) => void;
|
||||||
|
browserUrl: string;
|
||||||
|
reloadPage: () => void;
|
||||||
|
browserHasHistory: boolean;
|
||||||
|
goBack: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const BrowserURLBar: React.FC<BrowserControlsProps> = ({
|
||||||
|
goBack,
|
||||||
|
reloadPage,
|
||||||
|
browserHasHistory,
|
||||||
|
browserUrl,
|
||||||
|
setBrowser,
|
||||||
|
}) => {
|
||||||
|
const classes = useStyles();
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
const [inputState, setInputState] = useState('');
|
||||||
|
const [isFocused, setFocus] = useState(false);
|
||||||
|
|
||||||
|
const handleFocus: FocusEventHandler = (e) => {
|
||||||
|
setInputState(browserUrl);
|
||||||
|
setFocus(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleFocusOut: FocusEventHandler = (e) => {
|
||||||
|
setFocus(false);
|
||||||
|
setInputState(browserUrl);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
setInputState(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEnter: React.KeyboardEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
if ((e as any).code !== 'Enter') return;
|
||||||
|
setBrowser(inputState);
|
||||||
|
e.currentTarget.blur();
|
||||||
|
};
|
||||||
|
|
||||||
|
const styledUrl = browserUrl.replace(/(^\w+:|^)\/\//, '');
|
||||||
|
|
||||||
|
const transformedUrl = isFocused ? inputState : styledUrl;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box display="flex" py={1} className={classes.root} px={1}>
|
||||||
|
<IconButton size="small" onClick={() => reloadPage()}>
|
||||||
|
<Cached />
|
||||||
|
</IconButton>
|
||||||
|
{browserHasHistory && (
|
||||||
|
<IconButton size="small" onClick={() => goBack()}>
|
||||||
|
<KeyboardArrowLeft />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
<InputBase
|
||||||
|
className={classes.urlInput}
|
||||||
|
ref={inputRef}
|
||||||
|
fullWidth
|
||||||
|
onChange={handleChange}
|
||||||
|
onKeyDown={onEnter}
|
||||||
|
value={transformedUrl}
|
||||||
|
classes={{ focused: classes.urlInputFocused }}
|
||||||
|
onFocus={handleFocus}
|
||||||
|
spellCheck={false}
|
||||||
|
onBlur={handleFocusOut}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -3,38 +3,20 @@ import { AppWrapper } from '../../../ui/components';
|
|||||||
import { AppContent } from '../../../ui/components/AppContent';
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
import { GalleryGrid } from './grid/GalleryGrid';
|
import { GalleryGrid } from './grid/GalleryGrid';
|
||||||
import { GalleryModal } from './modal/GalleryModal';
|
import { GalleryModal } from './modal/GalleryModal';
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
|
||||||
import { Route, Switch } from 'react-router-dom';
|
import { Route, Switch } from 'react-router-dom';
|
||||||
import { PhotoEvents } from '../../../../../typings/photo';
|
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||||
|
|
||||||
InjectDebugData([
|
const CameraApp: React.FC = () => (
|
||||||
{
|
<AppWrapper id="camera-app">
|
||||||
app: 'CAMERA',
|
<AppContent>
|
||||||
method: PhotoEvents.SEND_PHOTOS,
|
<Switch>
|
||||||
data: [
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
image: 'https://beta.iodine.gg/noDcb.jpeg',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
image: 'https://beta.iodine.gg/teUcY.jpeg',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const CameraApp = () => {
|
|
||||||
return (
|
|
||||||
<AppWrapper id="camera-app">
|
|
||||||
<AppContent>
|
|
||||||
<Switch>
|
|
||||||
<Route path="/camera" exact component={GalleryGrid} />
|
<Route path="/camera" exact component={GalleryGrid} />
|
||||||
<Route path="/camera/image" exact component={GalleryModal} />
|
<Route path="/camera/image" exact component={GalleryModal} />
|
||||||
</Switch>
|
</React.Suspense>
|
||||||
</AppContent>
|
</Switch>
|
||||||
</AppWrapper>
|
</AppContent>
|
||||||
);
|
</AppWrapper>
|
||||||
};
|
);
|
||||||
|
|
||||||
export default CameraApp;
|
export default CameraApp;
|
||||||
@@ -1,37 +1,55 @@
|
|||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Box, Button } from '@material-ui/core';
|
import { Box, Button, CircularProgress } from '@material-ui/core';
|
||||||
import useStyles from './grid.styles';
|
import useStyles from './grid.styles';
|
||||||
import { usePhotos } from '../../hooks/usePhotos';
|
|
||||||
import AddIcon from '@material-ui/icons/Add';
|
import AddIcon from '@material-ui/icons/Add';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||||
import { addQueryToLocation } from '../../../../common/utils/addQueryToLocation';
|
import { addQueryToLocation } from '../../../../common/utils/addQueryToLocation';
|
||||||
import { getLocationFromUrl } from '../../../../common/utils/getLocationFromUrl';
|
import { getLocationFromUrl } from '../../../../common/utils/getLocationFromUrl';
|
||||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
|
import { GalleryPhoto, PhotoEvents } from '../../../../../../typings/photo';
|
||||||
|
import { usePhotoActions } from '../../hooks/usePhotoActions';
|
||||||
|
import { usePhotosValue } from '../../hooks/state';
|
||||||
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export const GalleryGrid = () => {
|
export const GalleryGrid = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const query = useQueryParams();
|
const query = useQueryParams();
|
||||||
|
const { addAlert } = useSnackbar();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const photos = usePhotosValue();
|
||||||
|
const { takePhoto } = usePhotoActions();
|
||||||
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
|
||||||
const referal = query.referal ? decodeURIComponent(query.referal) : '/camera/image';
|
const referal = query.referal ? decodeURIComponent(query.referal) : '/camera/image';
|
||||||
|
|
||||||
const photos = usePhotos();
|
|
||||||
|
|
||||||
const handleCamera = () => {
|
|
||||||
Nui.send(PhotoEvents.TAKE_PHOTO, {});
|
|
||||||
};
|
|
||||||
|
|
||||||
const handlePhotoOpen = (photo) => {
|
const handlePhotoOpen = (photo) => {
|
||||||
history.push(addQueryToLocation(getLocationFromUrl(referal), 'image', photo.image));
|
history.push(addQueryToLocation(getLocationFromUrl(referal), 'image', photo.image));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleTakePhoto = () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
fetchNui<ServerPromiseResp<GalleryPhoto>>(PhotoEvents.TAKE_PHOTO).then((serverResp) => {
|
||||||
|
if (serverResp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: t('APPS_CAMERA_FAILED_TO_TAKE_PHOTO'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
takePhoto(serverResp.data);
|
||||||
|
setIsLoading(false);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
if (!photos)
|
if (!photos)
|
||||||
return (
|
return (
|
||||||
<Box display="flex" flexWrap="wrap" alignContent="flex-start" className={classes.root}>
|
<Box display="flex" flexWrap="wrap" alignContent="flex-start" className={classes.root}>
|
||||||
<Box>
|
<Box>
|
||||||
<Button onClick={handleCamera} style={{ borderRadius: 0 }} className={classes.photo}>
|
<Button onClick={takePhoto} style={{ borderRadius: 0 }} className={classes.photo}>
|
||||||
<AddIcon fontSize="large" />
|
<AddIcon fontSize="large" />
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
@@ -42,8 +60,13 @@ export const GalleryGrid = () => {
|
|||||||
<div>
|
<div>
|
||||||
<Box display="flex" flexWrap="wrap" alignContent="flex-start" className={classes.root}>
|
<Box display="flex" flexWrap="wrap" alignContent="flex-start" className={classes.root}>
|
||||||
<Box>
|
<Box>
|
||||||
<Button onClick={handleCamera} style={{ borderRadius: 0 }} className={classes.photo}>
|
<Button
|
||||||
<AddIcon fontSize="large" />
|
disabled={isLoading}
|
||||||
|
onClick={handleTakePhoto}
|
||||||
|
style={{ borderRadius: 0 }}
|
||||||
|
className={classes.photo}
|
||||||
|
>
|
||||||
|
{!isLoading ? <AddIcon fontSize="large" /> : <CircularProgress />}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
{photos.map((photo) => (
|
{photos.map((photo) => (
|
||||||
|
|||||||
@@ -4,23 +4,30 @@ import { Button, Paper } from '@material-ui/core';
|
|||||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||||
import DeleteIcon from '@material-ui/icons/Delete';
|
import DeleteIcon from '@material-ui/icons/Delete';
|
||||||
import ShareIcon from '@material-ui/icons/Share';
|
import ShareIcon from '@material-ui/icons/Share';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
|
||||||
import { ShareModal } from './ShareModal';
|
import { ShareModal } from './ShareModal';
|
||||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
import { GalleryPhoto, PhotoEvents } from '../../../../../../typings/photo';
|
||||||
|
import { usePhotoActions } from '../../hooks/usePhotoActions';
|
||||||
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
|
|
||||||
export const GalleryModal = () => {
|
export const GalleryModal = () => {
|
||||||
|
const [shareOpen, setShareOpen] = useState(null);
|
||||||
|
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const query = useQueryParams();
|
const query = useQueryParams();
|
||||||
|
const { deletePhoto } = usePhotoActions();
|
||||||
|
const { addAlert } = useSnackbar();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const referal = query.referal || '/camera';
|
const referal = query.referal || '/camera';
|
||||||
|
|
||||||
const [shareOpen, setShareOpen] = useState(null);
|
const meta: GalleryPhoto = useMemo(
|
||||||
|
() => ({ id: parseInt(query.id), image: query.image as string }),
|
||||||
const meta: ICameraPhoto = useMemo(
|
|
||||||
() => ({ id: query.id as string, image: query.image as string }),
|
|
||||||
[query],
|
[query],
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -29,10 +36,17 @@ export const GalleryModal = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDeletePhoto = () => {
|
const handleDeletePhoto = () => {
|
||||||
Nui.send(PhotoEvents.DELETE_PHOTO, {
|
fetchNui<ServerPromiseResp<GalleryPhoto>>(PhotoEvents.DELETE_PHOTO, {
|
||||||
image: meta.image,
|
image: meta.image,
|
||||||
|
}).then((serverResp) => {
|
||||||
|
if (serverResp.status !== 'ok') {
|
||||||
|
return addAlert({ message: t('APPS_CAMERA_FAILED_TO_DELETE_PHOTO'), type: 'error' });
|
||||||
|
}
|
||||||
|
|
||||||
|
deletePhoto(meta.image);
|
||||||
|
|
||||||
|
history.push(referal);
|
||||||
});
|
});
|
||||||
history.push(referal);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSharePhoto = useCallback(() => {
|
const handleSharePhoto = useCallback(() => {
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import MessageIcon from '@material-ui/icons/Message';
|
|||||||
import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
|
import { setClipboard } from '../../../../os/phone/hooks/useClipboard';
|
||||||
|
|
||||||
import useStyles from './modal.styles';
|
import useStyles from './modal.styles';
|
||||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
import { GalleryPhoto } from '../../../../../../typings/photo';
|
||||||
|
|
||||||
interface IShareModalProps {
|
interface IShareModalProps {
|
||||||
meta: ICameraPhoto;
|
meta: GalleryPhoto;
|
||||||
referal: string;
|
referal: string;
|
||||||
onClose(): void;
|
onClose(): void;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,33 @@
|
|||||||
import { atom } from 'recoil';
|
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||||
|
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||||
|
import { GalleryPhoto, PhotoEvents } from '../../../../../typings/photo';
|
||||||
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import LogDebugEvent from '../../../os/debug/LogDebugEvents';
|
||||||
|
import { isEnvBrowser } from '../../../utils/misc';
|
||||||
|
import { MockPhotoData } from '../utils/constants';
|
||||||
|
|
||||||
export const photoState = {
|
export const photoState = {
|
||||||
photos: atom({
|
photos: atom<GalleryPhoto[]>({
|
||||||
key: 'galleryPhotos',
|
key: 'galleryPhotos',
|
||||||
default: null,
|
default: selector({
|
||||||
|
key: 'defaultGalleryPhotos',
|
||||||
|
get: async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetchNui<ServerPromiseResp<GalleryPhoto[]>>(PhotoEvents.FETCH_PHOTOS);
|
||||||
|
LogDebugEvent({ action: 'PhotosFetched', data: resp.data });
|
||||||
|
return resp.data;
|
||||||
|
} catch (e) {
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
return MockPhotoData;
|
||||||
|
}
|
||||||
|
console.error(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useSetPhotos = () => useSetRecoilState(photoState.photos);
|
||||||
|
export const usePhotos = () => useRecoilState(photoState.photos);
|
||||||
|
export const usePhotosValue = () => useRecoilValue(photoState.photos);
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import { useCallback, useState } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { SetterOrUpdater, useRecoilState } from 'recoil';
|
||||||
|
import { GalleryPhoto, PhotoEvents } from '../../../../../typings/photo';
|
||||||
|
import { useNuiEvent, useNuiCallback } from 'fivem-nui-react-lib/';
|
||||||
|
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||||
|
import { photoState } from './state';
|
||||||
|
|
||||||
|
interface IUseCamera {
|
||||||
|
photos: GalleryPhoto[];
|
||||||
|
setPhotos: SetterOrUpdater<GalleryPhoto[]>;
|
||||||
|
takePhoto: () => void;
|
||||||
|
isLoading: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useCamera = (): IUseCamera => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const { addAlert } = useSnackbar();
|
||||||
|
|
||||||
|
const [photos, setPhotos] = useRecoilState<GalleryPhoto[]>(photoState.photos);
|
||||||
|
|
||||||
|
const [isUploading, setUploading] = useState(false);
|
||||||
|
|
||||||
|
const onPhotoSuccess = useCallback(
|
||||||
|
(photo) => {
|
||||||
|
setUploading(false);
|
||||||
|
if (!photo?.image) return;
|
||||||
|
setPhotos((curr) => [photo, ...curr]);
|
||||||
|
},
|
||||||
|
[setPhotos],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onPhotoError = useCallback(
|
||||||
|
(i18nKey) => {
|
||||||
|
setUploading(false);
|
||||||
|
addAlert({ type: 'error', message: t(i18nKey) });
|
||||||
|
},
|
||||||
|
[addAlert, t],
|
||||||
|
);
|
||||||
|
|
||||||
|
const [_takePhoto] = useNuiCallback<void, GalleryPhoto>(
|
||||||
|
'CAMERA',
|
||||||
|
PhotoEvents.TAKE_PHOTO,
|
||||||
|
onPhotoSuccess,
|
||||||
|
onPhotoError,
|
||||||
|
);
|
||||||
|
|
||||||
|
useNuiEvent('CAMERA', PhotoEvents.UPLOAD_PHOTO, () => setUploading(true));
|
||||||
|
|
||||||
|
const takePhoto = () => {
|
||||||
|
// Timeout at 1 minute
|
||||||
|
_takePhoto(undefined, { timeout: 60000 });
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
photos,
|
||||||
|
setPhotos,
|
||||||
|
takePhoto,
|
||||||
|
isLoading: isUploading,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { useSetPhotos } from './state';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
export const usePhotoActions = () => {
|
||||||
|
const setPhotos = useSetPhotos();
|
||||||
|
|
||||||
|
const takePhoto = useCallback(
|
||||||
|
(photo) => {
|
||||||
|
setPhotos((curPhotos) => [photo, ...curPhotos]);
|
||||||
|
},
|
||||||
|
[setPhotos],
|
||||||
|
);
|
||||||
|
|
||||||
|
const deletePhoto = useCallback(
|
||||||
|
(image: string) => {
|
||||||
|
setPhotos((curPhotos) => [...curPhotos].filter((meta) => meta.image !== image));
|
||||||
|
},
|
||||||
|
[setPhotos],
|
||||||
|
);
|
||||||
|
|
||||||
|
return { takePhoto, deletePhoto };
|
||||||
|
};
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
import { useSetRecoilState } from 'recoil';
|
|
||||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
|
||||||
import { photoState } from './state';
|
|
||||||
import { PhotoEvents } from '../../../../../typings/photo';
|
|
||||||
|
|
||||||
export const usePhotoService = () => {
|
|
||||||
const setPhotos = useSetRecoilState(photoState.photos);
|
|
||||||
useNuiEvent('CAMERA', PhotoEvents.SEND_PHOTOS, setPhotos);
|
|
||||||
};
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { useRecoilValue } from 'recoil';
|
|
||||||
import { photoState } from './state';
|
|
||||||
|
|
||||||
export interface ICameraPhoto {
|
|
||||||
id: string;
|
|
||||||
image: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const usePhotos = (): ICameraPhoto[] | null => {
|
|
||||||
return useRecoilValue<ICameraPhoto[] | null>(photoState.photos);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export const MockPhotoData = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
image: 'https://beta.iodine.gg/noDcb.jpeg',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
image: 'https://beta.iodine.gg/teUcY.jpeg',
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -3,56 +3,47 @@ import { AppWrapper } from '../../../ui/components';
|
|||||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||||
import { AppContent } from '../../../ui/components/AppContent';
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
|
||||||
import { Route } from 'react-router-dom';
|
import { Route } from 'react-router-dom';
|
||||||
|
|
||||||
import ContactsInfoPage from './views/ContactInfo';
|
import ContactsInfoPage from './views/ContactInfo';
|
||||||
import { ContactPage } from './views/ContactsPage';
|
import { ContactPage } from './views/ContactsPage';
|
||||||
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
||||||
import { ContactEvents } from '../../../../../typings/contact';
|
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||||
|
import Fab from '@material-ui/core/Fab';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
|
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||||
|
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||||
|
|
||||||
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
|
absolute: {
|
||||||
|
position: 'absolute',
|
||||||
|
right: theme.spacing(3),
|
||||||
|
bottom: theme.spacing(2),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
export const ContactsApp = () => {
|
export const ContactsApp = () => {
|
||||||
const contacts = useApp('CONTACTS');
|
const contacts = useApp('CONTACTS');
|
||||||
|
const history = useHistory();
|
||||||
|
const classes = useStyles();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContactsThemeProvider>
|
<ContactsThemeProvider>
|
||||||
<AppWrapper id="contact-app">
|
<AppWrapper id="contact-app">
|
||||||
<AppTitle app={contacts} />
|
<AppTitle app={contacts} />
|
||||||
<AppContent>
|
<AppContent>
|
||||||
<Route path="/contacts/" exact component={ContactPage} />
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
<Route path="/contacts/:id" exact component={ContactsInfoPage} />
|
<Route path="/contacts/" exact component={ContactPage} />
|
||||||
|
<Route path="/contacts/:id" exact component={ContactsInfoPage} />
|
||||||
|
</React.Suspense>
|
||||||
</AppContent>
|
</AppContent>
|
||||||
|
<Fab
|
||||||
|
color="primary"
|
||||||
|
onClick={() => history.push('/contacts/-1')}
|
||||||
|
className={classes.absolute}
|
||||||
|
>
|
||||||
|
<PersonAddIcon />
|
||||||
|
</Fab>
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
</ContactsThemeProvider>
|
</ContactsThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
InjectDebugData([
|
|
||||||
{
|
|
||||||
app: 'CONTACTS',
|
|
||||||
method: ContactEvents.SEND_CONTACTS,
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
display: 'Ruqen',
|
|
||||||
number: '555-15196',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
display: 'Taso',
|
|
||||||
number: '215-8139',
|
|
||||||
avatar: 'http://i.tasoagc.dev/i9Ig',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
display: 'Chip',
|
|
||||||
number: '111-1111',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 4,
|
|
||||||
display: 'Kidz',
|
|
||||||
number: '444-4444',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
@@ -1,22 +1,19 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ListItemText from '@material-ui/core/ListItemText';
|
import ListItemText from '@material-ui/core/ListItemText';
|
||||||
import { Button, ListItemAvatar, Avatar as MuiAvatar, List, ListItem } from '@material-ui/core';
|
import { Button, ListItemAvatar, Avatar as MuiAvatar, List, ListItem } from '@material-ui/core';
|
||||||
import { useFilteredContacts } from '../../hooks/useFilteredContacts';
|
|
||||||
import PhoneIcon from '@material-ui/icons/Phone';
|
import PhoneIcon from '@material-ui/icons/Phone';
|
||||||
import ChatIcon from '@material-ui/icons/Chat';
|
import ChatIcon from '@material-ui/icons/Chat';
|
||||||
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
import MoreVertIcon from '@material-ui/icons/MoreVert';
|
||||||
import { useContacts } from '../../hooks/useContacts';
|
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
import { SearchContacts } from './SearchContacts';
|
import { SearchContacts } from './SearchContacts';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||||
import { CallEvents } from '../../../../../../typings/call';
|
import { useFilteredContacts } from '../../hooks/state';
|
||||||
|
import { useCall } from '../../../../os/call/hooks/useCall';
|
||||||
|
|
||||||
export const ContactList = () => {
|
export const ContactList = () => {
|
||||||
const { filteredContacts } = useFilteredContacts();
|
const filteredContacts = useFilteredContacts();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { initializeCall } = useCall();
|
||||||
const { contacts } = useContacts();
|
|
||||||
|
|
||||||
const openContactInfo = (contactId: number) => {
|
const openContactInfo = (contactId: number) => {
|
||||||
history.push(`/contacts/${contactId}`);
|
history.push(`/contacts/${contactId}`);
|
||||||
@@ -28,9 +25,7 @@ export const ContactList = () => {
|
|||||||
level: 2,
|
level: 2,
|
||||||
data: true,
|
data: true,
|
||||||
});
|
});
|
||||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
initializeCall(number);
|
||||||
number,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMessage = (phoneNumber: string) => {
|
const handleMessage = (phoneNumber: string) => {
|
||||||
@@ -42,38 +37,31 @@ export const ContactList = () => {
|
|||||||
history.push(`/messages/new/${phoneNumber}`);
|
history.push(`/messages/new/${phoneNumber}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const filteredRegEx = new RegExp(filteredContacts, 'gi');
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SearchContacts />
|
<SearchContacts />
|
||||||
<List>
|
<List>
|
||||||
{contacts
|
{filteredContacts.map((contact) => (
|
||||||
.filter(
|
<ListItem key={contact.id} divider>
|
||||||
(contact) =>
|
<ListItemAvatar>
|
||||||
contact.display.match(filteredRegEx) || contact.number.match(filteredRegEx),
|
{contact.avatar ? (
|
||||||
)
|
<MuiAvatar src={contact.avatar} />
|
||||||
.map((contact) => (
|
) : (
|
||||||
<ListItem key={contact.id} divider>
|
<MuiAvatar>{contact.display.slice(0, 1).toUpperCase()}</MuiAvatar>
|
||||||
<ListItemAvatar>
|
)}
|
||||||
{contact.avatar ? (
|
</ListItemAvatar>
|
||||||
<MuiAvatar src={contact.avatar} />
|
<ListItemText primary={contact.display} secondary={contact.number} />
|
||||||
) : (
|
<Button onClick={() => startCall(contact.number)}>
|
||||||
<MuiAvatar>{contact.display.slice(0, 1).toUpperCase()}</MuiAvatar>
|
<PhoneIcon />
|
||||||
)}
|
</Button>
|
||||||
</ListItemAvatar>
|
<Button onClick={() => handleMessage(contact.number)}>
|
||||||
<ListItemText primary={contact.display} secondary={contact.number} />
|
<ChatIcon />
|
||||||
<Button onClick={() => startCall(contact.number)}>
|
</Button>
|
||||||
<PhoneIcon />
|
<Button style={{ margin: -15 }} onClick={() => openContactInfo(contact.id)}>
|
||||||
</Button>
|
<MoreVertIcon />
|
||||||
<Button onClick={() => handleMessage(contact.number)}>
|
</Button>
|
||||||
<ChatIcon />
|
</ListItem>
|
||||||
</Button>
|
))}
|
||||||
<Button style={{ margin: -15 }} onClick={() => openContactInfo(contact.id)}>
|
|
||||||
<MoreVertIcon />
|
|
||||||
</Button>
|
|
||||||
</ListItem>
|
|
||||||
))}
|
|
||||||
</List>
|
</List>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,21 +1,29 @@
|
|||||||
import React from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Box } from '@material-ui/core';
|
import { Box } from '@material-ui/core';
|
||||||
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { useFilteredContacts } from '../../hooks/useFilteredContacts';
|
|
||||||
import { SearchField } from '../../../../ui/components/SearchField';
|
import { SearchField } from '../../../../ui/components/SearchField';
|
||||||
|
import { useDebounce } from '../../../../os/phone/hooks/useDebounce';
|
||||||
|
import { useSetContactFilterInput } from '../../hooks/state';
|
||||||
|
|
||||||
export const SearchContacts = () => {
|
export const SearchContacts = () => {
|
||||||
const { setFilteredContacts, filteredContacts } = useFilteredContacts();
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const setFilterVal = useSetContactFilterInput();
|
||||||
|
const [inputVal, setInputVal] = useState('');
|
||||||
|
|
||||||
|
const debouncedVal = useDebounce<string>(inputVal, 500);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setFilterVal(debouncedVal);
|
||||||
|
}, [debouncedVal, setFilterVal]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<SearchField
|
<SearchField
|
||||||
onChange={(e) => setFilteredContacts(e.target.value)}
|
onChange={(e) => setInputVal(e.target.value)}
|
||||||
placeholder={t('APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS')}
|
placeholder={t('APPS_CONTACT_PLACEHOLDER_SEARCH_CONTACTS')}
|
||||||
value={filteredContacts}
|
value={inputVal}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,14 +1,17 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Avatar as MuiAvatar, Box, Button, Paper, TextField } from '@material-ui/core';
|
import { Avatar as MuiAvatar, Box, Button, Paper } from '@material-ui/core';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
import { useContacts } from '../../hooks/useContacts';
|
import { useContactActions } from '../../hooks/useContactActions';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||||
import { ContactEvents } from '../../../../../../typings/contact';
|
import { Contact, ContactEvents, ContactsDatabaseLimits } from '../../../../../../typings/contact';
|
||||||
|
import { TextField } from '../../../../ui/components/Input';
|
||||||
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
|
|
||||||
interface ContactInfoRouteParams {
|
interface ContactInfoRouteParams {
|
||||||
mode: string;
|
mode: string;
|
||||||
@@ -49,10 +52,11 @@ const useStyles = makeStyles({
|
|||||||
|
|
||||||
const ContactsInfoPage = () => {
|
const ContactsInfoPage = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const { getContact } = useContacts();
|
const { getContact, addContact, updateContact, deleteContact } = useContactActions();
|
||||||
|
|
||||||
|
const { addAlert } = useSnackbar();
|
||||||
|
|
||||||
const { id } = useParams<ContactInfoRouteParams>();
|
const { id } = useParams<ContactInfoRouteParams>();
|
||||||
const { addNumber, referal } = useQueryParams<ContactInfoRouteQuery>({
|
const { addNumber, referal } = useQueryParams<ContactInfoRouteQuery>({
|
||||||
@@ -68,6 +72,24 @@ const ContactsInfoPage = () => {
|
|||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const handleNumberChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
const inputVal = e.target.value;
|
||||||
|
if (inputVal.length === ContactsDatabaseLimits.number) return;
|
||||||
|
setNumber(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDisplayChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
const inputVal = e.target.value;
|
||||||
|
if (inputVal.length === ContactsDatabaseLimits.display) return;
|
||||||
|
setName(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleAvatarChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
|
||||||
|
const inputVal = e.target.value;
|
||||||
|
if (inputVal.length === ContactsDatabaseLimits.avatar) return;
|
||||||
|
setAvatar(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (addNumber) {
|
if (addNumber) {
|
||||||
setNumber(addNumber);
|
setNumber(addNumber);
|
||||||
@@ -80,12 +102,27 @@ const ContactsInfoPage = () => {
|
|||||||
data: contact,
|
data: contact,
|
||||||
level: 2,
|
level: 2,
|
||||||
});
|
});
|
||||||
Nui.send(ContactEvents.ADD_CONTACT, {
|
fetchNui<ServerPromiseResp<Contact>>(ContactEvents.ADD_CONTACT, {
|
||||||
display: name,
|
display: name,
|
||||||
number,
|
number,
|
||||||
avatar,
|
avatar,
|
||||||
|
}).then((serverResp) => {
|
||||||
|
if (serverResp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: t('APPS_CONTACT_ADD_FAILED'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sanity checks maybe?
|
||||||
|
|
||||||
|
addContact(serverResp.data);
|
||||||
|
addAlert({
|
||||||
|
message: t('APPS_CONTACT_ADD_SUCCESS'),
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
|
history.replace(referal);
|
||||||
});
|
});
|
||||||
history.replace(referal);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleContactSave = () => {
|
const handleContactSave = () => {
|
||||||
@@ -94,13 +131,33 @@ const ContactsInfoPage = () => {
|
|||||||
data: contact,
|
data: contact,
|
||||||
level: 2,
|
level: 2,
|
||||||
});
|
});
|
||||||
Nui.send(ContactEvents.UPDATE_CONTACT, {
|
fetchNui<ServerPromiseResp>(ContactEvents.UPDATE_CONTACT, {
|
||||||
id: contact.id,
|
id: contact.id,
|
||||||
display: name,
|
display: name,
|
||||||
number,
|
number,
|
||||||
avatar,
|
avatar,
|
||||||
|
}).then((resp) => {
|
||||||
|
if (resp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: t('APPS_CONTACT_UPDATE_FAILED'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
updateContact({
|
||||||
|
id: contact.id,
|
||||||
|
display: name,
|
||||||
|
number,
|
||||||
|
avatar,
|
||||||
|
});
|
||||||
|
|
||||||
|
addAlert({
|
||||||
|
message: t('APPS_CONTACT_UPDATE_SUCCESS'),
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
|
|
||||||
|
history.goBack();
|
||||||
});
|
});
|
||||||
history.goBack();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleContactDelete = () => {
|
const handleContactDelete = () => {
|
||||||
@@ -109,10 +166,20 @@ const ContactsInfoPage = () => {
|
|||||||
data: contact,
|
data: contact,
|
||||||
level: 2,
|
level: 2,
|
||||||
});
|
});
|
||||||
Nui.send(ContactEvents.DELETE_CONTACT, {
|
fetchNui<ServerPromiseResp>(ContactEvents.DELETE_CONTACT, { id: contact.id }).then((resp) => {
|
||||||
id: contact.id,
|
if (resp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: t('APPS_CONTACT_DELETE_FAILED'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
history.goBack();
|
||||||
|
deleteContact(contact.id);
|
||||||
|
addAlert({
|
||||||
|
message: t('APPS_CONTACT_DELETE_SUCCESS'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
history.goBack();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -124,9 +191,10 @@ const ContactsInfoPage = () => {
|
|||||||
<MuiAvatar className={classes.avatar} src={avatar} />
|
<MuiAvatar className={classes.avatar} src={avatar} />
|
||||||
<TextField
|
<TextField
|
||||||
autoFocus
|
autoFocus
|
||||||
|
error={name.length === ContactsDatabaseLimits.display}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
value={name}
|
value={name}
|
||||||
onChange={(e) => setName(e.target.value)}
|
onChange={handleDisplayChange}
|
||||||
label={t('APPS_CONTACT_FORM_NAME')}
|
label={t('APPS_CONTACT_FORM_NAME')}
|
||||||
fullWidth
|
fullWidth
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -135,8 +203,9 @@ const ContactsInfoPage = () => {
|
|||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
|
error={number.length === ContactsDatabaseLimits.number}
|
||||||
value={number}
|
value={number}
|
||||||
onChange={(e) => setNumber(e.target.value)}
|
onChange={handleNumberChange}
|
||||||
label={t('APPS_CONTACT_FORM_NUMBER')}
|
label={t('APPS_CONTACT_FORM_NUMBER')}
|
||||||
fullWidth
|
fullWidth
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@@ -144,11 +213,12 @@ const ContactsInfoPage = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
|
error={avatar.length === ContactsDatabaseLimits.avatar}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
label={t('APPS_CONTACT_FORM_AVATAR')}
|
label={t('APPS_CONTACT_FORM_AVATAR')}
|
||||||
fullWidth
|
fullWidth
|
||||||
value={avatar}
|
value={avatar}
|
||||||
onChange={(e) => setAvatar(e.target.value)}
|
onChange={handleAvatarChange}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
className: classes.inputProps,
|
className: classes.inputProps,
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,37 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Fab from '@material-ui/core/Fab';
|
|
||||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
|
||||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
|
||||||
import { ContactList } from '../List/ContactList';
|
import { ContactList } from '../List/ContactList';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => ({
|
|
||||||
absolute: {
|
|
||||||
position: 'absolute',
|
|
||||||
bottom: theme.spacing(2),
|
|
||||||
right: theme.spacing(2),
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
color: '#fff',
|
|
||||||
fontSize: 30,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const ContactPage = () => {
|
export const ContactPage = () => {
|
||||||
const history = useHistory();
|
|
||||||
|
|
||||||
const classes = useStyles();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div style={{ paddingBottom: 60 }}>
|
||||||
<ContactList />
|
<ContactList />
|
||||||
<Fab
|
</div>
|
||||||
color="primary"
|
|
||||||
onClick={() => history.push('/contacts/-1')}
|
|
||||||
className={classes.absolute}
|
|
||||||
>
|
|
||||||
<PersonAddIcon />
|
|
||||||
</Fab>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,24 +1,57 @@
|
|||||||
import { atom } from 'recoil';
|
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||||
|
import { Contact, ContactEvents } from '../../../../../typings/contact';
|
||||||
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||||
|
import { isEnvBrowser } from '../../../utils/misc';
|
||||||
|
import LogDebugEvent from '../../../os/debug/LogDebugEvents';
|
||||||
|
import { BrowserContactsState } from '../utils/constants';
|
||||||
|
|
||||||
export const contactsState = {
|
export const contactsState = {
|
||||||
contacts: atom({
|
contacts: atom<Contact[]>({
|
||||||
key: 'contactsList',
|
key: 'contactsList',
|
||||||
default: [],
|
default: selector({
|
||||||
|
key: 'contactsListDefault',
|
||||||
|
get: async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetchNui<ServerPromiseResp<Contact[]>>(ContactEvents.GET_CONTACTS);
|
||||||
|
LogDebugEvent({ action: 'ContactsFetched', data: resp.data });
|
||||||
|
return resp.data;
|
||||||
|
} catch (e) {
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
return BrowserContactsState;
|
||||||
|
}
|
||||||
|
console.error(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
showModal: atom({
|
filterInput: atom<string>({
|
||||||
key: 'showModal',
|
key: 'filterInput',
|
||||||
default: false,
|
|
||||||
}),
|
|
||||||
filterContacts: atom({
|
|
||||||
key: 'filterContacts',
|
|
||||||
default: '',
|
default: '',
|
||||||
}),
|
}),
|
||||||
showContactsModal: atom({
|
filteredContacts: selector({
|
||||||
key: 'showContactModal',
|
key: 'filteredContacts',
|
||||||
default: false,
|
get: ({ get }) => {
|
||||||
}),
|
const filterInputVal: string = get(contactsState.filterInput);
|
||||||
contactDetail: atom({
|
const contacts: Contact[] = get(contactsState.contacts);
|
||||||
key: 'contactDetail',
|
|
||||||
default: null,
|
if (!filterInputVal) return contacts;
|
||||||
|
|
||||||
|
const regExp = new RegExp(filterInputVal, 'gi');
|
||||||
|
|
||||||
|
return contacts.filter(
|
||||||
|
(contact) => contact.display.match(regExp) || contact.number.match(regExp),
|
||||||
|
);
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useSetContacts = () => useSetRecoilState(contactsState.contacts);
|
||||||
|
export const useContacts = () => useRecoilState(contactsState.contacts);
|
||||||
|
export const useContactsValue = () => useRecoilValue(contactsState.contacts);
|
||||||
|
|
||||||
|
export const useFilteredContacts = () => useRecoilValue(contactsState.filteredContacts);
|
||||||
|
|
||||||
|
export const useContactFilterInput = () => useRecoilState(contactsState.filterInput);
|
||||||
|
export const useSetContactFilterInput = () => useSetRecoilState(contactsState.filterInput);
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { useContacts } from './state';
|
||||||
|
|
||||||
|
import { Contact } from '../../../../../typings/contact';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
interface UseContactsValue {
|
||||||
|
getDisplayByNumber: (number: string) => string;
|
||||||
|
getContactByNumber: (number: string) => Contact | null;
|
||||||
|
getContact: (id: number) => Contact | null;
|
||||||
|
getPictureByNumber: (number: string) => string | null;
|
||||||
|
deleteContact: (id: number) => void;
|
||||||
|
addContact: (contact: Contact) => void;
|
||||||
|
updateContact: (contact: Contact) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useContactActions = (): UseContactsValue => {
|
||||||
|
const [contacts, setContacts] = useContacts();
|
||||||
|
|
||||||
|
const getDisplayByNumber = useCallback(
|
||||||
|
(number: string) => {
|
||||||
|
const found = contacts.find((contact) => contact.number === number);
|
||||||
|
return found ? found.display : number;
|
||||||
|
},
|
||||||
|
[contacts],
|
||||||
|
);
|
||||||
|
|
||||||
|
const getPictureByNumber = useCallback(
|
||||||
|
(number: string) => {
|
||||||
|
const found = contacts.find((contact) => contact.number === number);
|
||||||
|
return found ? found.avatar : null;
|
||||||
|
},
|
||||||
|
[contacts],
|
||||||
|
);
|
||||||
|
|
||||||
|
const getContactByNumber = useCallback(
|
||||||
|
(number: string): Contact | null => {
|
||||||
|
for (const contact of contacts) {
|
||||||
|
if (contact.number === number) return contact;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
[contacts],
|
||||||
|
);
|
||||||
|
|
||||||
|
const getContact = useCallback(
|
||||||
|
(id: number): Contact | null => {
|
||||||
|
for (const contact of contacts) {
|
||||||
|
if (contact.id === id) return contact;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
[contacts],
|
||||||
|
);
|
||||||
|
|
||||||
|
const deleteContact = useCallback(
|
||||||
|
(id: number): void => {
|
||||||
|
setContacts((curContacts) => [...curContacts].filter((contact) => contact.id !== id));
|
||||||
|
},
|
||||||
|
[setContacts],
|
||||||
|
);
|
||||||
|
|
||||||
|
const addContact = useCallback(
|
||||||
|
(contact: Contact) => {
|
||||||
|
setContacts((curContacts) => [...curContacts, contact]);
|
||||||
|
},
|
||||||
|
[setContacts],
|
||||||
|
);
|
||||||
|
|
||||||
|
const updateContact = useCallback(
|
||||||
|
(updatedContact: Contact) => {
|
||||||
|
setContacts((curContacts) => {
|
||||||
|
const targetContactIndex = curContacts.findIndex(
|
||||||
|
(contact) => contact.id === updatedContact.id,
|
||||||
|
);
|
||||||
|
const newContactsArray = [...curContacts];
|
||||||
|
newContactsArray[targetContactIndex] = updatedContact;
|
||||||
|
return newContactsArray;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[setContacts],
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
getDisplayByNumber,
|
||||||
|
getContact,
|
||||||
|
getContactByNumber,
|
||||||
|
getPictureByNumber,
|
||||||
|
deleteContact,
|
||||||
|
updateContact,
|
||||||
|
addContact,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import { useRecoilValue } from 'recoil';
|
|
||||||
import { contactsState } from './state';
|
|
||||||
|
|
||||||
import { Contact } from '../../../../../typings/contact';
|
|
||||||
import { useCallback } from 'react';
|
|
||||||
|
|
||||||
interface IUseContacts {
|
|
||||||
contacts: Contact[];
|
|
||||||
getDisplayByNumber: (number: string) => string;
|
|
||||||
getContactByNumber: (number: string) => Contact | null;
|
|
||||||
getContact: (id: number) => Contact | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useContacts = (): IUseContacts => {
|
|
||||||
const contacts = useRecoilValue(contactsState.contacts);
|
|
||||||
|
|
||||||
const getDisplayByNumber = useCallback(
|
|
||||||
(number: string) => {
|
|
||||||
const found = contacts.find((contact) => contact.number === number);
|
|
||||||
return found ? found.display : number;
|
|
||||||
},
|
|
||||||
[contacts],
|
|
||||||
);
|
|
||||||
|
|
||||||
const getContactByNumber = useCallback(
|
|
||||||
(number: string): Contact | null => {
|
|
||||||
for (const contact of contacts) {
|
|
||||||
if (contact.number === number) return contact;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
[contacts],
|
|
||||||
);
|
|
||||||
|
|
||||||
const getContact = useCallback(
|
|
||||||
(id: number): Contact | null => {
|
|
||||||
for (const contact of contacts) {
|
|
||||||
if (contact.id === id) return contact;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
[contacts],
|
|
||||||
);
|
|
||||||
|
|
||||||
return { contacts, getDisplayByNumber, getContact, getContactByNumber };
|
|
||||||
};
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
|
||||||
import { useSetRecoilState } from 'recoil';
|
|
||||||
import { contactsState } from './state';
|
|
||||||
import { useContacts } from './useContacts';
|
|
||||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import { ContactEvents } from '../../../../../typings/contact';
|
|
||||||
|
|
||||||
export const useContactsService = () => {
|
|
||||||
const setContacts = useSetRecoilState(contactsState.contacts);
|
|
||||||
const { addAlert } = useSnackbar();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const handleAddAlert = ({ message, type }: IAlert) => {
|
|
||||||
addAlert({
|
|
||||||
message: t(`APPS_${message}`),
|
|
||||||
type,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
useNuiEvent('CONTACTS', ContactEvents.SEND_CONTACTS, setContacts);
|
|
||||||
useNuiEvent('CONTACTS', ContactEvents.SEND_ALERT, handleAddAlert);
|
|
||||||
return useContacts();
|
|
||||||
};
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { useRecoilState } from 'recoil';
|
|
||||||
import { contactsState } from './state';
|
|
||||||
|
|
||||||
interface FilterdContactsProps {
|
|
||||||
filteredContacts: string;
|
|
||||||
setFilteredContacts: (contact: any) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useFilteredContacts = (): FilterdContactsProps => {
|
|
||||||
const [filteredContacts, setFilteredContacts] = useRecoilState(contactsState.filterContacts);
|
|
||||||
return { filteredContacts, setFilteredContacts };
|
|
||||||
};
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { useRecoilState } from 'recoil';
|
|
||||||
import { contactsState } from './state';
|
|
||||||
|
|
||||||
interface ModalProps {
|
|
||||||
showModal: boolean;
|
|
||||||
setShowModal: (show: boolean) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useModal = (): ModalProps => {
|
|
||||||
const [showModal, setShowModal] = useRecoilState(contactsState.showModal);
|
|
||||||
return { showModal, setShowModal };
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
export const BrowserContactsState = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
display: 'Ruqen',
|
||||||
|
number: '555-15196',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
display: 'Taso',
|
||||||
|
number: '215-8139',
|
||||||
|
avatar: 'http://i.tasoagc.dev/i9Ig',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
display: 'Chip',
|
||||||
|
number: '603-275-8373',
|
||||||
|
avatar: 'http://i.tasoagc.dev/2QYV',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
display: 'Kidz',
|
||||||
|
number: '444-4444',
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -7,15 +7,17 @@ import { useApp } from '../../../os/apps/hooks/useApps';
|
|||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route } from 'react-router-dom';
|
||||||
import DialPage from './views/DialPage';
|
import DialPage from './views/DialPage';
|
||||||
import DialerNavBar from './DialerNavBar';
|
import DialerNavBar from './DialerNavBar';
|
||||||
import { useDialHistory } from '../hooks/useDialHistory';
|
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
|
||||||
import { ContactList } from '../../contacts/components/List/ContactList';
|
import { ContactList } from '../../contacts/components/List/ContactList';
|
||||||
import { DialerThemeProvider } from '../providers/DialerThemeProvider';
|
import { DialerThemeProvider } from '../providers/DialerThemeProvider';
|
||||||
import { CallEvents } from '../../../../../typings/call';
|
import { Box, CircularProgress } from '@material-ui/core';
|
||||||
|
|
||||||
|
const LoadingSpinner: React.FC = () => (
|
||||||
|
<Box>
|
||||||
|
<CircularProgress />
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
export const DialerApp = () => {
|
export const DialerApp = () => {
|
||||||
const history = useDialHistory();
|
|
||||||
|
|
||||||
const dialer = useApp('DIALER');
|
const dialer = useApp('DIALER');
|
||||||
return (
|
return (
|
||||||
<DialerThemeProvider>
|
<DialerThemeProvider>
|
||||||
@@ -27,7 +29,9 @@ export const DialerApp = () => {
|
|||||||
<DialPage />
|
<DialPage />
|
||||||
</Route>
|
</Route>
|
||||||
<Route exact path="/phone">
|
<Route exact path="/phone">
|
||||||
<DialerHistory calls={history} />
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
|
<DialerHistory />
|
||||||
|
</React.Suspense>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/phone/contacts" component={ContactList} />
|
<Route path="/phone/contacts" component={ContactList} />
|
||||||
</Switch>
|
</Switch>
|
||||||
@@ -37,22 +41,3 @@ export const DialerApp = () => {
|
|||||||
</DialerThemeProvider>
|
</DialerThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
InjectDebugData([
|
|
||||||
{
|
|
||||||
app: 'DIALER',
|
|
||||||
method: CallEvents.SET_CALL_HISTORY,
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
transmitter: '636-6496',
|
|
||||||
start: 1615946292,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
transmitter: '777-7777',
|
|
||||||
start: 1615946292,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
import React, { useContext } from 'react';
|
import React, { useContext } from 'react';
|
||||||
import { Box, IconButton, InputBase, Paper } from '@material-ui/core';
|
import { Box, IconButton, Paper } from '@material-ui/core';
|
||||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||||
import PhoneIcon from '@material-ui/icons/Phone';
|
import PhoneIcon from '@material-ui/icons/Phone';
|
||||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||||
import { DialInputCtx, IDialInputCtx } from '../context/InputContext';
|
import { DialInputCtx, IDialInputCtx } from '../context/InputContext';
|
||||||
import Nui from '../../../os/nui-events/utils/Nui';
|
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { CallEvents } from '../../../../../typings/call';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { InputBase } from '../../../ui/components/Input';
|
||||||
|
import { useCall } from '../../../os/call/hooks/useCall';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => ({
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -32,13 +32,12 @@ export const DialerInput = () => {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { initializeCall } = useCall();
|
||||||
|
|
||||||
const { inputVal, set } = useContext<IDialInputCtx>(DialInputCtx);
|
const { inputVal, set } = useContext<IDialInputCtx>(DialInputCtx);
|
||||||
|
|
||||||
const handleCall = (number: string) => {
|
const handleCall = (number: string) => {
|
||||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
initializeCall(number);
|
||||||
number,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleNewContact = (number: string) => {
|
const handleNewContact = (number: string) => {
|
||||||
@@ -52,7 +51,6 @@ export const DialerInput = () => {
|
|||||||
className={classes.input}
|
className={classes.input}
|
||||||
value={inputVal}
|
value={inputVal}
|
||||||
onChange={(e) => set(e.target.value)}
|
onChange={(e) => set(e.target.value)}
|
||||||
type="number"
|
|
||||||
/>
|
/>
|
||||||
<IconButton color="primary" className={classes.iconBtn} disabled={inputVal <= ''}>
|
<IconButton color="primary" className={classes.iconBtn} disabled={inputVal <= ''}>
|
||||||
<PhoneIcon fontSize="large" onClick={() => handleCall(inputVal)} />
|
<PhoneIcon fontSize="large" onClick={() => handleCall(inputVal)} />
|
||||||
|
|||||||
@@ -5,15 +5,16 @@ import PhoneIcon from '@material-ui/icons/Phone';
|
|||||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||||
import { List } from '../../../../ui/components/List';
|
import { List } from '../../../../ui/components/List';
|
||||||
import { ListItem } from '../../../../ui/components/ListItem';
|
import { ListItem } from '../../../../ui/components/ListItem';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import { useContactActions } from '../../../contacts/hooks/useContactActions';
|
||||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
import { CallHistoryItem } from '../../../../../../typings/call';
|
||||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
|
||||||
import { CallEvents, ICall } from '../../../../../../typings/call';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
|
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
import { useMyPhoneNumber } from '../../../../os/simcard/hooks/useMyPhoneNumber';
|
||||||
|
import { useDialHistory } from '../../hooks/useDialHistory';
|
||||||
|
import { useCall } from '../../../../os/call/hooks/useCall';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => ({
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
callForward: {
|
callForward: {
|
||||||
@@ -24,20 +25,17 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const DialerHistory = ({ calls }) => {
|
export const DialerHistory: React.FC = () => {
|
||||||
const { number: myNumber } = useSimcard();
|
const myNumber = useMyPhoneNumber();
|
||||||
const { getDisplayByNumber } = useContacts();
|
const { getDisplayByNumber } = useContactActions();
|
||||||
|
const { initializeCall } = useCall();
|
||||||
|
const calls = useDialHistory();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const handleCall = (phoneNumber) => {
|
const handleCall = (phoneNumber) => {
|
||||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
initializeCall(phoneNumber);
|
||||||
number: phoneNumber,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!calls?.length) {
|
if (!calls?.length) {
|
||||||
@@ -55,7 +53,7 @@ export const DialerHistory = ({ calls }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<List disablePadding>
|
<List disablePadding>
|
||||||
{calls.map((call: ICall) =>
|
{calls.map((call: CallHistoryItem) =>
|
||||||
call.transmitter === myNumber ? (
|
call.transmitter === myNumber ? (
|
||||||
<ListItem key={call.id} divider>
|
<ListItem key={call.id} divider>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
@@ -66,15 +64,15 @@ export const DialerHistory = ({ calls }) => {
|
|||||||
primary={getDisplayByNumber(call.receiver)}
|
primary={getDisplayByNumber(call.receiver)}
|
||||||
secondary={
|
secondary={
|
||||||
// TODO: Locale changes are pending #168 merge
|
// TODO: Locale changes are pending #168 merge
|
||||||
dayjs().to(dayjs.unix(call.start))
|
dayjs().to(dayjs.unix(parseInt(call.start)))
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconButton onClick={() => handleCall(call.receiver)}>{<PhoneIcon />}</IconButton>
|
<IconButton onClick={() => handleCall(call.receiver)}>{<PhoneIcon />}</IconButton>
|
||||||
|
|
||||||
{getDisplayByNumber(call.transmitter) === call.transmitter && (
|
{getDisplayByNumber(call.receiver) === call.receiver && (
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
history.push(`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`)
|
history.push(`/contacts/-1?addNumber=${call.receiver}&referal=/phone/contacts`)
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<PersonAddIcon />
|
<PersonAddIcon />
|
||||||
@@ -91,7 +89,7 @@ export const DialerHistory = ({ calls }) => {
|
|||||||
primary={getDisplayByNumber(call.transmitter)}
|
primary={getDisplayByNumber(call.transmitter)}
|
||||||
secondary={
|
secondary={
|
||||||
// TODO: Locale changes are pending #168 merge
|
// TODO: Locale changes are pending #168 merge
|
||||||
dayjs().to(dayjs.unix(call.start))
|
dayjs().to(dayjs.unix(parseInt(call.start)))
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<IconButton onClick={() => handleCall(call.transmitter)}>
|
<IconButton onClick={() => handleCall(call.transmitter)}>
|
||||||
|
|||||||
@@ -1,8 +1,29 @@
|
|||||||
import { atom } from 'recoil';
|
import { atom, selector } from 'recoil';
|
||||||
|
import { CallEvents, CallHistoryItem } from '../../../../../typings/call';
|
||||||
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||||
|
import LogDebugEvent from '../../../os/debug/LogDebugEvents';
|
||||||
|
import { isEnvBrowser } from '../../../utils/misc';
|
||||||
|
import { MockHistoryData } from '../utils/constants';
|
||||||
|
|
||||||
export const dialState = {
|
export const dialState = {
|
||||||
history: atom({
|
history: atom<CallHistoryItem[]>({
|
||||||
key: 'dialHistory',
|
key: 'dialHistory',
|
||||||
default: [],
|
default: selector({
|
||||||
|
key: 'dialHistoryDefault',
|
||||||
|
get: async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetchNui<ServerPromiseResp<CallHistoryItem[]>>(CallEvents.FETCH_CALLS);
|
||||||
|
LogDebugEvent({ action: 'ContactsFetched', data: resp.data });
|
||||||
|
return resp.data;
|
||||||
|
} catch (e) {
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
return MockHistoryData;
|
||||||
|
}
|
||||||
|
console.error(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import { ICall } from '../../../../../typings/call';
|
|
||||||
import { dialState } from './state';
|
import { dialState } from './state';
|
||||||
|
|
||||||
export const useDialHistory = () => {
|
export const useDialHistory = () => useRecoilValue(dialState.history);
|
||||||
return useRecoilValue<ICall[]>(dialState.history);
|
|
||||||
};
|
|
||||||
@@ -1,9 +1,18 @@
|
|||||||
import { useSetRecoilState } from 'recoil';
|
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
|
||||||
import { dialState } from './state';
|
|
||||||
import { CallEvents } from '../../../../../typings/call';
|
import { CallEvents } from '../../../../../typings/call';
|
||||||
|
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export const useDialService = () => {
|
export const useDialService = () => {
|
||||||
const setHistory = useSetRecoilState(dialState.history);
|
const { addAlert } = useSnackbar();
|
||||||
useNuiEvent('DIALER', CallEvents.SET_CALL_HISTORY, setHistory);
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const handleAddAlert = ({ message, type }: IAlert) => {
|
||||||
|
addAlert({
|
||||||
|
message: t(`APPS_${message}`),
|
||||||
|
type,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useNuiEvent('DIALER', CallEvents.SEND_ALERT, handleAddAlert);
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { CallHistoryItem } from '../../../../../typings/call';
|
||||||
|
|
||||||
|
export const MockHistoryData: CallHistoryItem[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
identifier: 'ca839e8c-ef9d-40bd-b6a3-d531ee58149f',
|
||||||
|
transmitter: '704-1549',
|
||||||
|
receiver: '704-1549',
|
||||||
|
is_accepted: true,
|
||||||
|
start: '1615939174',
|
||||||
|
end: null,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
identifier: 'b8080a50-ad30-4ee9-84cb-00688e2bf167',
|
||||||
|
transmitter: '704-1549',
|
||||||
|
receiver: '704-1549',
|
||||||
|
is_accepted: false,
|
||||||
|
start: '1615939850',
|
||||||
|
end: null,
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||||
import { useSetRecoilState } from 'recoil';
|
import { useSetRecoilState } from 'recoil';
|
||||||
import { exampleState } from './state';
|
import { exampleState } from './state';
|
||||||
import { useExample } from './useExample';
|
import { useExample } from './useExample';
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { AppWrapper } from '../../../ui/components/AppWrapper';
|
import { AppWrapper } from '../../../ui/components';
|
||||||
import { AppContent } from '../../../ui/components/AppContent';
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
import { MarketplaceTitle } from './MarketplaceTitle';
|
import { MarketplaceListContainer } from './MarketplaceList/MarketplaceListContainer';
|
||||||
import { MarketplaceListContainer } from './SelloutList/MarketplaceListContainer';
|
|
||||||
import { NavigationBar } from './navigation/NavigationBar';
|
import { NavigationBar } from './navigation/NavigationBar';
|
||||||
import { Switch, Route } from 'react-router-dom';
|
import { Switch, Route } from 'react-router-dom';
|
||||||
import { ListingFormContainer } from './form/ListingFormContainer';
|
import { ListingFormContainer } from './form/ListingFormContainer';
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
|
||||||
import { MarketplaceThemeProvider } from '../providers/MarketplaceThemeProvider';
|
import { MarketplaceThemeProvider } from '../providers/MarketplaceThemeProvider';
|
||||||
import { MarketplaceEvents } from '../../../../../typings/marketplace';
|
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||||
|
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||||
|
|
||||||
export const MarketplaceApp = () => {
|
export const MarketplaceApp = () => {
|
||||||
|
const marketplaceApp = useApp('MARKETPLACE');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MarketplaceThemeProvider>
|
<MarketplaceThemeProvider>
|
||||||
<AppWrapper id="sellout-app">
|
<AppWrapper id="marketplace-app">
|
||||||
<MarketplaceTitle />
|
<AppTitle app={marketplaceApp} />
|
||||||
<AppContent>
|
<AppContent>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route path="/marketplace" exact component={MarketplaceListContainer} />
|
<Route path="/marketplace" exact component={MarketplaceListContainer} />
|
||||||
@@ -26,29 +27,3 @@ export const MarketplaceApp = () => {
|
|||||||
</MarketplaceThemeProvider>
|
</MarketplaceThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
InjectDebugData([
|
|
||||||
{
|
|
||||||
app: 'SELLOUT',
|
|
||||||
method: MarketplaceEvents.SEND_LISTING,
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
name: 'Some guy',
|
|
||||||
number: '111-1134',
|
|
||||||
title: 'eeeeeeeeeeeeeeeeeeeeeeeee',
|
|
||||||
description:
|
|
||||||
'skldfsdEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE',
|
|
||||||
url: 'https://beta.iodine.gg/706Y3.jpeg',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
name: 'Some other dude',
|
|
||||||
number: '666-6666',
|
|
||||||
title: 'Material',
|
|
||||||
description: 'Selling my wife',
|
|
||||||
url: '',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
+41
-13
@@ -2,15 +2,17 @@ import { Box, Tooltip, Button } from '@material-ui/core';
|
|||||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
|
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
|
||||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
|
||||||
import DeleteIcon from '@material-ui/icons/Delete';
|
import DeleteIcon from '@material-ui/icons/Delete';
|
||||||
import ReportIcon from '@material-ui/icons/Report';
|
import ReportIcon from '@material-ui/icons/Report';
|
||||||
import ChatIcon from '@material-ui/icons/Chat';
|
import ChatIcon from '@material-ui/icons/Chat';
|
||||||
import PhoneIcon from '@material-ui/icons/Phone';
|
import PhoneIcon from '@material-ui/icons/Phone';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
import { CallEvents } from '../../../../../../typings/call';
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
|
import { useMyPhoneNumber } from '../../../../os/simcard/hooks/useMyPhoneNumber';
|
||||||
|
import { useCall } from '../../../../os/call/hooks/useCall';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => ({
|
const useStyles = makeStyles((theme: Theme) => ({
|
||||||
icon: {
|
icon: {
|
||||||
@@ -18,26 +20,52 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const ListingActions = ({ listing }: { listing: MarketplaceListing }) => {
|
export const ListingActions: React.FC<MarketplaceListing> = ({ children, ...listing }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { number: myNumber } = useSimcard();
|
const myNumber = useMyPhoneNumber();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { initializeCall } = useCall();
|
||||||
|
const { addAlert } = useSnackbar();
|
||||||
|
|
||||||
const handleDeleteListing = () => {
|
const handleDeleteListing = () => {
|
||||||
Nui.send(MarketplaceEvents.DELETE_LISTING, {
|
fetchNui<ServerPromiseResp>(MarketplaceEvents.DELETE_LISTING, {
|
||||||
id: listing.id,
|
id: listing.id,
|
||||||
|
}).then((resp) => {
|
||||||
|
if (resp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: t('APPS_MARKETPLACE_DELETE_LISTING_FAILED'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addAlert({
|
||||||
|
message: t('APPS_MARKETPLACE_DELETE_LISTING_SUCCESS'),
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReportListing = () => {
|
const handleReportListing = () => {
|
||||||
Nui.send(MarketplaceEvents.REPORT_LISTING, listing);
|
fetchNui<ServerPromiseResp>(MarketplaceEvents.REPORT_LISTING, {
|
||||||
|
listingId: listing.id,
|
||||||
|
}).then((resp) => {
|
||||||
|
if (resp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: t('APPS_MARKETPLACE_REPORT_LISTING_FAILED'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addAlert({
|
||||||
|
message: t('APPS_MARKETPLACE_REPORT_LISTING_SUCCESS'),
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCall = () => {
|
const handleCall = () => {
|
||||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
initializeCall(listing.number);
|
||||||
number: listing.number,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMessage = () => {
|
const handleMessage = () => {
|
||||||
@@ -45,9 +73,9 @@ export const ListingActions = ({ listing }: { listing: MarketplaceListing }) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flex justifyContent="space-between" alignItems="center">
|
<Box justifyContent="space-between" alignItems="center">
|
||||||
<div style={{ float: 'left' }}>
|
<div style={{ float: 'left' }}>
|
||||||
{listing.number !== myNumber ? (
|
{listing.number !== myNumber && (
|
||||||
<>
|
<>
|
||||||
<Tooltip title={t('GENERIC_MESSAGE')}>
|
<Tooltip title={t('GENERIC_MESSAGE')}>
|
||||||
<Button onClick={handleMessage}>
|
<Button onClick={handleMessage}>
|
||||||
@@ -60,7 +88,7 @@ export const ListingActions = ({ listing }: { listing: MarketplaceListing }) =>
|
|||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</>
|
</>
|
||||||
) : null}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{ float: 'right' }}>
|
<div style={{ float: 'right' }}>
|
||||||
+2
-2
@@ -41,7 +41,7 @@ const useStyles = makeStyles((theme) => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const MarketplaceItem = (listing: MarketplaceListing) => {
|
export const MarketplaceItem: React.FC<MarketplaceListing> = ({ children, ...listing }) => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -73,7 +73,7 @@ export const MarketplaceItem = (listing: MarketplaceListing) => {
|
|||||||
<Typography variant="body1" className={classes.listingContent}>
|
<Typography variant="body1" className={classes.listingContent}>
|
||||||
{listing.description}
|
{listing.description}
|
||||||
</Typography>
|
</Typography>
|
||||||
<ListingActions listing={listing} />
|
<ListingActions {...listing} />
|
||||||
</Paper>
|
</Paper>
|
||||||
</div>
|
</div>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
+3
-3
@@ -1,10 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { List } from '../../../../ui/components/List';
|
import { List } from '../../../../ui/components/List';
|
||||||
import { useListing } from '../../hooks/useListing';
|
import { useListingValue } from '../../hooks/state';
|
||||||
import { MarketplaceItem } from './MarketplaceItem';
|
import { MarketplaceItem } from './MarketplaceItem';
|
||||||
|
|
||||||
export const MarketplaceList = () => {
|
export const MarketplaceList: React.FC = () => {
|
||||||
const listings = useListing();
|
const listings = useListingValue();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<List>
|
<List>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { MarketplaceList } from './MarketplaceList';
|
||||||
|
import { LoadingSpinner } from '../../../../ui/components/LoadingSpinner';
|
||||||
|
|
||||||
|
export const MarketplaceListContainer: React.FC = () => {
|
||||||
|
return (
|
||||||
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
|
<MarketplaceList />
|
||||||
|
</React.Suspense>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import Paper from '@material-ui/core/Paper';
|
|
||||||
import { makeStyles } from '@material-ui/core';
|
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
||||||
import { faAd } from '@fortawesome/free-solid-svg-icons';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
|
||||||
root: {
|
|
||||||
height: '60px',
|
|
||||||
width: '100%',
|
|
||||||
display: 'flex',
|
|
||||||
flexFlow: 'row nowrap',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
background: theme.palette.background.default,
|
|
||||||
},
|
|
||||||
icon: {
|
|
||||||
color: theme.palette.primary.main,
|
|
||||||
fontSize: 40,
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
export const MarketplaceTitle = () => {
|
|
||||||
const classes = useStyles();
|
|
||||||
return (
|
|
||||||
<Paper className={classes.root} square variant="outlined" elevation={24}>
|
|
||||||
<FontAwesomeIcon icon={faAd} className={classes.icon} />
|
|
||||||
</Paper>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { MarketplaceList } from './MarketplaceList';
|
|
||||||
|
|
||||||
export const MarketplaceListContainer = () => {
|
|
||||||
return <MarketplaceList />;
|
|
||||||
};
|
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState, useCallback } from 'react';
|
||||||
import { makeStyles, Button, TextField, Typography } from '@material-ui/core';
|
import { makeStyles, Button, Box } from '@material-ui/core';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import { MarketplaceEvents, MarketplaceListing } from '../../../../../../typings/marketplace';
|
||||||
import { MarketplaceEvents } from '../../../../../../typings/marketplace';
|
|
||||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useHistory } from 'react-router';
|
import ImageIcon from '@material-ui/icons/Image';
|
||||||
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
|
import qs from 'qs';
|
||||||
|
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||||
|
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
|
||||||
|
import { TextField } from '../../../../ui/components/Input';
|
||||||
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -35,6 +41,8 @@ export const ListingForm = () => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { addAlert } = useSnackbar();
|
const { addAlert } = useSnackbar();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
const { pathname, search } = useLocation();
|
||||||
|
const query = useQueryParams();
|
||||||
|
|
||||||
const [title, setTitle] = useState('');
|
const [title, setTitle] = useState('');
|
||||||
const [url, setUrl] = useState('');
|
const [url, setUrl] = useState('');
|
||||||
@@ -42,12 +50,24 @@ export const ListingForm = () => {
|
|||||||
|
|
||||||
const addListing = () => {
|
const addListing = () => {
|
||||||
if (title !== '' && description !== '') {
|
if (title !== '' && description !== '') {
|
||||||
Nui.send(MarketplaceEvents.ADD_LISTING, {
|
fetchNui<ServerPromiseResp<MarketplaceListing[]>>(MarketplaceEvents.ADD_LISTING, {
|
||||||
title,
|
title,
|
||||||
url,
|
|
||||||
description,
|
description,
|
||||||
|
url,
|
||||||
|
}).then((resp) => {
|
||||||
|
if (resp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: t('APPS_MARKETPLACE_CREATE_LISTING_FAILED'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addAlert({
|
||||||
|
message: t('APPS_MARKETPLACE_CREATE_LISTING_SUCCESS'),
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
|
history.push('/marketplace');
|
||||||
});
|
});
|
||||||
history.push('/marketplace');
|
|
||||||
} else {
|
} else {
|
||||||
addAlert({
|
addAlert({
|
||||||
message: t('APPS_MARKETPLACE_REQUIRED_FIELDS'),
|
message: t('APPS_MARKETPLACE_REQUIRED_FIELDS'),
|
||||||
@@ -56,6 +76,26 @@ export const ListingForm = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*const handleChooseImage = () => {
|
||||||
|
history.push(`/camera?${qs.stringify({
|
||||||
|
referal: encodeURIComponent(pathname + search),
|
||||||
|
})}`)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
const handleChooseImage = useCallback(() => {
|
||||||
|
history.push(
|
||||||
|
`/camera?${qs.stringify({
|
||||||
|
referal: encodeURIComponent(pathname + search),
|
||||||
|
})}`,
|
||||||
|
);
|
||||||
|
}, [history, pathname, search]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!query?.image) return;
|
||||||
|
setUrl(query?.image);
|
||||||
|
history.replace(deleteQueryFromLocation({ pathname, search }, 'image'));
|
||||||
|
}, [query?.image, history, pathname, search]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<h1>New Listing</h1>
|
<h1>New Listing</h1>
|
||||||
@@ -75,10 +115,19 @@ export const ListingForm = () => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Box display="flex" alignItems="center" paddingLeft={5}>
|
||||||
|
<div>
|
||||||
|
<ImageIcon />
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Button onClick={handleChooseImage}>Choose a image</Button>
|
||||||
|
</div>
|
||||||
|
</Box>
|
||||||
<TextField
|
<TextField
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
placeholder={t('APPS_MARKETPLACE_FORM_IMAGE')}
|
placeholder={t('APPS_MARKETPLACE_FORM_IMAGE')}
|
||||||
onChange={(e) => setUrl(e.target.value)}
|
value={url}
|
||||||
|
onChange={(e) => setUrl(e.currentTarget.value)}
|
||||||
inputProps={{ className: classes.textFieldInput }}
|
inputProps={{ className: classes.textFieldInput }}
|
||||||
style={{ width: '80%' }}
|
style={{ width: '80%' }}
|
||||||
size="medium"
|
size="medium"
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ import React, { useState } from 'react';
|
|||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { AddCircle, Home } from '@material-ui/icons/';
|
||||||
import { faHome } from '@fortawesome/free-solid-svg-icons';
|
|
||||||
import AddCircleIcon from '@material-ui/icons/AddCircle';
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -28,12 +26,8 @@ export const NavigationBar = () => {
|
|||||||
showLabels
|
showLabels
|
||||||
className={classes.root}
|
className={classes.root}
|
||||||
>
|
>
|
||||||
<BottomNavigationAction
|
<BottomNavigationAction component={Link} icon={<Home />} to="/marketplace" />
|
||||||
component={Link}
|
<BottomNavigationAction component={Link} icon={<AddCircle />} to="/marketplace/new" />
|
||||||
icon={<FontAwesomeIcon icon={faHome} />}
|
|
||||||
to="/marketplace"
|
|
||||||
/>
|
|
||||||
<BottomNavigationAction component={Link} icon={<AddCircleIcon />} to="/marketplace/new" />
|
|
||||||
</BottomNavigation>
|
</BottomNavigation>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -1,8 +1,53 @@
|
|||||||
import { atom } from 'recoil';
|
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||||
|
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||||
|
import { MarketplaceEvents, MarketplaceListing } from '../../../../../typings/marketplace';
|
||||||
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import { isEnvBrowser } from '../../../utils/misc';
|
||||||
|
|
||||||
export const selloutState = {
|
const defaultData: MarketplaceListing[] = [
|
||||||
listing: atom({
|
{
|
||||||
key: 'listing',
|
id: 1,
|
||||||
default: [],
|
name: 'Some guy',
|
||||||
|
number: '111-1134',
|
||||||
|
username: 'Taso',
|
||||||
|
title: 'eeeeeeeeeeeeeeeeeeeeeeeee',
|
||||||
|
description:
|
||||||
|
'skldfsdEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE',
|
||||||
|
url: 'https://i.file.glass/706Y3.jpeg',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: 'Some other dude',
|
||||||
|
number: '666-6666',
|
||||||
|
username: 'Taso',
|
||||||
|
title: 'Material',
|
||||||
|
description: 'Selling my wife',
|
||||||
|
url: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const listingState = atom<MarketplaceListing[]>({
|
||||||
|
key: 'listings',
|
||||||
|
default: selector({
|
||||||
|
key: 'defaultListings',
|
||||||
|
get: async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetchNui<ServerPromiseResp<MarketplaceListing[]>>(
|
||||||
|
MarketplaceEvents.FETCH_LISTING,
|
||||||
|
);
|
||||||
|
|
||||||
|
return resp.data;
|
||||||
|
} catch (e) {
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
return defaultData;
|
||||||
|
}
|
||||||
|
console.error(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
};
|
});
|
||||||
|
|
||||||
|
export const useListingValue = () => useRecoilValue(listingState);
|
||||||
|
export const useSetListings = () => useSetRecoilState(listingState);
|
||||||
|
export const useListings = () => useRecoilState(listingState);
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import { useRecoilValue } from 'recoil';
|
|
||||||
import { MarketplaceListing } from '../../../../../typings/marketplace';
|
|
||||||
import { selloutState } from './state';
|
|
||||||
|
|
||||||
export const useListing = () => {
|
|
||||||
return useRecoilValue<MarketplaceListing[]>(selloutState.listing);
|
|
||||||
};
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { useCallback } from 'react';
|
||||||
|
import { listingState, useSetListings } from './state';
|
||||||
|
import { MarketplaceListing } from '../../../../../typings/marketplace';
|
||||||
|
import { useRecoilValueLoadable } from 'recoil';
|
||||||
|
|
||||||
|
interface MarketplaceActionValues {
|
||||||
|
deleteListing: (id: number) => void;
|
||||||
|
addListing: (listing: MarketplaceListing) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useMarketplaceActions = (): MarketplaceActionValues => {
|
||||||
|
const { state: valueLoading, contents } = useRecoilValueLoadable(listingState);
|
||||||
|
const setListings = useSetListings();
|
||||||
|
|
||||||
|
const deleteListing = useCallback(
|
||||||
|
(id: number) => {
|
||||||
|
// Make sure our atom is actually loaded before we attempt a dispatch
|
||||||
|
if (valueLoading !== 'hasValue') return;
|
||||||
|
// Tts possible for the init fetch to fail and empty array is passed. In that case
|
||||||
|
// block dispatch
|
||||||
|
if (!contents.length) return;
|
||||||
|
|
||||||
|
setListings((curListings) => [...curListings].filter((listing) => listing.id !== id));
|
||||||
|
},
|
||||||
|
[setListings, valueLoading, contents],
|
||||||
|
);
|
||||||
|
|
||||||
|
const addListing = useCallback(
|
||||||
|
(listing: MarketplaceListing) => {
|
||||||
|
// Make sure our atom is actually loaded before we attempt a dispatch
|
||||||
|
if (valueLoading !== 'hasValue') return;
|
||||||
|
setListings((curListings) => [...curListings, listing]);
|
||||||
|
},
|
||||||
|
[setListings, valueLoading],
|
||||||
|
);
|
||||||
|
|
||||||
|
return { deleteListing, addListing };
|
||||||
|
};
|
||||||
@@ -1,24 +1,38 @@
|
|||||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
import { useNuiEvent } from 'fivem-nui-react-lib';
|
||||||
import { selloutState } from './state';
|
import {
|
||||||
import { useListing } from './useListing';
|
MarketplaceBroadcastAddDTO,
|
||||||
import { useSetRecoilState } from 'recoil';
|
MarketplaceDeleteDTO,
|
||||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
MarketplaceEvents,
|
||||||
import { useTranslation } from 'react-i18next';
|
} from '../../../../../typings/marketplace';
|
||||||
import { MarketplaceEvents } from '../../../../../typings/marketplace';
|
import { useMarketplaceActions } from './useMarketplaceActions';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
export const useMarketplaceService = () => {
|
export const useMarketplaceService = () => {
|
||||||
const setSellout = useSetRecoilState(selloutState.listing);
|
const { addListing, deleteListing } = useMarketplaceActions();
|
||||||
const { addAlert } = useSnackbar();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const handleAddAlert = ({ message, type }: IAlert) => {
|
const addListingHandler = useCallback(
|
||||||
addAlert({
|
(resp: MarketplaceBroadcastAddDTO) => {
|
||||||
message: t(`APPS_${message}`),
|
addListing(resp.listing);
|
||||||
type,
|
},
|
||||||
});
|
[addListing],
|
||||||
};
|
);
|
||||||
|
|
||||||
useNuiEvent('SELLOUT', MarketplaceEvents.SEND_ALERT, handleAddAlert);
|
const deleteListingHandler = useCallback(
|
||||||
useNuiEvent('SELLOUT', MarketplaceEvents.SEND_LISTING, setSellout);
|
(listing: MarketplaceDeleteDTO) => {
|
||||||
return useListing();
|
deleteListing(listing.id);
|
||||||
|
},
|
||||||
|
[deleteListing],
|
||||||
|
);
|
||||||
|
|
||||||
|
useNuiEvent<MarketplaceBroadcastAddDTO>(
|
||||||
|
'MARKETPLACE',
|
||||||
|
MarketplaceEvents.BROADCAST_ADD,
|
||||||
|
addListingHandler,
|
||||||
|
);
|
||||||
|
|
||||||
|
useNuiEvent<MarketplaceDeleteDTO>(
|
||||||
|
'MARKETPLACE',
|
||||||
|
MarketplaceEvents.BROADCAST_DELETE,
|
||||||
|
deleteListingHandler,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import { common, red } from '@material-ui/core/colors';
|
import { common, red } from '@material-ui/core/colors';
|
||||||
|
|
||||||
export const SELLOUT_APP_PRIMARY_COLOR = red[500];
|
export const MARKETPLACE_APP_PRIMARY_COLOR = red[500];
|
||||||
export const SELLOUT_APP_ICON_COLOR = common.white;
|
export const MARKETPLACE_APP_ICON_COLOR = common.white;
|
||||||
export const SELLOUT_APP_TEXT_COLOR = common.black;
|
export const MARKETPLACE_APP_TEXT_COLOR = common.black;
|
||||||
|
|
||||||
const theme = {
|
const theme = {
|
||||||
palette: {
|
palette: {
|
||||||
primary: {
|
primary: {
|
||||||
main: SELLOUT_APP_PRIMARY_COLOR,
|
main: MARKETPLACE_APP_PRIMARY_COLOR,
|
||||||
dark: red[700],
|
dark: red[700],
|
||||||
light: red[200],
|
light: red[200],
|
||||||
contrastText: SELLOUT_APP_TEXT_COLOR,
|
contrastText: MARKETPLACE_APP_TEXT_COLOR,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
|
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
|
||||||
|
|
||||||
import selloutTheme from '../marketplace.theme';
|
import marketplaceTheme from '../marketplace.theme';
|
||||||
|
|
||||||
export const MarketplaceThemeProvider = createAppThemeProvider(selloutTheme);
|
export const MarketplaceThemeProvider = createAppThemeProvider(marketplaceTheme);
|
||||||
@@ -15,8 +15,6 @@ const useStyles = makeStyles({
|
|||||||
export function MatchBottomNavigation({ activePage, handleChange }) {
|
export function MatchBottomNavigation({ activePage, handleChange }) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
||||||
console.log(activePage);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BottomNavigation value={activePage} onChange={handleChange} className={classes.root}>
|
<BottomNavigation value={activePage} onChange={handleChange} className={classes.root}>
|
||||||
<BottomNavigationAction component={Link} to="/match" icon={<HomeIcon />} />
|
<BottomNavigationAction component={Link} to="/match" icon={<HomeIcon />} />
|
||||||
|
|||||||
@@ -1,29 +1,17 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { Route } from 'react-router-dom';
|
|
||||||
|
|
||||||
import { AppWrapper } from '../../../ui/components';
|
import { AppWrapper } from '../../../ui/components';
|
||||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||||
import { AppContent } from '../../../ui/components/AppContent';
|
import { AppContent } from '../../../ui/components/AppContent';
|
||||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
|
||||||
import { MatchThemeProvider } from '../providers/MatchThemeProvider';
|
import { MatchThemeProvider } from '../providers/MatchThemeProvider';
|
||||||
|
|
||||||
import Nui from '../../../os/nui-events/utils/Nui';
|
|
||||||
import MatchBottomNavigation from '../components/BottomNavigation';
|
import MatchBottomNavigation from '../components/BottomNavigation';
|
||||||
import MatchPage from './views/MatchPage';
|
import MatchContainer from './MatchContainer';
|
||||||
import ProfileEditor from './views/ProfileEditor';
|
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||||
import MatchList from './views/MatchList';
|
|
||||||
import { MatchEvents } from '../../../../../typings/match';
|
|
||||||
import { useProfile } from '../hooks/useProfile';
|
|
||||||
|
|
||||||
export const MatchApp = () => {
|
export const MatchApp = () => {
|
||||||
const match = useApp('MATCH');
|
const match = useApp('MATCH');
|
||||||
const [activePage, setActivePage] = useState(0);
|
const [activePage, setActivePage] = useState(0);
|
||||||
const { noProfileExists } = useProfile();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
Nui.send(MatchEvents.INITIALIZE);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handlePageChange = (e, page) => setActivePage(page);
|
const handlePageChange = (e, page) => setActivePage(page);
|
||||||
|
|
||||||
@@ -31,128 +19,13 @@ export const MatchApp = () => {
|
|||||||
<MatchThemeProvider>
|
<MatchThemeProvider>
|
||||||
<AppWrapper id="contact-app">
|
<AppWrapper id="contact-app">
|
||||||
<AppTitle app={match} />
|
<AppTitle app={match} />
|
||||||
{noProfileExists ? (
|
<AppContent>
|
||||||
<AppContent>
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
<ProfileEditor />
|
<MatchContainer />
|
||||||
</AppContent>
|
</React.Suspense>
|
||||||
) : (
|
</AppContent>
|
||||||
<>
|
<MatchBottomNavigation activePage={activePage} handleChange={handlePageChange} />
|
||||||
<AppContent>
|
|
||||||
<Route path="/match/" exact component={MatchPage} />
|
|
||||||
<Route path="/match/matches" exact component={MatchList} />
|
|
||||||
<Route path="/match/profile" exact component={ProfileEditor} />
|
|
||||||
</AppContent>
|
|
||||||
<MatchBottomNavigation activePage={activePage} handleChange={handlePageChange} />
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</AppWrapper>
|
</AppWrapper>
|
||||||
</MatchThemeProvider>
|
</MatchThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
InjectDebugData(
|
|
||||||
[
|
|
||||||
{
|
|
||||||
app: 'MATCH',
|
|
||||||
method: MatchEvents.GET_PROFILES_SUCCESS,
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
image:
|
|
||||||
'https://cdn.vox-cdn.com/thumbor/9xCALlkm2Mc0HQk8kMr1Ui3YNbc=/0x0:5464x3070/920x613/filters:focal(2295x1098:3169x1972):format(webp)/cdn.vox-cdn.com/uploads/chorus_image/image/67031748/shutterstock_1450403549.0.jpg',
|
|
||||||
name: 'Person Alpha',
|
|
||||||
bio:
|
|
||||||
'Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.',
|
|
||||||
createdAt: 1615932985,
|
|
||||||
updatedAt: 1615932985,
|
|
||||||
lastActive: 1616004986,
|
|
||||||
job: 'Gardener',
|
|
||||||
location: 'Grapeseed',
|
|
||||||
tags: 'gardening',
|
|
||||||
phoneNumber: '987-6543',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
image:
|
|
||||||
'https://media.cntraveler.com/photos/5f8f09c3a078e9112956774d/16:9/w_1600%2Cc_limit/Chicago-GettyImages-1065188752.jpg',
|
|
||||||
name: 'Person Beta',
|
|
||||||
bio: 'l impedit quo minus id quod maxime placeat facere possimus',
|
|
||||||
createdAt: 1615846585,
|
|
||||||
updatedAt: 1615846585,
|
|
||||||
lastActive: 1615850185,
|
|
||||||
job: 'Mechanic',
|
|
||||||
location: 'Harmony',
|
|
||||||
tags: 'tinkering,robotics',
|
|
||||||
phoneNumber: '654-3219',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
image: 'https://www.langan.com/wp-content/uploads/2019/02/Boston-996x554.jpg',
|
|
||||||
name: 'Person Charlie',
|
|
||||||
bio: 'ut aut reiciendis voluptatibus',
|
|
||||||
createdAt: 1615850185,
|
|
||||||
updatedAt: 1615850185,
|
|
||||||
lastActive: 1613607385,
|
|
||||||
job: 'Lawyer',
|
|
||||||
location: 'Los Santos',
|
|
||||||
tags: 'reading,coolstuff, coffee',
|
|
||||||
phoneNumber: '123-4567',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
app: 'MATCH',
|
|
||||||
method: MatchEvents.GET_MY_PROFILE_SUCCESS,
|
|
||||||
data: {
|
|
||||||
id: 4,
|
|
||||||
image:
|
|
||||||
'https://www.middlebury.edu/institute/sites/www.middlebury.edu.institute/files/styles/1040x585/public/2018-10/Nashville-skyline.jpg?fv=mS11EKrT&itok=HNhHqYUX',
|
|
||||||
name: 'Kire Says',
|
|
||||||
bio: "Kire's cool profile that has many cool things. And others.",
|
|
||||||
createdAt: 1615932985,
|
|
||||||
updatedAt: 1615932985,
|
|
||||||
lastActive: 1616004986,
|
|
||||||
job: 'Engineer',
|
|
||||||
location: 'Boston',
|
|
||||||
tags: 'code,books',
|
|
||||||
phoneNumber: '999-9999',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
app: 'MATCH',
|
|
||||||
method: MatchEvents.GET_MATCHES_SUCCESS,
|
|
||||||
data: [
|
|
||||||
{
|
|
||||||
id: 5,
|
|
||||||
image:
|
|
||||||
'https://media.cntraveler.com/photos/5f8f09c3a078e9112956774d/16:9/w_1600%2Cc_limit/Chicago-GettyImages-1065188752.jpg',
|
|
||||||
name: 'Person Delta',
|
|
||||||
bio: 'l impedit quo minus id quod maxime placeat facere possimus',
|
|
||||||
createdAt: 1615846585,
|
|
||||||
updatedAt: 1615846585,
|
|
||||||
lastActive: 1615850185,
|
|
||||||
matchedAt: 1613607385,
|
|
||||||
job: 'Mechanic',
|
|
||||||
location: 'Harmony',
|
|
||||||
tags: 'tinkering,robotics',
|
|
||||||
phoneNumber: '654-3219',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 6,
|
|
||||||
image: 'https://www.langan.com/wp-content/uploads/2019/02/Boston-996x554.jpg',
|
|
||||||
name: 'Person Echo',
|
|
||||||
bio: 'ut aut reiciendis voluptatibus',
|
|
||||||
createdAt: 1615850185,
|
|
||||||
updatedAt: 1615850185,
|
|
||||||
lastActive: 1613607385,
|
|
||||||
job: 'Lawyer',
|
|
||||||
location: 'Los Santos',
|
|
||||||
tags: 'reading,coolstuff, coffee',
|
|
||||||
phoneNumber: '123-4567',
|
|
||||||
matchedAt: 1613607385,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
200,
|
|
||||||
);
|
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import React, { useEffect } from 'react';
|
||||||
|
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||||
|
import ProfileEditor from './views/ProfileEditor';
|
||||||
|
import { Route } from 'react-router-dom';
|
||||||
|
import MatchPage from './views/MatchPage';
|
||||||
|
import MatchList from './views/MatchList';
|
||||||
|
import { useProfile } from '../hooks/useProfile';
|
||||||
|
|
||||||
|
const MatchContainer: React.FC = () => {
|
||||||
|
const { profile, noProfileExists, setNoProfileExists } = useProfile();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!profile) {
|
||||||
|
setNoProfileExists(true);
|
||||||
|
} else {
|
||||||
|
setNoProfileExists(false);
|
||||||
|
}
|
||||||
|
}, [setNoProfileExists, profile]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
|
{noProfileExists ? (
|
||||||
|
<ProfileEditor />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Route path="/match/" exact component={MatchPage} />
|
||||||
|
<Route path="/match/matches" exact component={MatchList} />
|
||||||
|
<Route path="/match/profile" exact component={ProfileEditor} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</React.Suspense>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MatchContainer;
|
||||||
@@ -6,7 +6,6 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { FormattedProfile, FormattedMatch } from '../../../../../../typings/match';
|
import { FormattedProfile, FormattedMatch } from '../../../../../../typings/match';
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
root: {},
|
|
||||||
tags: {
|
tags: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
bottom: '40%',
|
bottom: '40%',
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
import {
|
import {
|
||||||
Profile as IProfile,
|
Profile as IProfile,
|
||||||
FormattedProfile,
|
FormattedProfile,
|
||||||
@@ -14,6 +12,10 @@ import { Card } from '@material-ui/core';
|
|||||||
import Profile from './Profile';
|
import Profile from './Profile';
|
||||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||||
import PageText from '../PageText';
|
import PageText from '../PageText';
|
||||||
|
import { fetchNui } from '../../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../../typings/common';
|
||||||
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
|
import { useSetMyProfile } from '../../hooks/state';
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
root: {
|
root: {
|
||||||
@@ -42,7 +44,9 @@ interface IProps {
|
|||||||
export function ProfileForm({ profile, showPreview }: IProps) {
|
export function ProfileForm({ profile, showPreview }: IProps) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { config } = usePhone();
|
const { ResourceConfig } = usePhone();
|
||||||
|
const { addAlert } = useSnackbar();
|
||||||
|
const setMyProfile = useSetMyProfile();
|
||||||
|
|
||||||
// note that this assumes we are defensively checking
|
// note that this assumes we are defensively checking
|
||||||
// that profile is not null in a parent above this component.
|
// that profile is not null in a parent above this component.
|
||||||
@@ -74,10 +78,24 @@ export function ProfileForm({ profile, showPreview }: IProps) {
|
|||||||
tags: update.tagList.join(','),
|
tags: update.tagList.join(','),
|
||||||
};
|
};
|
||||||
const event = profile ? MatchEvents.UPDATE_MY_PROFILE : MatchEvents.CREATE_MY_PROFILE;
|
const event = profile ? MatchEvents.UPDATE_MY_PROFILE : MatchEvents.CREATE_MY_PROFILE;
|
||||||
Nui.send(event, updatedProfile);
|
fetchNui<ServerPromiseResp<FormattedProfile>>(event, updatedProfile).then((resp) => {
|
||||||
|
if (resp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: 'APPS_MATCH_UPDATE_PROFILE_FAILED',
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setMyProfile(resp.data);
|
||||||
|
|
||||||
|
addAlert({
|
||||||
|
message: 'APPS_MATCH_UPDATE_PROFILE_SUCCEEDED',
|
||||||
|
type: 'success',
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!profile && !config.match.allowEdtiableProfileName) {
|
if (!profile /* && !ResourceConfig.match.allowEditableProfileName*/) {
|
||||||
return <PageText text={t('APPS_MATCH_PROFILE_CONFIGURATION')} />;
|
return <PageText text={t('APPS_MATCH_PROFILE_CONFIGURATION')} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,13 +119,14 @@ export function ProfileForm({ profile, showPreview }: IProps) {
|
|||||||
label={t('APPS_MATCH_EDIT_PROFILE_NAME')}
|
label={t('APPS_MATCH_EDIT_PROFILE_NAME')}
|
||||||
value={name}
|
value={name}
|
||||||
handleChange={setName}
|
handleChange={setName}
|
||||||
allowChange={config.match.allowEdtiableProfileName}
|
allowChange={ResourceConfig.match.allowEditableProfileName}
|
||||||
/>
|
/>
|
||||||
<ProfileField
|
<ProfileField
|
||||||
label={t('APPS_MATCH_EDIT_PROFILE_BIO')}
|
label={t('APPS_MATCH_EDIT_PROFILE_BIO')}
|
||||||
value={update.bio}
|
value={update.bio}
|
||||||
handleChange={setBio}
|
handleChange={setBio}
|
||||||
multiline
|
multiline
|
||||||
|
maxLength={250}
|
||||||
/>
|
/>
|
||||||
<ProfileField
|
<ProfileField
|
||||||
label={t('APPS_MATCH_EDIT_PROFILE_LOCATION')}
|
label={t('APPS_MATCH_EDIT_PROFILE_LOCATION')}
|
||||||
@@ -118,6 +137,7 @@ export function ProfileForm({ profile, showPreview }: IProps) {
|
|||||||
label={t('APPS_MATCH_EDIT_PROFILE_JOB')}
|
label={t('APPS_MATCH_EDIT_PROFILE_JOB')}
|
||||||
value={update.job}
|
value={update.job}
|
||||||
handleChange={setJob}
|
handleChange={setJob}
|
||||||
|
maxLength={50}
|
||||||
/>
|
/>
|
||||||
<ProfileField label={t('APPS_MATCH_EDIT_PROFILE_TAGS')} value={tags} handleChange={setTags} />
|
<ProfileField label={t('APPS_MATCH_EDIT_PROFILE_TAGS')} value={tags} handleChange={setTags} />
|
||||||
<UpdateButton handleClick={handleUpdate} loading={false} />
|
<UpdateButton handleClick={handleUpdate} loading={false} />
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Box, makeStyles } from '@material-ui/core';
|
import { Box, makeStyles } from '@material-ui/core';
|
||||||
|
|
||||||
import { useMatches } from '../../hooks/useMatches';
|
|
||||||
import Loader from '../Loader';
|
import Loader from '../Loader';
|
||||||
import PageText from '../PageText';
|
import PageText from '../PageText';
|
||||||
import Match from '../matches/Match';
|
import Match from '../matches/Match';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import { useMatches } from '../../hooks/useMatches';
|
||||||
import { MatchEvents } from '../../../../../../typings/match';
|
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
root: {
|
root: {
|
||||||
@@ -15,29 +13,13 @@ const useStyles = makeStyles({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const MINIMUM_LOAD_TIME = 1500;
|
|
||||||
|
|
||||||
function MatchList() {
|
function MatchList() {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { matches, error } = useMatches();
|
const { matches, error } = useMatches();
|
||||||
const [loaded, setLoaded] = useState(false);
|
|
||||||
|
|
||||||
// We make the conscious descion here to fetch matches everytime
|
|
||||||
// a user loads this page because this list is dependent on
|
|
||||||
// other player's database interactions (i.e. their likes/dislikes)
|
|
||||||
// not just the current players.
|
|
||||||
// This is less performant but means that we will always have the
|
|
||||||
// correct state when the player views this page
|
|
||||||
useEffect(() => {
|
|
||||||
Nui.send(MatchEvents.GET_MATCHES);
|
|
||||||
window.setTimeout(() => {
|
|
||||||
setLoaded(true);
|
|
||||||
}, MINIMUM_LOAD_TIME);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (error) return <PageText text={t('APPS_MATCH_MATCHES_ERROR')} />;
|
if (error) return <PageText text={t('APPS_MATCH_MATCHES_ERROR')} />;
|
||||||
if (!loaded || !matches) return <Loader />;
|
if (!matches) return <Loader />;
|
||||||
if (matches.length === 0) return <PageText text={t('APPS_MATCH_NO_MATCHES')} />;
|
if (matches.length === 0) return <PageText text={t('APPS_MATCH_NO_MATCHES')} />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useProfiles } from '../../hooks/useProfiles';
|
|||||||
import Loader from '../Loader';
|
import Loader from '../Loader';
|
||||||
import PageText from '../PageText';
|
import PageText from '../PageText';
|
||||||
import ActiveProfile from '../ActiveProfile';
|
import ActiveProfile from '../ActiveProfile';
|
||||||
|
import { useMatchActions } from '../../hooks/useMatchActions';
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
root: {
|
root: {
|
||||||
@@ -23,7 +24,8 @@ const MINIMUM_LOAD_TIME = 1250;
|
|||||||
const MatchPage = () => {
|
const MatchPage = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { profiles, error, activeProfile, setViewed } = useProfiles();
|
const { profiles, error, activeProfile } = useProfiles();
|
||||||
|
const { setViewed } = useMatchActions();
|
||||||
const [loaded, setLoaded] = useState(false);
|
const [loaded, setLoaded] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ import React, { useState } from 'react';
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { Box, FormControlLabel, Switch } from '@material-ui/core';
|
import { Box, FormControlLabel, Switch } from '@material-ui/core';
|
||||||
|
|
||||||
import { useProfile } from '../../hooks/useProfile';
|
|
||||||
import Loader from '../Loader';
|
import Loader from '../Loader';
|
||||||
import ProfileForm from '../profile/ProfileForm';
|
import ProfileForm from '../profile/ProfileForm';
|
||||||
|
import { useProfile } from '../../hooks/useProfile';
|
||||||
|
|
||||||
const useStyles = makeStyles({
|
const useStyles = makeStyles({
|
||||||
root: {
|
root: {
|
||||||
|
|||||||
@@ -1,28 +1,98 @@
|
|||||||
import { atom } from 'recoil';
|
import { atom, selector, useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
|
||||||
|
import { FormattedMatch, FormattedProfile, MatchEvents } from '../../../../../typings/match';
|
||||||
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||||
|
import LogDebugEvent from '../../../os/debug/LogDebugEvents';
|
||||||
|
import { isEnvBrowser } from '../../../utils/misc';
|
||||||
|
import { MockMatchesData, MockMyProfileData, MockProfilesData } from '../utils/constants';
|
||||||
|
|
||||||
export const matchState = {
|
export const matchState = {
|
||||||
profiles: atom({
|
profiles: atom<FormattedProfile[]>({
|
||||||
key: 'profiles',
|
key: 'profiles',
|
||||||
default: null,
|
default: selector({
|
||||||
|
key: 'matchDefaultProfiles',
|
||||||
|
get: async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetchNui<ServerPromiseResp<FormattedProfile[]>>(
|
||||||
|
MatchEvents.GET_PROFILES,
|
||||||
|
);
|
||||||
|
LogDebugEvent({ action: 'fetchProfiles', data: resp.data });
|
||||||
|
return resp.data;
|
||||||
|
} catch (e) {
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
return MockProfilesData;
|
||||||
|
}
|
||||||
|
console.error(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
errorLoadingProfiles: atom({
|
errorLoadingProfiles: atom<boolean>({
|
||||||
key: 'errorLoadingProfiles',
|
key: 'errorLoadingProfiles',
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
matches: atom({
|
matches: atom<FormattedMatch[]>({
|
||||||
key: 'matches',
|
key: 'matches',
|
||||||
default: null,
|
default: selector({
|
||||||
|
key: 'defaultMatches',
|
||||||
|
get: async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetchNui<ServerPromiseResp<FormattedMatch[]>>(MatchEvents.GET_MATCHES);
|
||||||
|
LogDebugEvent({ action: 'fetchMatches', data: resp.data });
|
||||||
|
return resp.data;
|
||||||
|
} catch (e) {
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
return MockMatchesData;
|
||||||
|
}
|
||||||
|
console.log(e);
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
errorLoadingMatches: atom({
|
errorLoadingMatches: atom<boolean>({
|
||||||
key: 'errorLoadingMatches',
|
key: 'errorLoadingMatches',
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
myProfile: atom({
|
myProfile: atom<FormattedProfile | null>({
|
||||||
key: 'myProfile',
|
key: 'myProfile',
|
||||||
default: null,
|
default: selector({
|
||||||
|
key: 'myProfileDefault',
|
||||||
|
get: async () => {
|
||||||
|
try {
|
||||||
|
const resp = await fetchNui<ServerPromiseResp<FormattedProfile>>(
|
||||||
|
MatchEvents.GET_MY_PROFILE,
|
||||||
|
);
|
||||||
|
LogDebugEvent({ action: 'fetchMyProfile', data: resp.data });
|
||||||
|
return resp.data;
|
||||||
|
} catch (e) {
|
||||||
|
if (isEnvBrowser()) {
|
||||||
|
return MockMyProfileData;
|
||||||
|
}
|
||||||
|
console.error(e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
noProfileExists: atom({
|
noProfileExists: atom<boolean>({
|
||||||
key: 'noProfileExists',
|
key: 'noProfileExists',
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useFormattedProfiles = () => useRecoilState(matchState.profiles);
|
||||||
|
export const useFormattedProfilesValue = () => useRecoilValue(matchState.profiles);
|
||||||
|
export const useSetFormattedProfiles = () => useSetRecoilState(matchState.profiles);
|
||||||
|
|
||||||
|
export const useMyProfile = () => useRecoilState(matchState.myProfile);
|
||||||
|
export const useMyProfileValue = () => useRecoilValue(matchState.myProfile);
|
||||||
|
export const useSetMyProfile = () => useSetRecoilState(matchState.myProfile);
|
||||||
|
|
||||||
|
export const useProfileExistsValue = () => useRecoilValue(matchState.noProfileExists);
|
||||||
|
export const useProfileExists = () => useRecoilState(matchState.noProfileExists);
|
||||||
|
|
||||||
|
export const useFormattedMatches = () => useRecoilState(matchState.matches);
|
||||||
|
export const useMatchesValue = () => useRecoilValue(matchState.matches);
|
||||||
|
export const useSetMatches = () => useSetRecoilState(matchState.matches);
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
import { FormattedMatch, MatchEvents } from '../../../../../typings/match';
|
||||||
|
import { fetchNui } from '../../../utils/fetchNui';
|
||||||
|
import { ServerPromiseResp } from '../../../../../typings/common';
|
||||||
|
import { useSetFormattedProfiles, useSetMatches } from './state';
|
||||||
|
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
export const useMatchActions = () => {
|
||||||
|
const setProfiles = useSetFormattedProfiles();
|
||||||
|
const setMatches = useSetMatches();
|
||||||
|
const { addAlert } = useSnackbar();
|
||||||
|
|
||||||
|
const setViewed = useCallback(
|
||||||
|
(id: number, liked: boolean) => {
|
||||||
|
setProfiles((profiles) =>
|
||||||
|
profiles.map((profile) => {
|
||||||
|
if (id === profile.id) return { ...profile, viewed: true, liked };
|
||||||
|
return profile;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
fetchNui<ServerPromiseResp<boolean>>(MatchEvents.SAVE_LIKES, [{ id, liked }]).then((resp) => {
|
||||||
|
if (resp.status !== 'ok') {
|
||||||
|
return addAlert({
|
||||||
|
message: 'APPS_MATCH_SAVE_LIKES_FAILED',
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Instead of just fetching the matches again, we might want to first format the profile to a 'Match',then to a 'FormattedMatch'
|
||||||
|
// and then just mutate the already existing state of matches?
|
||||||
|
// I guess that's for another time :P
|
||||||
|
|
||||||
|
if (resp.data) {
|
||||||
|
addAlert({
|
||||||
|
message: 'APPS_MATCH_NEW_LIKE_FOUND',
|
||||||
|
type: 'info',
|
||||||
|
});
|
||||||
|
fetchNui<ServerPromiseResp<FormattedMatch[]>>(MatchEvents.GET_MATCHES).then((resp) => {
|
||||||
|
setMatches(resp.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[setProfiles, addAlert, setMatches],
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
setViewed,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
import { useSetRecoilState } from 'recoil';
|
|
||||||
import { matchState } from './state';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
|
||||||
import dayjs from 'dayjs';
|
|
||||||
|
|
||||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
|
||||||
import { Profile, FormattedProfile, Match, MatchEvents } from '../../../../../typings/match';
|
|
||||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
|
||||||
|
|
||||||
export const useMatchService = () => {
|
|
||||||
const { addAlert } = useSnackbar();
|
|
||||||
const { t } = useTranslation();
|
|
||||||
const setNoProfileExists = useSetRecoilState(matchState.noProfileExists);
|
|
||||||
const setProfiles = useSetRecoilState(matchState.profiles);
|
|
||||||
const setProfile = useSetRecoilState(matchState.myProfile);
|
|
||||||
const setMatches = useSetRecoilState(matchState.matches);
|
|
||||||
const setErrorLoadingMatches = useSetRecoilState(matchState.errorLoadingMatches);
|
|
||||||
const setErrorLoadingProfiles = useSetRecoilState(matchState.errorLoadingProfiles);
|
|
||||||
|
|
||||||
const handleAddAlert = ({ message, type }: IAlert) => {
|
|
||||||
addAlert({
|
|
||||||
message: t(message),
|
|
||||||
type,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
function formatProfile(profile: Profile): FormattedProfile | null {
|
|
||||||
return {
|
|
||||||
...profile,
|
|
||||||
tagList: profile.tags.split(',').filter((t) => t), // remove any empty tags
|
|
||||||
lastActiveFormatted: dayjs.unix(profile.lastActive).format(t('DATE_TIME_FORMAT')),
|
|
||||||
viewed: false,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const _setProfiles = (profiles: Profile[]): void => {
|
|
||||||
setProfiles(profiles.map(formatProfile));
|
|
||||||
};
|
|
||||||
const _setProfile = (profile: Profile) => {
|
|
||||||
if (!profile) {
|
|
||||||
setNoProfileExists(true);
|
|
||||||
} else {
|
|
||||||
setNoProfileExists(false);
|
|
||||||
setProfile(formatProfile(profile));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const _handleGetProfilesFailed = (alert: IAlert): void => {
|
|
||||||
handleAddAlert(alert);
|
|
||||||
setErrorLoadingProfiles(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const _setMatches = (matches: Match[]): void => {
|
|
||||||
setMatches(
|
|
||||||
matches.map((match) => ({
|
|
||||||
...match,
|
|
||||||
tagList: match.tags.split(',').filter((t) => t), // remove any empty tags
|
|
||||||
lastActiveFormatted: dayjs.unix(match.lastActive).format(t('DATE_TIME_FORMAT')),
|
|
||||||
matchedAtFormatted: dayjs.unix(match.matchedAt).format(t('DATE_TIME_FORMAT')),
|
|
||||||
})),
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const _handleGetMatchesFailed = (alert: IAlert): void => {
|
|
||||||
handleAddAlert(alert);
|
|
||||||
setErrorLoadingMatches(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const _handleUpdateProfile = (profile: Profile) => {
|
|
||||||
_setProfile(profile);
|
|
||||||
handleAddAlert({ message: 'APPS_MATCH_UPDATE_PROFILE_SUCCEEDED', type: 'info' });
|
|
||||||
};
|
|
||||||
|
|
||||||
useNuiEvent('MATCH', MatchEvents.GET_PROFILES_SUCCESS, _setProfiles);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.GET_PROFILES_FAILED, _handleGetProfilesFailed);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.GET_MY_PROFILE_SUCCESS, _setProfile);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.GET_MY_PROFILE_FAILED, handleAddAlert);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.GET_MATCHES_SUCCESS, _setMatches);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.GET_MATCHES_FAILED, _handleGetMatchesFailed);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.SAVE_LIKES_FAILED, handleAddAlert);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.NEW_MATCH, handleAddAlert);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.UPDATE_MY_PROFILE_SUCCESS, _handleUpdateProfile);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.UPDATE_MY_PROFILE_FAILED, handleAddAlert);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.CREATE_MY_PROFILE_SUCCESS, _handleUpdateProfile);
|
|
||||||
useNuiEvent('MATCH', MatchEvents.CREATE_MY_PROFILE_FAILED, handleAddAlert);
|
|
||||||
return {};
|
|
||||||
};
|
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
|
import { matchState, useFormattedMatches } from './state';
|
||||||
import { useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import { matchState } from './state';
|
|
||||||
|
|
||||||
import { FormattedMatch } from '../../../../../typings/match';
|
import { FormattedMatch } from '../../../../../typings/match';
|
||||||
|
|
||||||
interface IUseMatches {
|
interface UseMatchProps {
|
||||||
matches: FormattedMatch[];
|
matches: FormattedMatch[];
|
||||||
|
setMatches: (matches: FormattedMatch[]) => void;
|
||||||
error: boolean;
|
error: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useMatches = (): IUseMatches => {
|
export const useMatches = (): UseMatchProps => {
|
||||||
const matches = useRecoilValue<FormattedMatch[]>(matchState.matches);
|
const [matches, setMatches] = useFormattedMatches();
|
||||||
const error = useRecoilValue(matchState.errorLoadingMatches);
|
const error = useRecoilValue(matchState.errorLoadingMatches);
|
||||||
return { matches, error };
|
|
||||||
|
return { matches, setMatches, error };
|
||||||
};
|
};
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useMyProfile, useProfileExists } from './state';
|
||||||
import { matchState } from './state';
|
|
||||||
|
|
||||||
import { FormattedProfile } from '../../../../../typings/match';
|
import { FormattedProfile } from '../../../../../typings/match';
|
||||||
|
|
||||||
interface IUseProfiles {
|
interface UseProfileProps {
|
||||||
profile: FormattedProfile;
|
profile: FormattedProfile;
|
||||||
setProfile: (profile: FormattedProfile) => void;
|
setProfile: (profile: FormattedProfile) => void;
|
||||||
noProfileExists: boolean;
|
noProfileExists: boolean;
|
||||||
|
setNoProfileExists: (exists: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useProfile = (): IUseProfiles => {
|
export const useProfile = (): UseProfileProps => {
|
||||||
const [profile, setProfile] = useRecoilState<FormattedProfile>(matchState.myProfile);
|
const [profile, setProfile] = useMyProfile();
|
||||||
const noProfileExists = useRecoilValue(matchState.noProfileExists);
|
const [noProfileExists, setNoProfileExists] = useProfileExists();
|
||||||
return { profile, setProfile, noProfileExists };
|
|
||||||
|
return { profile, setProfile, noProfileExists, setNoProfileExists };
|
||||||
};
|
};
|
||||||
@@ -1,33 +1,20 @@
|
|||||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
import { useRecoilValue } from 'recoil';
|
||||||
import { matchState } from './state';
|
import { matchState, useFormattedProfiles } from './state';
|
||||||
|
|
||||||
import { FormattedProfile, MatchEvents } from '../../../../../typings/match';
|
import { FormattedProfile } from '../../../../../typings/match';
|
||||||
import Nui from '../../../os/nui-events/utils/Nui';
|
|
||||||
|
|
||||||
interface IUseProfiles {
|
interface UseProfilesProps {
|
||||||
profiles: FormattedProfile[];
|
profiles: FormattedProfile[];
|
||||||
activeProfile: FormattedProfile | null;
|
activeProfile: FormattedProfile | null;
|
||||||
setViewed: (index: number, liked: boolean) => void;
|
|
||||||
error: boolean;
|
error: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useProfiles = (): IUseProfiles => {
|
export const useProfiles = (): UseProfilesProps => {
|
||||||
const [profiles, setProfiles] = useRecoilState(matchState.profiles);
|
const [profiles] = useFormattedProfiles();
|
||||||
const error = useRecoilValue(matchState.errorLoadingProfiles);
|
const error = useRecoilValue(matchState.errorLoadingProfiles);
|
||||||
|
|
||||||
const setViewed = (id: number, liked: boolean) => {
|
|
||||||
setProfiles((profiles) =>
|
|
||||||
profiles.map((profile) => {
|
|
||||||
if (id === profile.id) return { ...profile, viewed: true, liked };
|
|
||||||
return profile;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
Nui.send(MatchEvents.SAVE_LIKES, [{ id, liked }]);
|
|
||||||
};
|
|
||||||
|
|
||||||
const filteredProfiles = profiles ? profiles.filter((profile) => !profile.viewed) : null;
|
const filteredProfiles = profiles ? profiles.filter((profile) => !profile.viewed) : null;
|
||||||
const activeProfile = profiles ? filteredProfiles[0] : null;
|
const activeProfile = profiles ? filteredProfiles[0] : null;
|
||||||
|
|
||||||
return { profiles, activeProfile, error, setViewed };
|
return { profiles, activeProfile, error };
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { FormattedMatch, FormattedProfile } from '../../../../../typings/match';
|
||||||
|
|
||||||
|
export const MockProfilesData: FormattedProfile[] = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
identifier: '3r523242',
|
||||||
|
viewed: false,
|
||||||
|
image:
|
||||||
|
'https://cdn.vox-cdn.com/thumbor/9xCALlkm2Mc0HQk8kMr1Ui3YNbc=/0x0:5464x3070/920x613/filters:focal(2295x1098:3169x1972):format(webp)/cdn.vox-cdn.com/uploads/chorus_image/image/67031748/shutterstock_1450403549.0.jpg',
|
||||||
|
name: 'Evan You',
|
||||||
|
bio: 'Husband, father of two, independent open source developer. Creator / project lead of @vuejs, @vite_js and connoisseur of sushi.',
|
||||||
|
createdAt: 1615932985,
|
||||||
|
updatedAt: 1615932985,
|
||||||
|
lastActive: 1616004986,
|
||||||
|
job: 'Gardener',
|
||||||
|
location: 'Grapeseed',
|
||||||
|
tags: 'shit framework, vue sucks',
|
||||||
|
phoneNumber: '987-6543',
|
||||||
|
tagList: ['shitframework', 'vue sucks'],
|
||||||
|
lastActiveFormatted: '1616004986',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
identifier: '3r523242',
|
||||||
|
viewed: false,
|
||||||
|
image:
|
||||||
|
'https://media.cntraveler.com/photos/5f8f09c3a078e9112956774d/16:9/w_1600%2Cc_limit/Chicago-GettyImages-1065188752.jpg',
|
||||||
|
name: 'Person Beta',
|
||||||
|
bio: 'l impedit quo minus id quod maxime placeat facere possimus',
|
||||||
|
createdAt: 1615846585,
|
||||||
|
updatedAt: 1615846585,
|
||||||
|
lastActive: 1615850185,
|
||||||
|
job: 'Mechanic',
|
||||||
|
location: 'Harmony',
|
||||||
|
tags: 'tinkering,robotics',
|
||||||
|
phoneNumber: '654-3219',
|
||||||
|
tagList: ['tinkering', 'robotics'],
|
||||||
|
lastActiveFormatted: '12332425',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
identifier: '3r523242',
|
||||||
|
viewed: false,
|
||||||
|
image: 'https://www.langan.com/wp-content/uploads/2019/02/Boston-996x554.jpg',
|
||||||
|
name: 'Person Charlie',
|
||||||
|
bio: 'ut aut reiciendis voluptatibus',
|
||||||
|
createdAt: 1615850185,
|
||||||
|
updatedAt: 1615850185,
|
||||||
|
lastActive: 1613607385,
|
||||||
|
job: 'Lawyer',
|
||||||
|
location: 'Los Santos',
|
||||||
|
tags: 'reading,coolstuff, coffee',
|
||||||
|
phoneNumber: '123-4567',
|
||||||
|
tagList: ['reading', 'coolstuff', 'coffee'],
|
||||||
|
lastActiveFormatted: '12332425',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const MockMyProfileData: FormattedProfile = {
|
||||||
|
id: 4,
|
||||||
|
identifier: '4785656',
|
||||||
|
viewed: false,
|
||||||
|
image:
|
||||||
|
'https://www.middlebury.edu/institute/sites/www.middlebury.edu.institute/files/styles/1040x585/public/2018-10/Nashville-skyline.jpg?fv=mS11EKrT&itok=HNhHqYUX',
|
||||||
|
name: 'Kire Says',
|
||||||
|
bio: "Kire's cool profile that has many cool things. And others.",
|
||||||
|
createdAt: 1615932985,
|
||||||
|
updatedAt: 1615932985,
|
||||||
|
lastActive: 1616004986,
|
||||||
|
job: 'Engineer',
|
||||||
|
location: 'Boston',
|
||||||
|
tags: 'code,javascript',
|
||||||
|
phoneNumber: '999-9999',
|
||||||
|
tagList: ['code', 'javascript'],
|
||||||
|
lastActiveFormatted: '12332425',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const MockMatchesData: FormattedMatch[] = [
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
identifier: '4785656',
|
||||||
|
viewed: true,
|
||||||
|
image:
|
||||||
|
'https://media.cntraveler.com/photos/5f8f09c3a078e9112956774d/16:9/w_1600%2Cc_limit/Chicago-GettyImages-1065188752.jpg',
|
||||||
|
name: 'Taso',
|
||||||
|
bio: 'l impedit quo minus id quod maxime placeat facere possimus',
|
||||||
|
createdAt: 1615846585,
|
||||||
|
updatedAt: 1615846585,
|
||||||
|
lastActive: 1615850185,
|
||||||
|
job: 'Mechanic',
|
||||||
|
location: 'Harmony',
|
||||||
|
tags: 'tinkering,robotics',
|
||||||
|
tagList: ['tinkering', 'robotics'],
|
||||||
|
lastActiveFormatted: '525343252',
|
||||||
|
matchedAtFormatted: '3452355',
|
||||||
|
phoneNumber: '654-3219',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
identifier: '4785656',
|
||||||
|
viewed: true,
|
||||||
|
image: 'https://www.langan.com/wp-content/uploads/2019/02/Boston-996x554.jpg',
|
||||||
|
name: 'Chip',
|
||||||
|
bio: 'ut aut reiciendis voluptatibus',
|
||||||
|
createdAt: 1615850185,
|
||||||
|
updatedAt: 1615850185,
|
||||||
|
lastActive: 1613607385,
|
||||||
|
job: 'Lawyer',
|
||||||
|
location: 'Los Santos',
|
||||||
|
tags: 'reading,coolstuff, coffee',
|
||||||
|
tagList: ['reading', 'coolstuff', 'coffee'],
|
||||||
|
phoneNumber: '123-4567',
|
||||||
|
lastActiveFormatted: '525343252',
|
||||||
|
matchedAtFormatted: '3452355',
|
||||||
|
},
|
||||||
|
];
|
||||||
@@ -9,38 +9,42 @@ import { Route, Switch, useHistory } from 'react-router-dom';
|
|||||||
import { MessageModal } from './modal/MessageModal';
|
import { MessageModal } from './modal/MessageModal';
|
||||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||||
import NewMessageGroupButton from './form/NewMessageGroupButton';
|
import NewMessageGroupButton from './form/NewMessageGroupButton';
|
||||||
import Nui from '../../../os/nui-events/utils/Nui';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
import { MessagesThemeProvider } from '../providers/MessagesThemeProvider';
|
import { MessagesThemeProvider } from '../providers/MessagesThemeProvider';
|
||||||
import { MessageEvents } from '../../../../../typings/messages';
|
import { MessageEvents } from '../../../../../typings/messages';
|
||||||
|
import { LoadingSpinner } from '../../../ui/components/LoadingSpinner';
|
||||||
|
|
||||||
export const MessagesApp = () => {
|
export const MessagesApp = () => {
|
||||||
|
const Nui = useNuiRequest();
|
||||||
const messages = useApp('MESSAGES');
|
const messages = useApp('MESSAGES');
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Nui.send(MessageEvents.FETCH_MESSAGE_GROUPS);
|
Nui.send(MessageEvents.FETCH_MESSAGE_GROUPS);
|
||||||
}, []);
|
}, [Nui]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MessagesThemeProvider>
|
<MessagesThemeProvider>
|
||||||
<AppWrapper id="messages-app">
|
<AppWrapper id="messages-app">
|
||||||
<AppTitle app={messages} />
|
<AppTitle app={messages} />
|
||||||
<AppContent>
|
<AppContent>
|
||||||
<Switch>
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
<Route path="/messages/conversations/:groupId">
|
<Switch>
|
||||||
<div>
|
<Route path="/messages/conversations/:groupId">
|
||||||
<MessageModal />
|
<div>
|
||||||
</div>
|
<MessageModal />
|
||||||
</Route>
|
</div>
|
||||||
<Route exact path="/messages">
|
</Route>
|
||||||
<MessagesList />
|
<Route exact path="/messages">
|
||||||
</Route>
|
<MessagesList />
|
||||||
</Switch>
|
</Route>
|
||||||
<Switch>
|
</Switch>
|
||||||
<Route exact path={['/messages/new/:phoneNumber', '/messages/new']}>
|
<Switch>
|
||||||
<MessageGroupModal />
|
<Route exact path={['/messages/new/:phoneNumber', '/messages/new']}>
|
||||||
</Route>
|
<MessageGroupModal />
|
||||||
</Switch>
|
</Route>
|
||||||
|
</Switch>
|
||||||
|
</React.Suspense>
|
||||||
</AppContent>
|
</AppContent>
|
||||||
<Route exact path="/messages">
|
<Route exact path="/messages">
|
||||||
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
|
<NewMessageGroupButton onClick={() => history.push('/messages/new')} />
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import React, { FormEvent, useState } from 'react';
|
import React, { FormEvent, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Paper, Box, makeStyles, TextField, Button } from '@material-ui/core';
|
import { Paper, Box, makeStyles, Button } from '@material-ui/core';
|
||||||
import SendIcon from '@material-ui/icons/Send';
|
import SendIcon from '@material-ui/icons/Send';
|
||||||
import ImageIcon from '@material-ui/icons/Image';
|
import ImageIcon from '@material-ui/icons/Image';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
import { MessageEvents } from '../../../../../../typings/messages';
|
import { MessageEvents } from '../../../../../../typings/messages';
|
||||||
|
import { TextField } from '../../../../ui/components/Input';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
onAddImageClick(): void;
|
onAddImageClick(): void;
|
||||||
@@ -17,6 +18,7 @@ const useStyles = makeStyles({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
||||||
|
const Nui = useNuiRequest();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [message, setMessage] = useState('');
|
const [message, setMessage] = useState('');
|
||||||
@@ -42,6 +44,8 @@ const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
|||||||
<Box display="flex">
|
<Box display="flex">
|
||||||
<Box pl={1} flexGrow={1}>
|
<Box pl={1} flexGrow={1}>
|
||||||
<TextField
|
<TextField
|
||||||
|
multiline
|
||||||
|
aria-multiline="true"
|
||||||
fullWidth
|
fullWidth
|
||||||
inputProps={{ style: { fontSize: '1.3em' } }}
|
inputProps={{ style: { fontSize: '1.3em' } }}
|
||||||
value={message}
|
value={message}
|
||||||
|
|||||||
@@ -1,22 +1,26 @@
|
|||||||
import React, { useCallback, useEffect, useState } from 'react';
|
import React, { useCallback, useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Box, Button, TextField } from '@material-ui/core';
|
import { Box, Button } from '@material-ui/core';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { Autocomplete } from '@material-ui/lab';
|
import { Autocomplete } from '@material-ui/lab';
|
||||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
import { useContactActions } from '../../../contacts/hooks/useContactActions';
|
||||||
import { Contact } from '../../../../../../typings/contact';
|
import { Contact } from '../../../../../../typings/contact';
|
||||||
import { MessageEvents } from '../../../../../../typings/messages';
|
import { MessageEvents } from '../../../../../../typings/messages';
|
||||||
import { PHONE_NUMBER_REGEX } from '../../../../../../typings/phone';
|
import { PHONE_NUMBER_REGEX } from '../../../../../../typings/phone';
|
||||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||||
|
import { TextField } from '../../../../ui/components/Input';
|
||||||
|
import { useContactsValue } from '../../../contacts/hooks/state';
|
||||||
|
|
||||||
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||||
|
const Nui = useNuiRequest();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { addAlert } = useSnackbar();
|
const { addAlert } = useSnackbar();
|
||||||
const [participants, setParticipants] = useState([]);
|
const [participants, setParticipants] = useState([]);
|
||||||
const [label, setLabel] = useState('');
|
const [label, setLabel] = useState('');
|
||||||
const { getContactByNumber, contacts } = useContacts();
|
const { getContactByNumber } = useContactActions();
|
||||||
|
const contacts = useContactsValue();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (phoneNumber) {
|
if (phoneNumber) {
|
||||||
@@ -42,7 +46,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
|||||||
setParticipants([]);
|
setParticipants([]);
|
||||||
history.push('/messages');
|
history.push('/messages');
|
||||||
}
|
}
|
||||||
}, [history, label, participants, isGroupChat]);
|
}, [history, label, participants, isGroupChat, Nui]);
|
||||||
|
|
||||||
const onAutocompleteChange = (_e, value: any) => {
|
const onAutocompleteChange = (_e, value: any) => {
|
||||||
const lastIdx = value.length - 1;
|
const lastIdx = value.length - 1;
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Box, List } from '@material-ui/core';
|
import { Box, List } from '@material-ui/core';
|
||||||
import { MessageEvents, MessageGroup } from '../../../../../../typings/messages';
|
import { MessageGroup } from '../../../../../../typings/messages';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
|
||||||
import useMessages from '../../hooks/useMessages';
|
import useMessages from '../../hooks/useMessages';
|
||||||
import MessageGroupItem from './MessageGroupItem';
|
import MessageGroupItem from './MessageGroupItem';
|
||||||
import useStyles from './list.styles';
|
import useStyles from './list.styles';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { goToConversation } from '../../utils/goToConversation';
|
|
||||||
import { SearchField } from '../../../../ui/components/SearchField';
|
import { SearchField } from '../../../../ui/components/SearchField';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
@@ -17,6 +15,7 @@ const MessagesList = (): any => {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
messageGroups,
|
messageGroups,
|
||||||
|
goToConversation,
|
||||||
createMessageGroupResult,
|
createMessageGroupResult,
|
||||||
clearMessageGroupResult,
|
clearMessageGroupResult,
|
||||||
getMessageGroupById,
|
getMessageGroupById,
|
||||||
@@ -41,7 +40,7 @@ const MessagesList = (): any => {
|
|||||||
const findGroup = getMessageGroupById(createMessageGroupResult.groupId);
|
const findGroup = getMessageGroupById(createMessageGroupResult.groupId);
|
||||||
clearMessageGroupResult();
|
clearMessageGroupResult();
|
||||||
if (findGroup) {
|
if (findGroup) {
|
||||||
goToConversation(findGroup, history);
|
goToConversation(findGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
@@ -51,12 +50,13 @@ const MessagesList = (): any => {
|
|||||||
history,
|
history,
|
||||||
setActiveMessageGroup,
|
setActiveMessageGroup,
|
||||||
getMessageGroupById,
|
getMessageGroupById,
|
||||||
|
goToConversation,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (!messageGroups) return null;
|
if (!messageGroups) return null;
|
||||||
|
|
||||||
const handleClick = (messageGroup: MessageGroup) => () => {
|
const handleClick = (messageGroup: MessageGroup) => () => {
|
||||||
goToConversation(messageGroup, history);
|
goToConversation(messageGroup);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
|||||||
import useStyles from './modal.styles';
|
import useStyles from './modal.styles';
|
||||||
import NewMessageGroupForm from '../form/NewMessageGroupForm';
|
import NewMessageGroupForm from '../form/NewMessageGroupForm';
|
||||||
import { useHistory, useParams } from 'react-router-dom';
|
import { useHistory, useParams } from 'react-router-dom';
|
||||||
|
import { LoadingSpinner } from '../../../../ui/components/LoadingSpinner';
|
||||||
|
|
||||||
const MessageGroupModal = () => {
|
const MessageGroupModal = () => {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
@@ -16,10 +17,12 @@ const MessageGroupModal = () => {
|
|||||||
return (
|
return (
|
||||||
<Slide direction="left" in>
|
<Slide direction="left" in>
|
||||||
<Paper className={classes.modalRoot}>
|
<Paper className={classes.modalRoot}>
|
||||||
<Button onClick={handleClose}>
|
<React.Suspense fallback={<LoadingSpinner />}>
|
||||||
<ArrowBackIcon fontSize="large" />
|
<Button onClick={handleClose}>
|
||||||
</Button>
|
<ArrowBackIcon fontSize="large" />
|
||||||
<NewMessageGroupForm phoneNumber={params.phoneNumber} />
|
</Button>
|
||||||
|
<NewMessageGroupForm phoneNumber={params.phoneNumber} />
|
||||||
|
</React.Suspense>
|
||||||
</Paper>
|
</Paper>
|
||||||
</Slide>
|
</Slide>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
import Modal from '../../../../ui/components/Modal';
|
import Modal from '../../../../ui/components/Modal';
|
||||||
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
|
import PhotoLibraryIcon from '@material-ui/icons/PhotoLibrary';
|
||||||
import { Box, Typography, TextField, Button } from '@material-ui/core';
|
import { Box, Typography, Button } from '@material-ui/core';
|
||||||
import FileCopyIcon from '@material-ui/icons/FileCopy';
|
|
||||||
import useStyles from './modal.styles';
|
|
||||||
import { useHistory, useLocation } from 'react-router-dom';
|
import { useHistory, useLocation } from 'react-router-dom';
|
||||||
import { ContextMenu } from '../../../../ui/components/ContextMenu';
|
import { ContextMenu } from '../../../../ui/components/ContextMenu';
|
||||||
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
|
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
|
||||||
@@ -20,12 +18,9 @@ interface IProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IProps) => {
|
export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IProps) => {
|
||||||
const classes = useStyles();
|
const Nui = useNuiRequest();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { pathname, search } = useLocation();
|
const { pathname, search } = useLocation();
|
||||||
|
|
||||||
const [message, setMessage] = useState('');
|
|
||||||
const [pasteVisible, setPasteVisible] = useState(false);
|
|
||||||
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
|
const [queryParamImagePreview, setQueryParamImagePreview] = useState(null);
|
||||||
|
|
||||||
const removeQueryParamImage = useCallback(() => {
|
const removeQueryParamImage = useCallback(() => {
|
||||||
@@ -41,7 +36,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
|
|||||||
});
|
});
|
||||||
onClose();
|
onClose();
|
||||||
},
|
},
|
||||||
[messageGroupId, onClose],
|
[messageGroupId, onClose, Nui],
|
||||||
);
|
);
|
||||||
|
|
||||||
const sendFromQueryParam = useCallback(
|
const sendFromQueryParam = useCallback(
|
||||||
@@ -55,21 +50,10 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!image) return;
|
if (!image) return;
|
||||||
setQueryParamImagePreview(image);
|
setQueryParamImagePreview(image);
|
||||||
}, [image, sendFromQueryParam]);
|
}, [image]);
|
||||||
|
|
||||||
const sendFromClipboard = (event) => {
|
|
||||||
if (event.key === 'Enter') {
|
|
||||||
sendImageMessage(message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const menuOptions = useMemo(
|
const menuOptions = useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
|
||||||
label: 'Paste from clipboard',
|
|
||||||
icon: <FileCopyIcon />,
|
|
||||||
onClick: () => setPasteVisible(true),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
label: 'Camera / Gallery',
|
label: 'Camera / Gallery',
|
||||||
icon: <PhotoLibraryIcon />,
|
icon: <PhotoLibraryIcon />,
|
||||||
@@ -90,7 +74,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
|
|||||||
<Modal visible={queryParamImagePreview} handleClose={removeQueryParamImage}>
|
<Modal visible={queryParamImagePreview} handleClose={removeQueryParamImage}>
|
||||||
<Box py={1}>
|
<Box py={1}>
|
||||||
<Typography paragraph>Do you want to share this image?</Typography>
|
<Typography paragraph>Do you want to share this image?</Typography>
|
||||||
<PictureResponsive src={queryParamImagePreview} alt={'Share gallery image preview'} />
|
<PictureResponsive src={queryParamImagePreview} alt="Share gallery image preview" />
|
||||||
<Button
|
<Button
|
||||||
fullWidth
|
fullWidth
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@@ -101,21 +85,6 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
|
|||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
</Modal>
|
</Modal>
|
||||||
<Modal visible={pasteVisible} handleClose={() => setPasteVisible(false)}>
|
|
||||||
<Box p={1}>
|
|
||||||
<TextField
|
|
||||||
placeholder="A link to your image or gif"
|
|
||||||
onChange={(e) => setMessage(e.target.value)}
|
|
||||||
value={message}
|
|
||||||
fullWidth
|
|
||||||
inputProps={{
|
|
||||||
className: classes.messagesInput,
|
|
||||||
}}
|
|
||||||
inputRef={(input) => input && input.focus()}
|
|
||||||
onKeyPress={sendFromClipboard}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Modal>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -17,12 +17,12 @@ import useStyles from './modal.styles';
|
|||||||
import useMessages from '../../hooks/useMessages';
|
import useMessages from '../../hooks/useMessages';
|
||||||
import Conversation, { CONVERSATION_ELEMENT_ID } from './Conversation';
|
import Conversation, { CONVERSATION_ELEMENT_ID } from './Conversation';
|
||||||
import MessageSkeletonList from './MessageSkeletonList';
|
import MessageSkeletonList from './MessageSkeletonList';
|
||||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
import { useHistory, useLocation, useParams } from 'react-router-dom';
|
import { useHistory, useLocation, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import Modal from '../../../../ui/components/Modal';
|
import Modal from '../../../../ui/components/Modal';
|
||||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
import { useContactActions } from '../../../contacts/hooks/useContactActions';
|
||||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
import { useMyPhoneNumber } from '../../../../os/simcard/hooks/useMyPhoneNumber';
|
||||||
import { MessageEvents } from '../../../../../../typings/messages';
|
import { MessageEvents } from '../../../../../../typings/messages';
|
||||||
|
|
||||||
const LARGE_HEADER_CHARS = 30;
|
const LARGE_HEADER_CHARS = 30;
|
||||||
@@ -48,14 +48,15 @@ const memberDisplay = (display, number, myNumber, t) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const MessageModal = () => {
|
export const MessageModal = () => {
|
||||||
|
const Nui = useNuiRequest();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { number: myNumber } = useSimcard();
|
const myNumber = useMyPhoneNumber();
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { groupId } = useParams<{ groupId: string }>();
|
const { groupId } = useParams<{ groupId: string }>();
|
||||||
const { messages, setMessages, activeMessageGroup, setActiveMessageGroup } = useMessages();
|
const { messages, setMessages, activeMessageGroup, setActiveMessageGroup } = useMessages();
|
||||||
const { getContactByNumber, getDisplayByNumber } = useContacts();
|
const { getContactByNumber, getDisplayByNumber } = useContactActions();
|
||||||
|
|
||||||
const [isLoaded, setLoaded] = useState(false);
|
const [isLoaded, setLoaded] = useState(false);
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ export const MessageModal = () => {
|
|||||||
groupId: activeMessageGroup.groupId,
|
groupId: activeMessageGroup.groupId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [activeMessageGroup]);
|
}, [activeMessageGroup, Nui]);
|
||||||
|
|
||||||
// don't allow too many characters, it takes too much room
|
// don't allow too many characters, it takes too much room
|
||||||
let header = activeMessageGroup ? activeMessageGroup.groupDisplay : '';
|
let header = activeMessageGroup ? activeMessageGroup.groupDisplay : '';
|
||||||
|
|||||||
@@ -1,32 +1,33 @@
|
|||||||
import { atom } from 'recoil';
|
import { atom } from 'recoil';
|
||||||
|
import { CreateMessageGroupResult, Message, MessageGroup } from '../../../../../typings/messages';
|
||||||
|
|
||||||
export const messageState = {
|
export const messageState = {
|
||||||
messageGroups: atom({
|
messageGroups: atom<MessageGroup[]>({
|
||||||
key: 'messageGroups',
|
key: 'messageGroups',
|
||||||
default: null,
|
default: [],
|
||||||
}),
|
}),
|
||||||
messages: atom({
|
messages: atom<Message[]>({
|
||||||
key: 'messages',
|
key: 'messages',
|
||||||
default: null,
|
default: null,
|
||||||
}),
|
}),
|
||||||
activeMessageGroup: atom({
|
activeMessageGroup: atom<MessageGroup>({
|
||||||
key: 'activeMessageGroup',
|
key: 'activeMessageGroup',
|
||||||
default: null,
|
default: null,
|
||||||
}),
|
}),
|
||||||
showNewMessageGroup: atom({
|
showNewMessageGroup: atom<boolean>({
|
||||||
key: 'showNewMessageGroup',
|
key: 'showNewMessageGroup',
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
createMessageGroupResult: atom({
|
createMessageGroupResult: atom<CreateMessageGroupResult>({
|
||||||
key: 'createMessageGroupResult',
|
key: 'createMessageGroupResult',
|
||||||
default: null,
|
default: null,
|
||||||
}),
|
}),
|
||||||
imageModal: atom({
|
imageModal: atom<boolean>({
|
||||||
key: 'useImageModal',
|
key: 'useImageModal',
|
||||||
default: false,
|
default: false,
|
||||||
}),
|
}),
|
||||||
unreadMessagesCount: atom({
|
unreadMessagesCount: atom<number>({
|
||||||
key: 'unreadMessagesCount',
|
key: 'unreadMessagesCount',
|
||||||
default: 0,
|
default: 0,
|
||||||
})
|
}),
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
import { useCallback } from 'react';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { matchPath, useHistory } from 'react-router-dom';
|
import { matchPath, useHistory } from 'react-router-dom';
|
||||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||||
import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
|
import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
|
||||||
import { goToConversation } from '../utils/goToConversation';
|
|
||||||
import useMessages from './useMessages';
|
import useMessages from './useMessages';
|
||||||
|
|
||||||
const NOTIFICATION_ID = 'messages:broadcast';
|
const NOTIFICATION_ID = 'messages:broadcast';
|
||||||
@@ -13,7 +11,7 @@ export const useMessageNotifications = () => {
|
|||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { removeId, addNotification, addNotificationAlert } = useNotifications();
|
const { removeId, addNotification, addNotificationAlert } = useNotifications();
|
||||||
const { icon, notificationIcon } = useApp('MESSAGES');
|
const { icon, notificationIcon } = useApp('MESSAGES');
|
||||||
const { getMessageGroupById, activeMessageGroup } = useMessages();
|
const { getMessageGroupById, activeMessageGroup, goToConversation } = useMessages();
|
||||||
|
|
||||||
// Remove notifications from groups when opening them
|
// Remove notifications from groups when opening them
|
||||||
history.listen((location) => {
|
history.listen((location) => {
|
||||||
@@ -39,7 +37,7 @@ export const useMessageNotifications = () => {
|
|||||||
id,
|
id,
|
||||||
sound: true,
|
sound: true,
|
||||||
title: group.label || group.groupDisplay,
|
title: group.label || group.groupDisplay,
|
||||||
onClick: () => goToConversation(group, history),
|
onClick: () => goToConversation(group),
|
||||||
content: message,
|
content: message,
|
||||||
icon,
|
icon,
|
||||||
notificationIcon,
|
notificationIcon,
|
||||||
|
|||||||
Loaded 100 of 373 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user