mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-01 14:38:47 +00:00
Compare commits
55
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f3076a45fb | ||
|
|
62aaaea368 | ||
|
|
9896f2384e | ||
|
|
289207beb9 | ||
|
|
8bfdc1b8b2 | ||
|
|
d315d72e93 | ||
|
|
2992a644fe | ||
|
|
2b633c9e80 | ||
|
|
dab4c1eaf7 | ||
|
|
48e0dd2443 | ||
|
|
3157cafd5a | ||
|
|
c82a48b012 | ||
|
|
4d46566811 | ||
|
|
ee7e3a3ae1 | ||
|
|
31241c7e8f | ||
|
|
5f2dce2dda | ||
|
|
107dc43624 | ||
|
|
f27e486ff5 | ||
|
|
a88286f97a | ||
|
|
baf6dedb6f | ||
|
|
c5115777c5 | ||
|
|
d95cd8d4bc | ||
|
|
632e27e0fa | ||
|
|
853b335ef9 | ||
|
|
6b865f2e73 | ||
|
|
b02b19be5f | ||
|
|
0bb9b6738f | ||
|
|
a6f98d7ac0 | ||
|
|
5ce6cf2d4a | ||
|
|
2e4d752cd3 | ||
|
|
2cd3e9e93d | ||
|
|
b789e73447 | ||
|
|
98efed4e64 | ||
|
|
6c2eae7f5d | ||
|
|
de10ce92b2 | ||
|
|
5654e1f46f | ||
|
|
a3d7c19f44 | ||
|
|
b42ee97450 | ||
|
|
4e7e6b3e92 | ||
|
|
0f61088999 | ||
|
|
53d5bb459d | ||
|
|
fe1e685f6f | ||
|
|
c8f680fdfb | ||
|
|
f3f055944c | ||
|
|
21a2f8912d | ||
|
|
97f5c99cc0 | ||
|
|
8000cc3d3f | ||
|
|
9261025b4f | ||
|
|
a52ffc4e79 | ||
|
|
2a4457b323 | ||
|
|
97c308f550 | ||
|
|
769f5a3d21 | ||
|
|
73f057b55b | ||
|
|
0ec2b682e7 | ||
|
|
f1f6a05981 |
No files matched your search
@@ -3,6 +3,8 @@
|
||||
|
||||
resources/html
|
||||
|
||||
phone/.eslintcache
|
||||
|
||||
# Node Modules and Built Folders
|
||||
node_modules
|
||||
build
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<img src="https://beta.iodine.gg/zVkK7.png" width="500" height="300" />
|
||||
|
||||
|
||||
NPWD is our current running project. Our team has been working on the project since Auguest, 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 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.
|
||||
|
||||
Written completely by the Project Error Dev Team in [React](https://reactjs.org/) with a [TypeScript](https://www.typescriptlang.org/) client/server environment.
|
||||
|
||||
|
||||
@@ -27,6 +27,10 @@
|
||||
"enableImages": true,
|
||||
"maxImages": 3
|
||||
},
|
||||
"match": {
|
||||
"generateProfileNameFromUsers": true,
|
||||
"allowEdtiableProfileName": true
|
||||
},
|
||||
"bank": {
|
||||
"showNotifications": true
|
||||
},
|
||||
|
||||
+69
-44
@@ -1,15 +1,13 @@
|
||||
# comment this out if your server has a different table/location for phone_number
|
||||
# or if it already exists in the users table
|
||||
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 (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
identifier varchar(60) DEFAULT NULL,
|
||||
avatar varchar(512) DEFAULT NULL,
|
||||
number varchar(10) DEFAULT NULL,
|
||||
display varchar(60) NOT NULL DEFAULT '',
|
||||
CREATE TABLE IF NOT EXISTS `npwd_phone_contacts` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(48) DEFAULT NULL,
|
||||
`avatar` varchar(512) DEFAULT NULL,
|
||||
`number` varchar(10) DEFAULT NULL,
|
||||
`display` varchar(60) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
@@ -19,7 +17,7 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_tweets` (
|
||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`likes` int NOT NULL DEFAULT '0',
|
||||
`identifier` varchar(40) NOT NULL,
|
||||
`identifier` varchar(48) NOT NULL,
|
||||
`visible` tinyint NOT NULL DEFAULT '1',
|
||||
`images` varchar(1000) DEFAULT '',
|
||||
`retweet` int DEFAULT NULL,
|
||||
@@ -30,7 +28,7 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_tweets` (
|
||||
CREATE TABLE IF NOT EXISTS `npwd_twitter_profiles` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`profile_name` varchar(90) NOT NULL,
|
||||
`identifier` varchar(40) NOT NULL,
|
||||
`identifier` varchar(48) NOT NULL,
|
||||
# Default Profile avatar can be set here
|
||||
`avatar_url` varchar(255) DEFAULT 'https://beta.iodine.gg/QrEvq.png',
|
||||
`bio` varchar(512) DEFAULT NULL,
|
||||
@@ -54,33 +52,60 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_likes` (
|
||||
CONSTRAINT `tweet` FOREIGN KEY (`tweet_id`) REFERENCES `npwd_twitter_tweets` (`id`) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `npwd_match_profiles` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(48) NOT NULL,
|
||||
`name` varchar(90) NOT NULL,
|
||||
`image` varchar(255) NOT NULL,
|
||||
`bio` varchar(512) DEFAULT NULL,
|
||||
`location` varchar(45) DEFAULT NULL,
|
||||
`job` varchar(45) DEFAULT NULL,
|
||||
`tags` varchar(255) NOT NULL DEFAULT '',
|
||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `name_UNIQUE` (`name`),
|
||||
UNIQUE KEY `identifier_UNIQUE` (`identifier`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_notes (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
identifier varchar(255) NOT NULL,
|
||||
title varchar(255) NOT NULL,
|
||||
content varchar(255) NOT NULL,
|
||||
CREATE TABLE IF NOT EXISTS `npwd_match_views` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(48) NOT NULL,
|
||||
`profile` int NOT NULL,
|
||||
`liked` tinyint DEFAULT '0',
|
||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `match_profile_idx` (`profile`),
|
||||
CONSTRAINT `match_profile` FOREIGN KEY (`profile`) REFERENCES `npwd_match_profiles` (`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `npwd_notes` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(48) NOT NULL,
|
||||
`title` varchar(255) NOT NULL,
|
||||
`content` varchar(255) NOT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_marketplace_listings (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
identifier varchar(255) DEFAULT NULL,
|
||||
username varchar(255) DEFAULT NULL,
|
||||
name varchar(50) DEFAULT NULL,
|
||||
number varchar(255) NOT NULL,
|
||||
title varchar(255) DEFAULT NULL,
|
||||
url varchar(255) DEFAULT NULL,
|
||||
description varchar(255) NOT NULL,
|
||||
createdAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updatedAt timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
CREATE TABLE IF NOT EXISTS `npwd_marketplace_listings` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(48) DEFAULT NULL,
|
||||
`username` varchar(255) DEFAULT NULL,
|
||||
`name` varchar(50) DEFAULT NULL,
|
||||
`number` varchar(255) NOT NULL,
|
||||
`title` varchar(255) DEFAULT NULL,
|
||||
`url` varchar(255) DEFAULT NULL,
|
||||
`description` varchar(255) NOT NULL,
|
||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_marketplace_reports (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
listing_id int(11) DEFAULT NULL,
|
||||
profile varchar(255) DEFAULT NULL,
|
||||
CREATE TABLE IF NOT EXISTS `npwd_marketplace_reports` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`listing_id` int(11) DEFAULT NULL,
|
||||
`profile` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
@@ -98,11 +123,11 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_reports` (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `npwd_messages_groups` (
|
||||
`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,
|
||||
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
`group_id` varchar(512) NOT NULL,
|
||||
`participant_identifier` varchar(40) NOT NULL,
|
||||
`participant_identifier` varchar(48) NOT NULL,
|
||||
`label` varchar(60) DEFAULT '',
|
||||
`unreadCount` int(11) NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`id`)
|
||||
@@ -110,7 +135,7 @@ CREATE TABLE IF NOT EXISTS `npwd_messages_groups` (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `npwd_messages_labels` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`user_identifier` varchar(40) NOT NULL,
|
||||
`user_identifier` varchar(48) 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,
|
||||
@@ -121,7 +146,7 @@ CREATE TABLE IF NOT EXISTS `npwd_messages_labels` (
|
||||
CREATE TABLE IF NOT EXISTS `npwd_messages` (
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`message` varchar(512) NOT NULL,
|
||||
`user_identifier` varchar(40) NOT NULL,
|
||||
`user_identifier` varchar(48) NOT NULL,
|
||||
`group_id` varchar(512) NOT NULL,
|
||||
`isRead` tinyint NOT NULL DEFAULT '0',
|
||||
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
@@ -130,20 +155,20 @@ CREATE TABLE IF NOT EXISTS `npwd_messages` (
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_calls (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
identifier varchar(255) DEFAULT NULL,
|
||||
transmitter varchar(255) NOT NULL,
|
||||
receiver varchar(255) NOT NULL,
|
||||
is_accepted tinyint(4) DEFAULT 0,
|
||||
start varchar(255) DEFAULT NULL,
|
||||
CREATE TABLE IF NOT EXISTS `npwd_calls` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(48) DEFAULT NULL,
|
||||
`transmitter` varchar(255) NOT NULL,
|
||||
`receiver` varchar(255) NOT NULL,
|
||||
`is_accepted` tinyint(4) DEFAULT 0,
|
||||
`start` varchar(255) DEFAULT NULL,
|
||||
end varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS npwd_phone_gallery (
|
||||
id int(11) NOT NULL AUTO_INCREMENT,
|
||||
identifier varchar(255) DEFAULT NULL,
|
||||
image varchar(255) DEFAULT NULL,
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`identifier` varchar(48) DEFAULT NULL,
|
||||
`image` varchar(255) DEFAULT NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
@@ -0,0 +1,58 @@
|
||||
const {
|
||||
addAfterLoader,
|
||||
removeLoaders,
|
||||
loaderByName,
|
||||
getLoaders,
|
||||
throwUnexpectedConfigError,
|
||||
} = require('@craco/craco');
|
||||
|
||||
const throwError = (message) =>
|
||||
throwUnexpectedConfigError({
|
||||
packageName: 'craco',
|
||||
githubRepo: 'gsoft-inc/craco',
|
||||
message,
|
||||
githubIssueQuery: 'webpack',
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
webpack: {
|
||||
configure: (webpackConfig, { paths }) => {
|
||||
const { hasFoundAny, matches } = getLoaders(webpackConfig, loaderByName('babel-loader'));
|
||||
if (!hasFoundAny) throwError('failed to find babel-loader');
|
||||
|
||||
const { hasRemovedAny, removedCount } = removeLoaders(
|
||||
webpackConfig,
|
||||
loaderByName('babel-loader'),
|
||||
);
|
||||
if (!hasRemovedAny) throwError('no babel-loader to remove');
|
||||
if (removedCount !== 2) throwError('had expected to remove 2 babel loader instances');
|
||||
webpackConfig.resolve.plugins = webpackConfig.resolve.plugins.filter(
|
||||
({ constructor: c }) => !c || c.name !== 'ModuleScopePlugin',
|
||||
);
|
||||
|
||||
const tsLoader = {
|
||||
test: /\.tsx?$/,
|
||||
loader: require.resolve('ts-loader'),
|
||||
options: { transpileOnly: true },
|
||||
};
|
||||
|
||||
const { isAdded: tsLoaderIsAdded } = addAfterLoader(
|
||||
webpackConfig,
|
||||
loaderByName('url-loader'),
|
||||
tsLoader,
|
||||
);
|
||||
|
||||
if (!tsLoaderIsAdded) throwError('failed to add ts-loader');
|
||||
|
||||
const { isAdded: babelLoaderIsAdded } = addAfterLoader(
|
||||
webpackConfig,
|
||||
loaderByName('ts-loader'),
|
||||
matches[1].loader, // babel-loader
|
||||
);
|
||||
|
||||
if (!babelLoaderIsAdded) throwError('failed to add back babel-loader for non-application JS');
|
||||
|
||||
return webpackConfig;
|
||||
},
|
||||
},
|
||||
};
|
||||
+6
-3
@@ -24,6 +24,7 @@
|
||||
"enzyme-adapter-react-16": "^1.15.5",
|
||||
"howler": "^2.2.1",
|
||||
"i18next": "^19.7.0",
|
||||
"jsonschema": "^1.4.0",
|
||||
"parse-url": "^5.0.2",
|
||||
"qs": "^6.9.6",
|
||||
"react": "^16.13.1",
|
||||
@@ -32,7 +33,7 @@
|
||||
"react-i18next": "^11.7.1",
|
||||
"react-popper": "^2.2.3",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-scripts": "3.4.3",
|
||||
"react-scripts": "4.0.1",
|
||||
"recoil": "^0.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -42,6 +43,7 @@
|
||||
"@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",
|
||||
"@testing-library/jest-dom": "^4.2.4",
|
||||
"@testing-library/react": "^9.5.0",
|
||||
"@testing-library/user-event": "^7.2.1",
|
||||
@@ -62,6 +64,7 @@
|
||||
"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",
|
||||
@@ -78,11 +81,11 @@
|
||||
"scripts": {
|
||||
"i18n:missing": "node --experimental-json-modules i18n.missingKeys.js",
|
||||
"copy:config": "cp-cli ../config.json ./src/config.autogen.json",
|
||||
"start": "yarn copy:config && react-scripts start",
|
||||
"start": "craco start",
|
||||
"watch": "cra-build-watch --disable-chunks --build-path ../resources/html --output-filename dev.js",
|
||||
"build": "yarn copy:config && cross-env NODE_ENV=production webpack --config webpack/prod.config.js --color -p --progress --hide-modules --display-optimization-bailout",
|
||||
"build:dev": "cross-env NODE_ENV=development webpack --config webpack/dev.config.js --color -p --progress --hide-modules --display-optimization-bailout --analyze",
|
||||
"test": "react-scripts 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"
|
||||
},
|
||||
|
||||
+24
-5
@@ -15,12 +15,13 @@ import { useApps } from './os/apps/hooks/useApps';
|
||||
|
||||
import { useContactsService } from './apps/contacts/hooks/useContactsService';
|
||||
import { useTwitterService } from './apps/twitter/hooks/useTwitterService';
|
||||
import { useSelloutService } from './apps/sellout/hooks/useSelloutService';
|
||||
import { useMatchService } from './apps/match/hooks/useMatchService';
|
||||
import { useMarketplaceService } from './apps/marketplace/hooks/useMarketplaceService';
|
||||
import { useBankService } from './apps/bank/hooks/useBankService';
|
||||
import { useMessagesService } from './apps/messages/hooks/useMessageService';
|
||||
import { useNotesService } from './apps/notes/hooks/useNotesService';
|
||||
import { usePhotoService } from './apps/camera/hooks/usePhotoService';
|
||||
import { useSettings } from './apps/settings/hooks/useSettings';
|
||||
import { isSettingsSchemaValid, useSettings } from './apps/settings/hooks/useSettings';
|
||||
import { useCallService } from './os/call/hooks/useCallService';
|
||||
import { useDialService } from './apps/dialer/hooks/useDialService';
|
||||
import InjectDebugData from './os/debug/InjectDebugData';
|
||||
@@ -31,6 +32,7 @@ import { useCallModal } from './os/call/hooks/useCallModal';
|
||||
import WindowSnackbar from './ui/components/WindowSnackbar';
|
||||
import { usePhone } from './os/phone/hooks/usePhone';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useSnackbar } from './ui/hooks/useSnackbar';
|
||||
|
||||
function Phone() {
|
||||
const { t, i18n } = useTranslation();
|
||||
@@ -39,19 +41,34 @@ function Phone() {
|
||||
|
||||
const [settings] = useSettings();
|
||||
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
// Set language from local storage
|
||||
// This will only trigger on first mount & settings changes
|
||||
useEffect(() => {
|
||||
i18n.changeLanguage(settings.language.value).catch((e) => console.error(e));
|
||||
}, [i18n, settings.language]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSettingsSchemaValid()) {
|
||||
addAlert({
|
||||
message: t('SETTINGS.MESSAGES.INVALID_SETTINGS'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
// We only want to run this on first mount of the phone,
|
||||
// so we leave an empty dep array. Otherwise, we hit a max depth error.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useNuiService();
|
||||
useKeyboardService();
|
||||
usePhoneService();
|
||||
useSimcardService();
|
||||
useContactsService();
|
||||
useTwitterService();
|
||||
useSelloutService();
|
||||
useMatchService();
|
||||
useMarketplaceService();
|
||||
useBankService();
|
||||
useMessagesService();
|
||||
useNotesService();
|
||||
@@ -80,14 +97,16 @@ function Phone() {
|
||||
<div
|
||||
className="PhoneFrame"
|
||||
style={{
|
||||
backgroundImage: `url(./media/frames/${settings.frame.value})`,
|
||||
backgroundImage: `url(media/frames/${settings.frame.value})`,
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
id="phone"
|
||||
className="PhoneScreen"
|
||||
style={{
|
||||
backgroundImage: `url(./media/backgrounds/${settings.wallpaper.value})`,
|
||||
backgroundImage: settings.customWallpaper
|
||||
? `url(${settings.customWallpaper})`
|
||||
: `url(media/backgrounds/${settings.wallpaper.value})`,
|
||||
}}
|
||||
>
|
||||
{isPhoneReady ? (
|
||||
|
||||
@@ -3,9 +3,8 @@ import React, { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import HomeIcon from '@material-ui/icons/Home';
|
||||
import LocalAtmIcon from '@material-ui/icons/LocalAtm';
|
||||
import ListIcon from '@material-ui/icons/List';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faHome, faList, faMoneyCheck } from '@fortawesome/free-solid-svg-icons';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -31,9 +30,21 @@ export const NavigationBar = () => {
|
||||
showLabels
|
||||
className={classes.root}
|
||||
>
|
||||
<BottomNavigationAction component={Link} icon={<HomeIcon />} to="/bank" />
|
||||
<BottomNavigationAction component={Link} icon={<LocalAtmIcon />} to="/bank/account" />
|
||||
<BottomNavigationAction component={Link} icon={<ListIcon />} to="/bank/transactions" />
|
||||
<BottomNavigationAction
|
||||
component={Link}
|
||||
icon={<FontAwesomeIcon icon={faHome} />}
|
||||
to="/bank"
|
||||
/>
|
||||
<BottomNavigationAction
|
||||
component={Link}
|
||||
icon={<FontAwesomeIcon icon={faMoneyCheck} />}
|
||||
to="/bank/account"
|
||||
/>
|
||||
<BottomNavigationAction
|
||||
component={Link}
|
||||
icon={<FontAwesomeIcon icon={faList} />}
|
||||
to="/bank/transactions"
|
||||
/>
|
||||
</BottomNavigation>
|
||||
);
|
||||
};
|
||||
@@ -5,6 +5,7 @@ import { Button, List, ListItem, TextField, makeStyles } from '@material-ui/core
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
|
||||
import { useBankModal } from '../../hooks/useBankModal';
|
||||
import { BankEvents } from '../../../../../../typings/bank';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
input: {
|
||||
@@ -43,7 +44,7 @@ export const TransferModal = () => {
|
||||
|
||||
const addTransfer = () => {
|
||||
const transferAmount = parseInt(amount);
|
||||
Nui.send('phone:addTransfer', {
|
||||
Nui.send(BankEvents.ADD_TRANSFER, {
|
||||
targetID,
|
||||
transferAmount,
|
||||
message,
|
||||
|
||||
@@ -6,6 +6,8 @@ import { useSetRecoilState } from 'recoil';
|
||||
import { useBankNotification } from './useBankNotification';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { BankEvents } from '../../../../../typings/bank';
|
||||
import { PhoneEvents } from '../../../../../typings/phone';
|
||||
|
||||
export const useBankService = () => {
|
||||
const setTransaction = useSetRecoilState(bankState.transactions);
|
||||
@@ -21,9 +23,9 @@ export const useBankService = () => {
|
||||
});
|
||||
};
|
||||
|
||||
useNuiEvent('BANK', 'setTransaction', setTransaction);
|
||||
useNuiEvent('BANK', 'setCredentials', setCredentials);
|
||||
useNuiEvent('BANK', 'setAlert', handleAddAlert);
|
||||
useNuiEvent('BANK', 'setNotification', setNotification);
|
||||
useNuiEvent('BANK', BankEvents.SEND_TRANSFERS, setTransaction);
|
||||
useNuiEvent('BANK', BankEvents.SEND_CREDENTIALS, setCredentials);
|
||||
useNuiEvent('BANK', BankEvents.SEND_ALERT, handleAddAlert);
|
||||
useNuiEvent('BANK', BankEvents.SEND_NOTIFICATION, setNotification);
|
||||
return { useTransactions, useCredentials, useBankNotification };
|
||||
};
|
||||
@@ -5,11 +5,12 @@ import { GalleryGrid } from './grid/GalleryGrid';
|
||||
import { GalleryModal } from './modal/GalleryModal';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import { PhotoEvents } from '../../../../../typings/photo';
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'CAMERA',
|
||||
method: 'setPhotos',
|
||||
method: PhotoEvents.SEND_PHOTOS,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
|
||||
@@ -8,6 +8,7 @@ import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { addQueryToLocation } from '../../../../common/utils/addQueryToLocation';
|
||||
import { getLocationFromUrl } from '../../../../common/utils/getLocationFromUrl';
|
||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
||||
|
||||
export const GalleryGrid = () => {
|
||||
const classes = useStyles();
|
||||
@@ -19,7 +20,7 @@ export const GalleryGrid = () => {
|
||||
const photos = usePhotos();
|
||||
|
||||
const handleCamera = () => {
|
||||
Nui.send('phone:TakePhoto', {});
|
||||
Nui.send(PhotoEvents.TAKE_PHOTO, {});
|
||||
};
|
||||
|
||||
const handlePhotoOpen = (photo) => {
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useHistory } from 'react-router-dom';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { ICameraPhoto } from '../../hooks/usePhotos';
|
||||
import { ShareModal } from './ShareModal';
|
||||
import { PhotoEvents } from '../../../../../../typings/photo';
|
||||
|
||||
export const GalleryModal = () => {
|
||||
const classes = useStyles();
|
||||
@@ -28,7 +29,7 @@ export const GalleryModal = () => {
|
||||
};
|
||||
|
||||
const handleDeletePhoto = () => {
|
||||
Nui.send('photo:deletePhoto', {
|
||||
Nui.send(PhotoEvents.DELETE_PHOTO, {
|
||||
image: meta.image,
|
||||
});
|
||||
history.push(referal);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
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', 'setPhotos', setPhotos);
|
||||
useNuiEvent('CAMERA', PhotoEvents.SEND_PHOTOS, setPhotos);
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import { Route } from 'react-router-dom';
|
||||
import ContactsInfoPage from './views/ContactInfo';
|
||||
import { ContactPage } from './views/ContactsPage';
|
||||
import { ContactsThemeProvider } from '../providers/ContactsThemeProvider';
|
||||
import { ContactEvents } from '../../../../../typings/contact';
|
||||
|
||||
export const ContactsApp = () => {
|
||||
const contacts = useApp('CONTACTS');
|
||||
@@ -29,7 +30,7 @@ export const ContactsApp = () => {
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'CONTACTS',
|
||||
method: 'setContacts',
|
||||
method: ContactEvents.SEND_CONTACTS,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
|
||||
@@ -10,6 +10,7 @@ import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { SearchContacts } from './SearchContacts';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||
import { CallEvents } from '../../../../../../typings/call';
|
||||
|
||||
export const ContactList = () => {
|
||||
const { filteredContacts } = useFilteredContacts();
|
||||
@@ -27,7 +28,7 @@ export const ContactList = () => {
|
||||
level: 2,
|
||||
data: true,
|
||||
});
|
||||
Nui.send('phone:beginCall', {
|
||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
||||
number,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import LogDebugEvent from '../../../../os/debug/LogDebugEvents';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { ContactEvents } from '../../../../../../typings/contact';
|
||||
|
||||
interface ContactInfoRouteParams {
|
||||
mode: string;
|
||||
@@ -79,7 +80,7 @@ const ContactsInfoPage = () => {
|
||||
data: contact,
|
||||
level: 2,
|
||||
});
|
||||
Nui.send('phone:addContacts', {
|
||||
Nui.send(ContactEvents.ADD_CONTACT, {
|
||||
display: name,
|
||||
number,
|
||||
avatar,
|
||||
@@ -93,7 +94,7 @@ const ContactsInfoPage = () => {
|
||||
data: contact,
|
||||
level: 2,
|
||||
});
|
||||
Nui.send('phone:updateContact', {
|
||||
Nui.send(ContactEvents.UPDATE_CONTACT, {
|
||||
id: contact.id,
|
||||
display: name,
|
||||
number,
|
||||
@@ -108,7 +109,7 @@ const ContactsInfoPage = () => {
|
||||
data: contact,
|
||||
level: 2,
|
||||
});
|
||||
Nui.send('phone:deleteContact', {
|
||||
Nui.send(ContactEvents.DELETE_CONTACT, {
|
||||
id: contact.id,
|
||||
});
|
||||
history.goBack();
|
||||
|
||||
@@ -4,6 +4,7 @@ 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);
|
||||
@@ -17,7 +18,7 @@ export const useContactsService = () => {
|
||||
});
|
||||
};
|
||||
|
||||
useNuiEvent('CONTACTS', 'setContacts', setContacts);
|
||||
useNuiEvent('CONTACTS', 'setAlert', handleAddAlert);
|
||||
useNuiEvent('CONTACTS', ContactEvents.SEND_CONTACTS, setContacts);
|
||||
useNuiEvent('CONTACTS', ContactEvents.SEND_ALERT, handleAddAlert);
|
||||
return useContacts();
|
||||
};
|
||||
@@ -11,6 +11,7 @@ import { useDialHistory } from '../hooks/useDialHistory';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { ContactList } from '../../contacts/components/List/ContactList';
|
||||
import { DialerThemeProvider } from '../providers/DialerThemeProvider';
|
||||
import { CallEvents } from '../../../../../typings/call';
|
||||
|
||||
export const DialerApp = () => {
|
||||
const history = useDialHistory();
|
||||
@@ -28,7 +29,7 @@ export const DialerApp = () => {
|
||||
<Route exact path="/phone">
|
||||
<DialerHistory calls={history} />
|
||||
</Route>
|
||||
<Route path="/phone/contacts" component={ContactList}></Route>
|
||||
<Route path="/phone/contacts" component={ContactList} />
|
||||
</Switch>
|
||||
</AppContent>
|
||||
<DialerNavBar />
|
||||
@@ -39,18 +40,18 @@ export const DialerApp = () => {
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'DAILER',
|
||||
method: 'setHistory',
|
||||
app: 'DIALER',
|
||||
method: CallEvents.SET_CALL_HISTORY,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
transmitter: '636-6496',
|
||||
start: 1612301545782,
|
||||
start: 1615946292,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
transmitter: '777-7777',
|
||||
start: 1612301545782,
|
||||
start: 1615946292,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -3,9 +3,11 @@ import { Box, IconButton, InputBase, Paper } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import PersonAddIcon from '@material-ui/icons/PersonAdd';
|
||||
import { DialInputCtx } from '../context/InputContext';
|
||||
import { DialInputCtx, IDialInputCtx } from '../context/InputContext';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { CallEvents } from '../../../../../typings/call';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
root: {
|
||||
@@ -29,11 +31,12 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||
export const DialerInput = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { inputVal } = useContext(DialInputCtx);
|
||||
const { inputVal, set } = useContext<IDialInputCtx>(DialInputCtx);
|
||||
|
||||
const handleCall = (number: string) => {
|
||||
Nui.send('phone:beginCall', {
|
||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
||||
number,
|
||||
});
|
||||
};
|
||||
@@ -44,8 +47,14 @@ export const DialerInput = () => {
|
||||
|
||||
return (
|
||||
<Box component={Paper} className={classes.root}>
|
||||
<InputBase placeholder="Enter a number" className={classes.input} value={inputVal} />
|
||||
<IconButton color="primary" className={classes.iconBtn}>
|
||||
<InputBase
|
||||
placeholder={t('APPS_DIALER_INPUT_PLACEHOLDER')}
|
||||
className={classes.input}
|
||||
value={inputVal}
|
||||
onChange={(e) => set(e.target.value)}
|
||||
type="number"
|
||||
/>
|
||||
<IconButton color="primary" className={classes.iconBtn} disabled={inputVal <= ''}>
|
||||
<PhoneIcon fontSize="large" onClick={() => handleCall(inputVal)} />
|
||||
</IconButton>
|
||||
<IconButton className={classes.iconBtn}>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import PersonIcon from '@material-ui/icons/Person';
|
||||
import HistoryIcon from '@material-ui/icons/History';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
root: {
|
||||
@@ -20,6 +21,7 @@ const DialerNavBar = () => {
|
||||
const classes = useStyles();
|
||||
const { pathname } = useLocation();
|
||||
const [page, setPage] = useState(pathname);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleChange = (_e, newPage) => {
|
||||
setPage(newPage);
|
||||
@@ -28,14 +30,14 @@ const DialerNavBar = () => {
|
||||
return (
|
||||
<BottomNavigation value={page} onChange={handleChange} showLabels className={classes.root}>
|
||||
<BottomNavigationAction
|
||||
label="History"
|
||||
label={t('APPS_DIALER_NAVBAR_HISTORY')}
|
||||
value="/phone"
|
||||
component={NavLink}
|
||||
icon={<HistoryIcon />}
|
||||
to="/phone"
|
||||
/>
|
||||
<BottomNavigationAction
|
||||
label="Dial"
|
||||
label={t('APPS_DIALER_NAVBAR_DIAL')}
|
||||
value="/phone/dial"
|
||||
color="secondary"
|
||||
component={NavLink}
|
||||
@@ -43,7 +45,7 @@ const DialerNavBar = () => {
|
||||
to="/phone/dial"
|
||||
/>
|
||||
<BottomNavigationAction
|
||||
label="Contacts"
|
||||
label={t('APPS_DIALER_NAVBAR_CONTACTS')}
|
||||
value="/phone/contacts"
|
||||
color="secondary"
|
||||
component={NavLink}
|
||||
|
||||
@@ -28,6 +28,7 @@ const DialPage = () => {
|
||||
add: (val: string) => setInputVal(inputVal + val),
|
||||
removeOne: () => setInputVal(inputVal.slice(0, -1)),
|
||||
clear: () => setInputVal(''),
|
||||
set: (val: string) => setInputVal(val),
|
||||
}}
|
||||
>
|
||||
<DialerInput />
|
||||
|
||||
@@ -8,12 +8,12 @@ import { ListItem } from '../../../../ui/components/ListItem';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { ICall } from '../../../../../../typings/call';
|
||||
import dayjs from 'dayjs';
|
||||
import { CallEvents, ICall } from '../../../../../../typings/call';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, IconButton, ListItemIcon, ListItemText } from '@material-ui/core';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
callForward: {
|
||||
@@ -25,7 +25,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||
}));
|
||||
|
||||
export const DialerHistory = ({ calls }) => {
|
||||
const { number } = useSimcard();
|
||||
const { number: myNumber } = useSimcard();
|
||||
const { getDisplayByNumber } = useContacts();
|
||||
|
||||
const classes = useStyles();
|
||||
@@ -35,7 +35,7 @@ export const DialerHistory = ({ calls }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleCall = (phoneNumber) => {
|
||||
Nui.send('phone:beginCall', {
|
||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
||||
number: phoneNumber,
|
||||
});
|
||||
};
|
||||
@@ -44,9 +44,9 @@ export const DialerHistory = ({ calls }) => {
|
||||
return (
|
||||
<Box display="flex" justifyContent="center" alignItems="center" paddingTop={35}>
|
||||
<p>
|
||||
You got no friends!
|
||||
<span role="img" aria-label="deal with it">
|
||||
😎
|
||||
{t('APPS_DIALER_NO_HISTORY')}
|
||||
<span role="img" aria-label="sad">
|
||||
😞
|
||||
</span>
|
||||
</p>
|
||||
</Box>
|
||||
@@ -56,45 +56,57 @@ export const DialerHistory = ({ calls }) => {
|
||||
return (
|
||||
<List disablePadding>
|
||||
{calls.map((call: ICall) =>
|
||||
call.transmitter === number ? (
|
||||
call.transmitter === myNumber ? (
|
||||
<ListItem key={call.id} divider>
|
||||
<ListItemIcon>{<PhoneForwardedIcon className={classes.callForward} />}</ListItemIcon>
|
||||
<ListItemIcon>
|
||||
<PhoneForwardedIcon className={classes.callForward} />
|
||||
</ListItemIcon>
|
||||
|
||||
<ListItemText
|
||||
primary={getDisplayByNumber(call.receiver)}
|
||||
secondary={dayjs.unix(call.start).format(t('DATE_TIME_FORMAT'))}
|
||||
secondary={
|
||||
// TODO: Locale changes are pending #168 merge
|
||||
dayjs().to(dayjs.unix(call.start))
|
||||
}
|
||||
/>
|
||||
<IconButton onClick={() => handleCall(call.receiver)}>{<PhoneIcon />}</IconButton>
|
||||
|
||||
{getDisplayByNumber(call.transmitter) === call.transmitter ? (
|
||||
{getDisplayByNumber(call.transmitter) === call.transmitter && (
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
history.push(`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`)
|
||||
}
|
||||
>
|
||||
{<PersonAddIcon />}
|
||||
<PersonAddIcon />
|
||||
</IconButton>
|
||||
) : null}
|
||||
)}
|
||||
</ListItem>
|
||||
) : (
|
||||
<ListItem key={call.id} divider>
|
||||
<ListItemIcon>{<PhoneCallbackIcon className={classes.callBack} />}</ListItemIcon>
|
||||
<ListItemIcon>
|
||||
<PhoneCallbackIcon className={classes.callBack} />
|
||||
</ListItemIcon>
|
||||
|
||||
<ListItemText
|
||||
primary={getDisplayByNumber(call.transmitter)}
|
||||
secondary={dayjs.unix(call.start).format(t('DATE_TIME_FORMAT'))}
|
||||
secondary={
|
||||
// TODO: Locale changes are pending #168 merge
|
||||
dayjs().to(dayjs.unix(call.start))
|
||||
}
|
||||
/>
|
||||
<IconButton onClick={() => handleCall(call.transmitter)}>{<PhoneIcon />}</IconButton>
|
||||
<IconButton onClick={() => handleCall(call.transmitter)}>
|
||||
<PhoneIcon />
|
||||
</IconButton>
|
||||
|
||||
{getDisplayByNumber(call.transmitter) === call.transmitter ? (
|
||||
{getDisplayByNumber(call.transmitter) === call.transmitter && (
|
||||
<IconButton
|
||||
onClick={() =>
|
||||
history.push(`/contacts/-1?addNumber=${call.transmitter}&referal=/phone/contacts`)
|
||||
}
|
||||
>
|
||||
{<PersonAddIcon />}
|
||||
<PersonAddIcon />
|
||||
</IconButton>
|
||||
) : null}
|
||||
)}
|
||||
</ListItem>
|
||||
),
|
||||
)}
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface IDialInputCtx {
|
||||
add: (char: string | number) => void;
|
||||
removeOne: () => void;
|
||||
clear: () => void;
|
||||
set: (val) => void;
|
||||
}
|
||||
|
||||
export const DialInputCtx = createContext(null);
|
||||
@@ -1,11 +1,7 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { ICall } from '../../../../../typings/call';
|
||||
import { dialState } from './state';
|
||||
interface ICallUI {
|
||||
history: ICall[];
|
||||
}
|
||||
|
||||
export const useDialHistory = (): ICallUI[] => {
|
||||
const history = useRecoilValue(dialState.history);
|
||||
return history;
|
||||
export const useDialHistory = () => {
|
||||
return useRecoilValue<ICall[]>(dialState.history);
|
||||
};
|
||||
@@ -1,8 +1,9 @@
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { dialState } from './state';
|
||||
import { CallEvents } from '../../../../../typings/call';
|
||||
|
||||
export const useDialService = () => {
|
||||
const setHistory = useSetRecoilState(dialState.history);
|
||||
useNuiEvent('DAILER', 'setHistory', setHistory);
|
||||
useNuiEvent('DIALER', CallEvents.SET_CALL_HISTORY, setHistory);
|
||||
};
|
||||
@@ -16,7 +16,7 @@ export const ExampleApp = () => {
|
||||
const exampleString = useExample();
|
||||
const example = useApp('EXAMPLE');
|
||||
const [soundName, setSound] = useState('pixel.ogg');
|
||||
const { play, playing, stop } = useSound('./media/ringtones/' + soundName);
|
||||
const { play, playing, stop } = useSound('media/ringtones/' + soundName);
|
||||
|
||||
const toggleSound = () => {
|
||||
if (soundName === 'pixel.ogg') {
|
||||
|
||||
+14
-12
@@ -1,42 +1,44 @@
|
||||
import React from 'react';
|
||||
import { AppWrapper } from '../../../ui/components/AppWrapper';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { SelloutTitle } from './SelloutTitle';
|
||||
import { SelloutListContainer } from './SelloutList/SelloutListContainer';
|
||||
import { MarketplaceTitle } from './MarketplaceTitle';
|
||||
import { MarketplaceListContainer } from './SelloutList/MarketplaceListContainer';
|
||||
import { NavigationBar } from './navigation/NavigationBar';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
import { ListingFormContainer } from './form/ListingFormContainer';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { SelloutThemeProvider } from '../providers/SelloutThemeProvider';
|
||||
import { MarketplaceThemeProvider } from '../providers/MarketplaceThemeProvider';
|
||||
import { MarketplaceEvents } from '../../../../../typings/marketplace';
|
||||
|
||||
export const SelloutApp = () => {
|
||||
export const MarketplaceApp = () => {
|
||||
return (
|
||||
<SelloutThemeProvider>
|
||||
<MarketplaceThemeProvider>
|
||||
<AppWrapper id="sellout-app">
|
||||
<SelloutTitle />
|
||||
<MarketplaceTitle />
|
||||
<AppContent>
|
||||
<Switch>
|
||||
<Route path="/sellout" exact component={SelloutListContainer} />
|
||||
<Route path="/sellout/new" component={ListingFormContainer} />
|
||||
<Route path="/marketplace" exact component={MarketplaceListContainer} />
|
||||
<Route path="/marketplace/new" component={ListingFormContainer} />
|
||||
</Switch>
|
||||
</AppContent>
|
||||
<NavigationBar />
|
||||
</AppWrapper>
|
||||
</SelloutThemeProvider>
|
||||
</MarketplaceThemeProvider>
|
||||
);
|
||||
};
|
||||
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'SELLOUT',
|
||||
method: 'setListings',
|
||||
method: MarketplaceEvents.SEND_LISTING,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Some guy',
|
||||
number: '111-1134',
|
||||
title: 'Car',
|
||||
description: 'Selling this cool car',
|
||||
title: 'eeeeeeeeeeeeeeeeeeeeeeeee',
|
||||
description:
|
||||
'skldfsdEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE',
|
||||
url: 'https://beta.iodine.gg/706Y3.jpeg',
|
||||
},
|
||||
{
|
||||
+1
-1
@@ -20,7 +20,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
export const SelloutTitle = () => {
|
||||
export const MarketplaceTitle = () => {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Paper className={classes.root} square variant="outlined" elevation={24}>
|
||||
+5
-4
@@ -1,7 +1,7 @@
|
||||
import { Box, Tooltip, Button } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
import React from 'react';
|
||||
import { 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 ReportIcon from '@material-ui/icons/Report';
|
||||
@@ -10,6 +10,7 @@ import PhoneIcon from '@material-ui/icons/Phone';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router';
|
||||
import { CallEvents } from '../../../../../../typings/call';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
icon: {
|
||||
@@ -24,17 +25,17 @@ export const ListingActions = ({ listing }: { listing: MarketplaceListing }) =>
|
||||
const history = useHistory();
|
||||
|
||||
const handleDeleteListing = () => {
|
||||
Nui.send('phone:marketplaceDeleteListing', {
|
||||
Nui.send(MarketplaceEvents.DELETE_LISTING, {
|
||||
id: listing.id,
|
||||
});
|
||||
};
|
||||
|
||||
const handleReportListing = () => {
|
||||
Nui.send('phone:reportListing', listing);
|
||||
Nui.send(MarketplaceEvents.REPORT_LISTING, listing);
|
||||
};
|
||||
|
||||
const handleCall = () => {
|
||||
Nui.send('phone:beginCall', {
|
||||
Nui.send(CallEvents.INITIALIZE_CALL, {
|
||||
number: listing.number,
|
||||
});
|
||||
};
|
||||
+10
-2
@@ -31,9 +31,17 @@ const useStyles = makeStyles((theme) => ({
|
||||
background: theme.palette.background.default,
|
||||
marginBottom: 20,
|
||||
},
|
||||
listingContent: {
|
||||
padding: 10,
|
||||
minWidth: 100,
|
||||
maxWidth: '100%',
|
||||
width: '100%',
|
||||
overflowWrap: 'break-word',
|
||||
wordWrap: 'break-word',
|
||||
},
|
||||
}));
|
||||
|
||||
export const SelloutItem = (listing: MarketplaceListing) => {
|
||||
export const MarketplaceItem = (listing: MarketplaceListing) => {
|
||||
const classes = useStyles();
|
||||
|
||||
return (
|
||||
@@ -62,7 +70,7 @@ export const SelloutItem = (listing: MarketplaceListing) => {
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
<Typography variant="h6" style={{ padding: 10 }}>
|
||||
<Typography variant="body1" className={classes.listingContent}>
|
||||
{listing.description}
|
||||
</Typography>
|
||||
<ListingActions listing={listing} />
|
||||
+3
-3
@@ -1,15 +1,15 @@
|
||||
import React from 'react';
|
||||
import { List } from '../../../../ui/components/List';
|
||||
import { useListing } from '../../hooks/useListing';
|
||||
import { SelloutItem } from './SelloutItem';
|
||||
import { MarketplaceItem } from './MarketplaceItem';
|
||||
|
||||
export const SelloutList = () => {
|
||||
export const MarketplaceList = () => {
|
||||
const listings = useListing();
|
||||
|
||||
return (
|
||||
<List>
|
||||
{listings.map((listing) => (
|
||||
<SelloutItem key={listing.id} {...listing} />
|
||||
<MarketplaceItem key={listing.id} {...listing} />
|
||||
))}
|
||||
</List>
|
||||
);
|
||||
@@ -0,0 +1,6 @@
|
||||
import React from 'react';
|
||||
import { MarketplaceList } from './MarketplaceList';
|
||||
|
||||
export const MarketplaceListContainer = () => {
|
||||
return <MarketplaceList />;
|
||||
};
|
||||
+40
-12
@@ -1,6 +1,10 @@
|
||||
import React, { useState } from 'react';
|
||||
import { makeStyles, Button, TextField } from '@material-ui/core';
|
||||
import { makeStyles, Button, TextField, Typography } from '@material-ui/core';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { MarketplaceEvents } from '../../../../../../typings/marketplace';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -28,17 +32,28 @@ const useStyles = makeStyles((theme) => ({
|
||||
|
||||
export const ListingForm = () => {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { addAlert } = useSnackbar();
|
||||
const history = useHistory();
|
||||
|
||||
const [title, setTitle] = useState('');
|
||||
const [url, setUrl] = useState('');
|
||||
const [description, setDescription] = useState('');
|
||||
|
||||
const addListing = () => {
|
||||
Nui.send('phone:addListing', {
|
||||
title,
|
||||
url,
|
||||
description,
|
||||
});
|
||||
if (title !== '' && description !== '') {
|
||||
Nui.send(MarketplaceEvents.ADD_LISTING, {
|
||||
title,
|
||||
url,
|
||||
description,
|
||||
});
|
||||
history.push('/marketplace');
|
||||
} else {
|
||||
addAlert({
|
||||
message: t('APPS_MARKETPLACE_REQUIRED_FIELDS'),
|
||||
type: 'error',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -47,15 +62,22 @@ export const ListingForm = () => {
|
||||
<TextField
|
||||
className={classes.input}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="Title on listing.."
|
||||
inputProps={{ className: classes.textFieldInput }}
|
||||
label={t('GENERIC_REQUIRED')}
|
||||
placeholder={t('APPS_MARKETPLACE_FORM_TITLE')}
|
||||
inputProps={{
|
||||
className: classes.textFieldInput,
|
||||
maxLength: 25,
|
||||
}}
|
||||
style={{ width: '80%' }}
|
||||
size="medium"
|
||||
InputLabelProps={{
|
||||
shrink: true,
|
||||
}}
|
||||
/>
|
||||
|
||||
<TextField
|
||||
className={classes.input}
|
||||
placeholder="Image URL"
|
||||
placeholder={t('APPS_MARKETPLACE_FORM_IMAGE')}
|
||||
onChange={(e) => setUrl(e.target.value)}
|
||||
inputProps={{ className: classes.textFieldInput }}
|
||||
style={{ width: '80%' }}
|
||||
@@ -66,15 +88,21 @@ export const ListingForm = () => {
|
||||
<TextField
|
||||
className={classes.input}
|
||||
onChange={(e) => setDescription(e.target.value)}
|
||||
placeholder="Description"
|
||||
inputProps={{ className: classes.multilineFieldInput }}
|
||||
label={t('GENERIC_REQUIRED')}
|
||||
placeholder={t('APPS_MARKETPLACE_FORM_DESCRIPTION')}
|
||||
inputProps={{
|
||||
className: classes.multilineFieldInput,
|
||||
maxLength: 130,
|
||||
}}
|
||||
style={{ width: '80%' }}
|
||||
size="medium"
|
||||
InputLabelProps={{
|
||||
shrink: true,
|
||||
}}
|
||||
multiline
|
||||
rows={4}
|
||||
variant="outlined"
|
||||
/>
|
||||
|
||||
<Button onClick={addListing} className={classes.postButton}>
|
||||
Post
|
||||
</Button>
|
||||
File renamed without changes.
+8
-3
@@ -2,8 +2,9 @@ import React, { useState } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faHome } from '@fortawesome/free-solid-svg-icons';
|
||||
import AddCircleIcon from '@material-ui/icons/AddCircle';
|
||||
import HomeIcon from '@material-ui/icons/Home';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -27,8 +28,12 @@ export const NavigationBar = () => {
|
||||
showLabels
|
||||
className={classes.root}
|
||||
>
|
||||
<BottomNavigationAction component={Link} icon={<HomeIcon />} to="/sellout" />
|
||||
<BottomNavigationAction component={Link} icon={<AddCircleIcon />} to="/sellout/new" />
|
||||
<BottomNavigationAction
|
||||
component={Link}
|
||||
icon={<FontAwesomeIcon icon={faHome} />}
|
||||
to="/marketplace"
|
||||
/>
|
||||
<BottomNavigationAction component={Link} icon={<AddCircleIcon />} to="/marketplace/new" />
|
||||
</BottomNavigation>
|
||||
);
|
||||
};
|
||||
File renamed without changes.
File renamed without changes.
+4
-3
@@ -4,8 +4,9 @@ import { useListing } from './useListing';
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { MarketplaceEvents } from '../../../../../typings/marketplace';
|
||||
|
||||
export const useSelloutService = () => {
|
||||
export const useMarketplaceService = () => {
|
||||
const setSellout = useSetRecoilState(selloutState.listing);
|
||||
const { addAlert } = useSnackbar();
|
||||
const { t } = useTranslation();
|
||||
@@ -17,7 +18,7 @@ export const useSelloutService = () => {
|
||||
});
|
||||
};
|
||||
|
||||
useNuiEvent('SELLOUT', 'setAlert', handleAddAlert);
|
||||
useNuiEvent('SELLOUT', 'setListings', setSellout);
|
||||
useNuiEvent('SELLOUT', MarketplaceEvents.SEND_ALERT, handleAddAlert);
|
||||
useNuiEvent('SELLOUT', MarketplaceEvents.SEND_LISTING, setSellout);
|
||||
return useListing();
|
||||
};
|
||||
File renamed without changes.
@@ -0,0 +1,5 @@
|
||||
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
|
||||
|
||||
import selloutTheme from '../marketplace.theme';
|
||||
|
||||
export const MarketplaceThemeProvider = createAppThemeProvider(selloutTheme);
|
||||
@@ -0,0 +1,163 @@
|
||||
import React, { useState, useRef } from 'react';
|
||||
import { Card, Fab, Box, Tooltip } from '@material-ui/core';
|
||||
import CancelIcon from '@material-ui/icons/Clear';
|
||||
import FireIcon from '@material-ui/icons/Whatshot';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { FormattedProfile } from '../../../../../typings/match';
|
||||
import Draggable from './Draggable';
|
||||
import StatusDisplay from './StatusDisplay';
|
||||
import Profile from './profile/Profile';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
position: 'absolute',
|
||||
margin: '15px 15px 25px 15px',
|
||||
height: 'calc(100% - 90px)',
|
||||
width: 'calc(100% - 30px)',
|
||||
overflow: 'hidden',
|
||||
cursor: 'pointer',
|
||||
},
|
||||
media: {
|
||||
height: '60%',
|
||||
},
|
||||
content: {
|
||||
height: '40%',
|
||||
},
|
||||
status: {
|
||||
position: 'absolute',
|
||||
zIndex: 20,
|
||||
padding: '5px 15px',
|
||||
top: 40,
|
||||
fontSize: '28px',
|
||||
fontWeight: 'bold',
|
||||
},
|
||||
statusVisible: {
|
||||
transition: 'opacity 0.25s ease-in-out',
|
||||
},
|
||||
// when a user swipes on a profile we need to hide the transition
|
||||
// otherwise the status will be transitioning out when the next
|
||||
// profile shows up
|
||||
statusNull: {
|
||||
transition: 'opacity 0s',
|
||||
},
|
||||
like: {
|
||||
color: 'green',
|
||||
border: '6px solid green',
|
||||
left: 30,
|
||||
transform: 'rotate(-18deg)',
|
||||
},
|
||||
nope: {
|
||||
color: 'red',
|
||||
border: '6px solid red',
|
||||
right: 30,
|
||||
transform: 'rotate(18deg)',
|
||||
},
|
||||
buttons: {
|
||||
position: 'absolute',
|
||||
bottom: '3px',
|
||||
width: '100%',
|
||||
height: '55px',
|
||||
},
|
||||
button: {
|
||||
margin: '0px 15px',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
profile: FormattedProfile;
|
||||
onSwipe: (id: number, liked: boolean) => void;
|
||||
}
|
||||
|
||||
// this represents how far from the original mouse
|
||||
// click a user has to drag the profile in order for
|
||||
// it to be registered as a like or dislike
|
||||
const DECISION_THRESHOLD_X_px = 150;
|
||||
|
||||
const ActiveProfile = ({ profile, onSwipe }: IProps) => {
|
||||
const c = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [status, setStatus] = useState(null);
|
||||
const statusRef = useRef(null);
|
||||
const idRef = useRef(null);
|
||||
|
||||
// we are reading mutated state from the Draggable element so we
|
||||
// keep track of it using a ref. Without this ref it will appear
|
||||
// from React's point of view that the state is not updating
|
||||
statusRef.current = status;
|
||||
idRef.current = profile.id;
|
||||
|
||||
function onDrag(deltaX: number): void {
|
||||
const hasDecision = status !== null;
|
||||
if (!hasDecision && deltaX > DECISION_THRESHOLD_X_px) {
|
||||
setStatus(true);
|
||||
} else if (!hasDecision && deltaX < -DECISION_THRESHOLD_X_px) {
|
||||
setStatus(false);
|
||||
} else if (deltaX > -DECISION_THRESHOLD_X_px && deltaX < DECISION_THRESHOLD_X_px) {
|
||||
setStatus(null);
|
||||
}
|
||||
}
|
||||
|
||||
// handles when user uses mouse to "swipe", or
|
||||
// more specifically drag the card to one side or the other
|
||||
const handleSwipe = () => {
|
||||
onSwipe(idRef.current, statusRef.current);
|
||||
setStatus(null);
|
||||
};
|
||||
|
||||
// these handlers are explicit and used for when the
|
||||
// user clicks on buttons
|
||||
const handleLike = () => {
|
||||
onSwipe(idRef.current, true);
|
||||
setStatus(null);
|
||||
};
|
||||
const handleNope = () => {
|
||||
onSwipe(idRef.current, false);
|
||||
setStatus(null);
|
||||
};
|
||||
|
||||
const isLiked = status === true;
|
||||
const notLiked = status === false;
|
||||
|
||||
const likeClass = `${c.status} ${isLiked ? c.statusVisible : c.statusNull} ${c.like}`;
|
||||
const nopeClass = `${c.status} ${notLiked ? c.statusVisible : c.statusNull} ${c.nope}`;
|
||||
|
||||
return (
|
||||
<>
|
||||
<Draggable id="active-profile" onDrag={onDrag} onDrop={handleSwipe}>
|
||||
<Card raised className={c.root}>
|
||||
<StatusDisplay className={likeClass} text={t('APPS_MATCH_LIKED')} visible={isLiked} />
|
||||
<StatusDisplay className={nopeClass} text={t('APPS_MATCH_NOPE')} visible={notLiked} />
|
||||
<Profile profile={profile} />
|
||||
</Card>
|
||||
</Draggable>
|
||||
<Box className={c.buttons} display="flex" justifyContent="center">
|
||||
<Tooltip title={t('APPS_MATCH_DISLIKE')} aria-label="dislike">
|
||||
<Fab
|
||||
size="large"
|
||||
color="secondary"
|
||||
aria-label="dislike"
|
||||
onClick={handleNope}
|
||||
className={c.button}
|
||||
>
|
||||
<CancelIcon />
|
||||
</Fab>
|
||||
</Tooltip>
|
||||
<Tooltip title={t('APPS_MATCH_LIKE')} aria-label="like">
|
||||
<Fab
|
||||
size="large"
|
||||
color="primary"
|
||||
aria-label="like"
|
||||
onClick={handleLike}
|
||||
className={c.button}
|
||||
>
|
||||
<FireIcon />
|
||||
</Fab>
|
||||
</Tooltip>
|
||||
</Box>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default ActiveProfile;
|
||||
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { BottomNavigation, BottomNavigationAction } from '@material-ui/core';
|
||||
import HomeIcon from '@material-ui/icons/Whatshot';
|
||||
import GroupIcon from '@material-ui/icons/Group';
|
||||
import ProfileIcon from '@material-ui/icons/Person';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
width: '100%',
|
||||
},
|
||||
});
|
||||
|
||||
export function MatchBottomNavigation({ activePage, handleChange }) {
|
||||
const classes = useStyles();
|
||||
|
||||
console.log(activePage);
|
||||
|
||||
return (
|
||||
<BottomNavigation value={activePage} onChange={handleChange} className={classes.root}>
|
||||
<BottomNavigationAction component={Link} to="/match" icon={<HomeIcon />} />
|
||||
<BottomNavigationAction component={Link} to="/match/matches" icon={<GroupIcon />} />
|
||||
<BottomNavigationAction component={Link} to="/match/profile" icon={<ProfileIcon />} />
|
||||
</BottomNavigation>
|
||||
);
|
||||
}
|
||||
|
||||
export default MatchBottomNavigation;
|
||||
@@ -0,0 +1,61 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { makeStyles } from '@material-ui/core';
|
||||
|
||||
import { LikeorDislikeDraggableElement } from '../utils/drag';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
position: 'relative',
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
},
|
||||
like: {
|
||||
position: 'absolute',
|
||||
zIndex: 20,
|
||||
padding: '5px 15px',
|
||||
top: 100,
|
||||
|
||||
color: 'green',
|
||||
border: '4px solid green',
|
||||
right: 15,
|
||||
},
|
||||
nope: {
|
||||
position: 'absolute',
|
||||
zIndex: 20,
|
||||
padding: '5px 15px',
|
||||
top: 100,
|
||||
|
||||
color: 'red',
|
||||
border: '4px solid red',
|
||||
left: 15,
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
id: string;
|
||||
children: JSX.Element | JSX.Element[];
|
||||
onDrag: (deltaX: number) => void;
|
||||
onDrop: () => void;
|
||||
}
|
||||
|
||||
const MAX_ROTATION_DEG = 15;
|
||||
|
||||
function Draggable({ id, children, onDrag, onDrop }: IProps) {
|
||||
const classes = useStyles();
|
||||
const elementRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const drag = new LikeorDislikeDraggableElement(elementRef, MAX_ROTATION_DEG, onDrag, onDrop);
|
||||
return () => drag.cleanup();
|
||||
}, [elementRef]); // eslint-disable-line
|
||||
|
||||
return (
|
||||
<>
|
||||
<div ref={elementRef} key={id} id={id} className={classes.root}>
|
||||
{children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default Draggable;
|
||||
@@ -0,0 +1,28 @@
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, Typography } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
root: {
|
||||
color: theme.palette.primary.main,
|
||||
fontSize: theme.typography.fontSize,
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
paddingTop: '140px',
|
||||
},
|
||||
}));
|
||||
|
||||
function NoProfiles() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<Typography variant="h5">{t('APPS_MATCH_NO_PROFILES')}</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default NoProfiles;
|
||||
@@ -0,0 +1,26 @@
|
||||
import React from 'react';
|
||||
import { Box, CircularProgress } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
},
|
||||
progress: {
|
||||
marginTop: '140px',
|
||||
},
|
||||
});
|
||||
|
||||
function Loader() {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<CircularProgress size={60} className={classes.progress} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default Loader;
|
||||
@@ -0,0 +1,158 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Route } from 'react-router-dom';
|
||||
|
||||
import { AppWrapper } from '../../../ui/components';
|
||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { MatchThemeProvider } from '../providers/MatchThemeProvider';
|
||||
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import MatchBottomNavigation from '../components/BottomNavigation';
|
||||
import MatchPage from './views/MatchPage';
|
||||
import ProfileEditor from './views/ProfileEditor';
|
||||
import MatchList from './views/MatchList';
|
||||
import { MatchEvents } from '../../../../../typings/match';
|
||||
import { useProfile } from '../hooks/useProfile';
|
||||
|
||||
export const MatchApp = () => {
|
||||
const match = useApp('MATCH');
|
||||
const [activePage, setActivePage] = useState(0);
|
||||
const { noProfileExists } = useProfile();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send(MatchEvents.INITIALIZE);
|
||||
}, []);
|
||||
|
||||
const handlePageChange = (e, page) => setActivePage(page);
|
||||
|
||||
return (
|
||||
<MatchThemeProvider>
|
||||
<AppWrapper id="contact-app">
|
||||
<AppTitle app={match} />
|
||||
{noProfileExists ? (
|
||||
<AppContent>
|
||||
<ProfileEditor />
|
||||
</AppContent>
|
||||
) : (
|
||||
<>
|
||||
<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>
|
||||
</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,31 @@
|
||||
import React from 'react';
|
||||
import { Box, Typography } from '@material-ui/core';
|
||||
import { makeStyles, Theme } from '@material-ui/core/styles';
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => ({
|
||||
root: {
|
||||
color: theme.palette.primary.main,
|
||||
fontSize: theme.typography.fontSize,
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
textAlign: 'center',
|
||||
padding: '140px 15px 15px 15px',
|
||||
},
|
||||
}));
|
||||
|
||||
interface IProps {
|
||||
text: string;
|
||||
}
|
||||
|
||||
function PageText({ text }: IProps) {
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<Typography variant="h5">{text}</Typography>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default PageText;
|
||||
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import { Box } from '@material-ui/core';
|
||||
|
||||
function StatusDisplay({ className, visible, text }) {
|
||||
const style = { opacity: visible ? '0.65' : '0.0' };
|
||||
|
||||
return (
|
||||
<Box className={className} style={style}>
|
||||
{text}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default StatusDisplay;
|
||||
@@ -0,0 +1,62 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
import { Box, Button, ListItem, makeStyles } from '@material-ui/core';
|
||||
import PersonIcon from '@material-ui/icons/Person';
|
||||
import ChatIcon from '@material-ui/icons/Chat';
|
||||
|
||||
import { FormattedMatch } from '../../../../../../typings/match';
|
||||
import Profile from '../profile/Profile';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
profile: {
|
||||
position: 'relative',
|
||||
height: '90%',
|
||||
marginTop: '15px',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
match: FormattedMatch;
|
||||
}
|
||||
|
||||
export const Match = ({ match }: IProps) => {
|
||||
const history = useHistory();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [showProfile, setShowProfile] = useState(false);
|
||||
|
||||
const handleMessage = () => {
|
||||
history.push(`/messages/new/${match.phoneNumber}`);
|
||||
};
|
||||
|
||||
const handleProfile = () => {
|
||||
setShowProfile((show) => !show);
|
||||
};
|
||||
|
||||
const secondaryText = t('APPS_MATCH_PROFILE_MATCHED_AT', {
|
||||
matchedAt: match.matchedAtFormatted,
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<ListItem divider>
|
||||
<ListItemText primary={match.name} secondary={secondaryText} />
|
||||
<Button onClick={handleProfile}>
|
||||
<PersonIcon />
|
||||
</Button>
|
||||
<Button onClick={handleMessage}>
|
||||
<ChatIcon />
|
||||
</Button>
|
||||
</ListItem>
|
||||
{showProfile && (
|
||||
<Box className={classes.profile}>
|
||||
<Profile profile={match} />
|
||||
</Box>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Match;
|
||||
@@ -0,0 +1,78 @@
|
||||
import React from 'react';
|
||||
import { CardContent, CardMedia, Chip, Typography } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { FormattedProfile, FormattedMatch } from '../../../../../../typings/match';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {},
|
||||
tags: {
|
||||
position: 'absolute',
|
||||
bottom: '40%',
|
||||
},
|
||||
tag: {
|
||||
margin: '3px 3px 0px 0px',
|
||||
opacity: '0.8',
|
||||
},
|
||||
media: {
|
||||
height: '60%',
|
||||
},
|
||||
content: {
|
||||
height: '40%',
|
||||
overflowY: 'auto',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
profile: FormattedProfile | FormattedMatch;
|
||||
}
|
||||
|
||||
const DEFAULT_IMAGE = 'https://upload.wikimedia.org/wikipedia/commons/a/ac/No_image_available.svg';
|
||||
|
||||
const Profile = ({ profile }: IProps) => {
|
||||
const c = useStyles();
|
||||
const { t } = useTranslation();
|
||||
|
||||
function parseSecondaryBio(): string | undefined {
|
||||
const { location, job } = profile;
|
||||
if (location && job) {
|
||||
return `${location} - ${job}`;
|
||||
} else if (location) {
|
||||
return location;
|
||||
} else if (job) {
|
||||
return job;
|
||||
}
|
||||
}
|
||||
|
||||
const bioSecondary = parseSecondaryBio();
|
||||
|
||||
return (
|
||||
<>
|
||||
<CardContent className={c.tags}>
|
||||
{profile.tagList.map((tag) => (
|
||||
<Chip className={c.tag} label={tag} color="primary" />
|
||||
))}
|
||||
</CardContent>
|
||||
<CardMedia className={c.media} image={profile.image || DEFAULT_IMAGE} title={profile.name} />
|
||||
<CardContent className={c.content}>
|
||||
<Typography gutterBottom variant="h4" component="h2">
|
||||
{profile.name}
|
||||
</Typography>
|
||||
<Typography gutterBottom color="textSecondary" component="p">
|
||||
{t('APPS_MATCH_PROFILE_LAST_ACTIVE', { lastActive: profile.lastActiveFormatted })}
|
||||
</Typography>
|
||||
{bioSecondary && (
|
||||
<Typography gutterBottom variant="body1" color="textSecondary" component="p">
|
||||
{bioSecondary}
|
||||
</Typography>
|
||||
)}
|
||||
<Typography variant="body2" color="textSecondary" component="p">
|
||||
{profile.bio}
|
||||
</Typography>
|
||||
</CardContent>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Profile;
|
||||
@@ -0,0 +1,128 @@
|
||||
import React, { useState } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import {
|
||||
Profile as IProfile,
|
||||
FormattedProfile,
|
||||
MatchEvents,
|
||||
} from '../../../../../../typings/match';
|
||||
import ProfileField from '../../../../ui/components/ProfileField';
|
||||
import UpdateButton from '../../../../ui/components/UpdateButton';
|
||||
import { Card } from '@material-ui/core';
|
||||
import Profile from './Profile';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
import PageText from '../PageText';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
position: 'relative',
|
||||
width: '100%',
|
||||
height: 'calc(100% - 40px)',
|
||||
padding: '15px',
|
||||
},
|
||||
card: {
|
||||
position: 'absolute',
|
||||
margin: '15px 15px 25px 15px',
|
||||
height: 'calc(100% - 80px)',
|
||||
width: 'calc(100% - 30px)',
|
||||
overflow: 'hidden',
|
||||
},
|
||||
spacer: {
|
||||
height: '8px',
|
||||
},
|
||||
});
|
||||
|
||||
interface IProps {
|
||||
profile: FormattedProfile;
|
||||
showPreview: boolean;
|
||||
}
|
||||
|
||||
export function ProfileForm({ profile, showPreview }: IProps) {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { config } = usePhone();
|
||||
|
||||
// note that this assumes we are defensively checking
|
||||
// that profile is not null in a parent above this component.
|
||||
// Annoyingling adding conditionals above this line to not render
|
||||
// when profile === null results in a react error that different
|
||||
// amounts of hooks are rendering
|
||||
const [image, setImage] = useState(profile?.image || '');
|
||||
const [name, setName] = useState(profile?.name || '');
|
||||
const [bio, setBio] = useState(profile?.bio || '');
|
||||
const [job, setJob] = useState(profile?.job || '');
|
||||
const [location, setLocation] = useState(profile?.location || '');
|
||||
const [tags, setTags] = useState(profile?.tags || '');
|
||||
|
||||
const update: FormattedProfile = {
|
||||
...profile,
|
||||
image,
|
||||
name,
|
||||
bio,
|
||||
location,
|
||||
job,
|
||||
tagList: tags.split(',').map((tag) => tag.trim()),
|
||||
};
|
||||
|
||||
const handleUpdate = () => {
|
||||
const updatedProfile: IProfile = {
|
||||
...update,
|
||||
name: update.name.trim(),
|
||||
image: update.image.trim(),
|
||||
tags: update.tagList.join(','),
|
||||
};
|
||||
const event = profile ? MatchEvents.UPDATE_MY_PROFILE : MatchEvents.CREATE_MY_PROFILE;
|
||||
Nui.send(event, updatedProfile);
|
||||
};
|
||||
|
||||
if (!profile && !config.match.allowEdtiableProfileName) {
|
||||
return <PageText text={t('APPS_MATCH_PROFILE_CONFIGURATION')} />;
|
||||
}
|
||||
|
||||
if (showPreview) {
|
||||
return (
|
||||
<Card raised className={classes.card}>
|
||||
<Profile profile={update} />
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_IMAGE')}
|
||||
value={update.image}
|
||||
handleChange={setImage}
|
||||
allowChange
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_NAME')}
|
||||
value={name}
|
||||
handleChange={setName}
|
||||
allowChange={config.match.allowEdtiableProfileName}
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_BIO')}
|
||||
value={update.bio}
|
||||
handleChange={setBio}
|
||||
multiline
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_LOCATION')}
|
||||
value={update.location}
|
||||
handleChange={setLocation}
|
||||
/>
|
||||
<ProfileField
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_JOB')}
|
||||
value={update.job}
|
||||
handleChange={setJob}
|
||||
/>
|
||||
<ProfileField label={t('APPS_MATCH_EDIT_PROFILE_TAGS')} value={tags} handleChange={setTags} />
|
||||
<UpdateButton handleClick={handleUpdate} loading={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProfileForm;
|
||||
@@ -0,0 +1,52 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, makeStyles } from '@material-ui/core';
|
||||
|
||||
import { useMatches } from '../../hooks/useMatches';
|
||||
import Loader from '../Loader';
|
||||
import PageText from '../PageText';
|
||||
import Match from '../matches/Match';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { MatchEvents } from '../../../../../../typings/match';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
},
|
||||
});
|
||||
|
||||
const MINIMUM_LOAD_TIME = 1500;
|
||||
|
||||
function MatchList() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
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 (!loaded || !matches) return <Loader />;
|
||||
if (matches.length === 0) return <PageText text={t('APPS_MATCH_NO_MATCHES')} />;
|
||||
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
{matches.map((match) => (
|
||||
<Match key={match.id} match={match} />
|
||||
))}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default MatchList;
|
||||
@@ -0,0 +1,53 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Paper } from '@material-ui/core';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { useProfiles } from '../../hooks/useProfiles';
|
||||
import Loader from '../Loader';
|
||||
import PageText from '../PageText';
|
||||
import ActiveProfile from '../ActiveProfile';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
overflow: 'hidden',
|
||||
},
|
||||
});
|
||||
|
||||
// set a minimum load time so the user doesn't see a flash
|
||||
// of the loader and then the matches themselves
|
||||
const MINIMUM_LOAD_TIME = 1250;
|
||||
|
||||
const MatchPage = () => {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { profiles, error, activeProfile, setViewed } = useProfiles();
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
window.setTimeout(() => {
|
||||
setLoaded(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
}, []);
|
||||
|
||||
const handleSwipe = (id: number, liked: boolean) => {
|
||||
// the user didn't choose (didn't swipe far enough)
|
||||
if (liked === null) return;
|
||||
|
||||
setViewed(id, liked);
|
||||
};
|
||||
|
||||
if (error) return <PageText text={t('APPS_MATCH_PROFILES_ERROR')} />;
|
||||
if (!loaded || !profiles) return <Loader />;
|
||||
if (!activeProfile) return <PageText text={t('APPS_MATCH_NO_PROFILES')} />;
|
||||
|
||||
return (
|
||||
<Paper className={classes.root} square>
|
||||
<ActiveProfile profile={activeProfile} onSwipe={handleSwipe} />
|
||||
</Paper>
|
||||
);
|
||||
};
|
||||
|
||||
export default MatchPage;
|
||||
@@ -0,0 +1,45 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Box, FormControlLabel, Switch } from '@material-ui/core';
|
||||
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
import Loader from '../Loader';
|
||||
import ProfileForm from '../profile/ProfileForm';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
},
|
||||
switch: {
|
||||
marginLeft: '15px',
|
||||
},
|
||||
});
|
||||
|
||||
function ProfileEditor() {
|
||||
const { profile, noProfileExists } = useProfile();
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const [showPreview, setShowPreview] = useState(false);
|
||||
|
||||
const toggleSwitch = () => {
|
||||
setShowPreview((preview) => !preview);
|
||||
};
|
||||
|
||||
if (!profile && !noProfileExists) return <Loader />;
|
||||
|
||||
return (
|
||||
<Box className={classes.root}>
|
||||
<Box className={classes.switch}>
|
||||
<FormControlLabel
|
||||
control={<Switch checked={showPreview} onChange={toggleSwitch} />}
|
||||
label={t('APPS_MATCH_EDIT_PROFILE_PREVIEW')}
|
||||
/>
|
||||
</Box>
|
||||
<ProfileForm showPreview={showPreview} profile={profile} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProfileEditor;
|
||||
@@ -0,0 +1,28 @@
|
||||
import { atom } from 'recoil';
|
||||
|
||||
export const matchState = {
|
||||
profiles: atom({
|
||||
key: 'profiles',
|
||||
default: null,
|
||||
}),
|
||||
errorLoadingProfiles: atom({
|
||||
key: 'errorLoadingProfiles',
|
||||
default: false,
|
||||
}),
|
||||
matches: atom({
|
||||
key: 'matches',
|
||||
default: null,
|
||||
}),
|
||||
errorLoadingMatches: atom({
|
||||
key: 'errorLoadingMatches',
|
||||
default: false,
|
||||
}),
|
||||
myProfile: atom({
|
||||
key: 'myProfile',
|
||||
default: null,
|
||||
}),
|
||||
noProfileExists: atom({
|
||||
key: 'noProfileExists',
|
||||
default: false,
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,86 @@
|
||||
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 {};
|
||||
};
|
||||
@@ -0,0 +1,15 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { matchState } from './state';
|
||||
|
||||
import { FormattedMatch } from '../../../../../typings/match';
|
||||
|
||||
interface IUseMatches {
|
||||
matches: FormattedMatch[];
|
||||
error: boolean;
|
||||
}
|
||||
|
||||
export const useMatches = (): IUseMatches => {
|
||||
const matches = useRecoilValue<FormattedMatch[]>(matchState.matches);
|
||||
const error = useRecoilValue(matchState.errorLoadingMatches);
|
||||
return { matches, error };
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { matchState } from './state';
|
||||
|
||||
import { FormattedProfile } from '../../../../../typings/match';
|
||||
|
||||
interface IUseProfiles {
|
||||
profile: FormattedProfile;
|
||||
setProfile: (profile: FormattedProfile) => void;
|
||||
noProfileExists: boolean;
|
||||
}
|
||||
|
||||
export const useProfile = (): IUseProfiles => {
|
||||
const [profile, setProfile] = useRecoilState<FormattedProfile>(matchState.myProfile);
|
||||
const noProfileExists = useRecoilValue(matchState.noProfileExists);
|
||||
return { profile, setProfile, noProfileExists };
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { matchState } from './state';
|
||||
|
||||
import { FormattedProfile, MatchEvents } from '../../../../../typings/match';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
|
||||
interface IUseProfiles {
|
||||
profiles: FormattedProfile[];
|
||||
activeProfile: FormattedProfile | null;
|
||||
setViewed: (index: number, liked: boolean) => void;
|
||||
error: boolean;
|
||||
}
|
||||
|
||||
export const useProfiles = (): IUseProfiles => {
|
||||
const [profiles, setProfiles] = useRecoilState(matchState.profiles);
|
||||
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 activeProfile = profiles ? filteredProfiles[0] : null;
|
||||
|
||||
return { profiles, activeProfile, error, setViewed };
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
import { red, common } from '@material-ui/core/colors';
|
||||
|
||||
export const MATCH_APP_PRIMARY_COLOR = '#FE3B73';
|
||||
export const MATCH_APP_TEXT_COLOR = common.white;
|
||||
|
||||
const theme = {
|
||||
palette: {
|
||||
primary: {
|
||||
main: MATCH_APP_PRIMARY_COLOR,
|
||||
dark: red[700],
|
||||
light: red[300],
|
||||
contrastText: MATCH_APP_TEXT_COLOR,
|
||||
},
|
||||
secondary: {
|
||||
main: '#d32f2f',
|
||||
light: '#eb4242',
|
||||
dark: '#941212',
|
||||
contrastText: MATCH_APP_TEXT_COLOR,
|
||||
},
|
||||
success: {
|
||||
main: '#2196f3',
|
||||
contrastText: MATCH_APP_TEXT_COLOR,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default theme;
|
||||
@@ -0,0 +1,5 @@
|
||||
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
|
||||
|
||||
import matchTheme from '../match.theme';
|
||||
|
||||
export const MatchThemeProvider = createAppThemeProvider(matchTheme);
|
||||
@@ -0,0 +1,161 @@
|
||||
interface IDeltas {
|
||||
deltaX: number;
|
||||
deltaY: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a React ref, which should point to some HTML element,
|
||||
* add draggable functionality to that element so the user can
|
||||
* interact with it.
|
||||
*
|
||||
* It should be noted that when using this in React that this
|
||||
* class is directly mutating the DOM, not relying on React state
|
||||
* to do so. This can cause some problems when relying on React
|
||||
* state updates based on the values derived from this class. That
|
||||
* is why we primarily use refs to interact with it.
|
||||
*
|
||||
* Order of operations:
|
||||
* 1. User clicks "down" on element - this initializes event
|
||||
* handlers and saves initial state
|
||||
* 2. User moves mouse. Every mouse move event triggers a movement
|
||||
* of the HTML element and also performs some logic to see how far
|
||||
* we have moved
|
||||
* 3. User "releases" mouse - cleanup event handlers and do logic
|
||||
* to compare our final position to our initial position
|
||||
*/
|
||||
export class DraggableElement {
|
||||
private element: HTMLElement;
|
||||
|
||||
private width: number = 0;
|
||||
private initialX: number = 0;
|
||||
private initialY: number = 0;
|
||||
private mouseDownInitialX: number = 0;
|
||||
private mouseDownInitialY: number = 0;
|
||||
|
||||
private useRotation: boolean;
|
||||
private maxRotationDeg: null | number;
|
||||
|
||||
private updatedX: number = 0;
|
||||
private updatedY: number = 0;
|
||||
private mouseDownX: number = 0;
|
||||
private mouseDownY: number = 0;
|
||||
|
||||
constructor(ref: React.MutableRefObject<any>, maxRotationDeg: number | null = null) {
|
||||
this.element = ref.current;
|
||||
this.width = this.element.clientWidth;
|
||||
this.maxRotationDeg = maxRotationDeg;
|
||||
this.useRotation = maxRotationDeg !== null;
|
||||
|
||||
this.element.onmousedown = this.onMouseDown;
|
||||
}
|
||||
|
||||
onMouseDown = (e: MouseEvent): void => {
|
||||
e.preventDefault();
|
||||
// get the mouse cursor position at startup:
|
||||
this.mouseDownX = e.clientX;
|
||||
this.mouseDownY = e.clientY;
|
||||
|
||||
// save where we initially started dragging from
|
||||
// so we can do some math later
|
||||
this.mouseDownInitialX = this.mouseDownX;
|
||||
this.mouseDownInitialY = this.mouseDownY;
|
||||
|
||||
document.onmouseup = this.onMouseUp;
|
||||
// call a function whenever the cursor moves:
|
||||
document.onmousemove = this.onMouseMove;
|
||||
};
|
||||
|
||||
onMouseMove = (e: MouseEvent): void => {
|
||||
e.preventDefault();
|
||||
const x = e.clientX;
|
||||
const y = e.clientY;
|
||||
this._onMouseMove(x, y);
|
||||
};
|
||||
|
||||
_onMouseMove = (x: number, y: number): void => {
|
||||
// calculate the new cursor position:
|
||||
this.updatedX = this.mouseDownX - x;
|
||||
this.updatedY = this.mouseDownY - y;
|
||||
this.mouseDownX = x;
|
||||
this.mouseDownY = y;
|
||||
|
||||
// set the element's new position:
|
||||
this.element.style.top = this.element.offsetTop - this.updatedY + 'px';
|
||||
this.element.style.left = this.element.offsetLeft - this.updatedX + 'px';
|
||||
|
||||
if (this.useRotation) {
|
||||
const { deltaX } = this.deltas(this.mouseDownX, this.mouseDownY);
|
||||
const pctWidth = deltaX / this.width;
|
||||
const rotationDeg = -1 * this.maxRotationDeg * pctWidth;
|
||||
|
||||
this.element.style.webkitTransform = `rotate(${rotationDeg}deg)`;
|
||||
}
|
||||
};
|
||||
|
||||
onMouseUp = (e: MouseEvent): void => {
|
||||
e.preventDefault();
|
||||
this._onMouseUp();
|
||||
};
|
||||
|
||||
_onMouseUp = (): void => {
|
||||
// stop moving when mouse button is released:
|
||||
this.cleanup();
|
||||
|
||||
// revert back to intitial position
|
||||
this.element.style.left = `${this.initialX}px`;
|
||||
this.element.style.top = `${this.initialY}px`;
|
||||
if (this.useRotation) {
|
||||
this.element.style.webkitTransform = 'rotate(0deg)';
|
||||
}
|
||||
};
|
||||
|
||||
cleanup = (): void => {
|
||||
document.onmouseup = null;
|
||||
document.onmousemove = null;
|
||||
};
|
||||
|
||||
deltas = (x: number, y: number): IDeltas => {
|
||||
const deltaX = x - this.mouseDownInitialX;
|
||||
const deltaY = y - this.mouseDownInitialX;
|
||||
return { deltaX, deltaY };
|
||||
};
|
||||
}
|
||||
|
||||
type StatusChange = (deltaX: number) => void;
|
||||
|
||||
/**
|
||||
* This class adds hooks to the base DraggableElement class
|
||||
* so we can update application state based on events
|
||||
*/
|
||||
export class LikeorDislikeDraggableElement extends DraggableElement {
|
||||
private onDrag: StatusChange;
|
||||
private onDrop: () => void;
|
||||
|
||||
constructor(
|
||||
ref: React.MutableRefObject<any>,
|
||||
maxRotationDeg: number,
|
||||
onDrag: StatusChange,
|
||||
onDrop: () => void,
|
||||
) {
|
||||
super(ref, maxRotationDeg);
|
||||
|
||||
this.onDrag = onDrag;
|
||||
this.onDrop = onDrop;
|
||||
}
|
||||
|
||||
onMouseMove = (e: MouseEvent): void => {
|
||||
e.preventDefault();
|
||||
const x = e.clientX;
|
||||
const y = e.clientY;
|
||||
|
||||
const { deltaX } = this.deltas(x, y);
|
||||
|
||||
this.onDrag(deltaX);
|
||||
this._onMouseMove(x, y);
|
||||
};
|
||||
|
||||
onMouseUp = (): void => {
|
||||
this.onDrop();
|
||||
this._onMouseUp();
|
||||
};
|
||||
}
|
||||
@@ -11,13 +11,14 @@ import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import NewMessageGroupButton from './form/NewMessageGroupButton';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { MessagesThemeProvider } from '../providers/MessagesThemeProvider';
|
||||
import { MessageEvents } from '../../../../../typings/messages';
|
||||
|
||||
export const MessagesApp = () => {
|
||||
const messages = useApp('MESSAGES');
|
||||
const history = useHistory();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send('phone:fetchMessageGroups');
|
||||
Nui.send(MessageEvents.FETCH_MESSAGE_GROUPS);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
@@ -52,7 +53,7 @@ export const MessagesApp = () => {
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'MESSAGES',
|
||||
method: 'phone:fetchMessageGroupsSuccess',
|
||||
method: MessageEvents.FETCH_MESSAGE_GROUPS_SUCCESS,
|
||||
data: [
|
||||
{
|
||||
groupId: '2',
|
||||
@@ -92,7 +93,7 @@ InjectDebugData(
|
||||
[
|
||||
{
|
||||
app: 'MESSAGES',
|
||||
method: 'phone:fetchMessagesSuccess',
|
||||
method: MessageEvents.FETCH_MESSAGES_SUCCESS,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Paper, Box, makeStyles, TextField, Button } from '@material-ui/core';
|
||||
import SendIcon from '@material-ui/icons/Send';
|
||||
import ImageIcon from '@material-ui/icons/Image';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { MessageEvents } from '../../../../../../typings/messages';
|
||||
|
||||
interface IProps {
|
||||
onAddImageClick(): void;
|
||||
@@ -25,7 +26,7 @@ const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
|
||||
if (message.trim()) {
|
||||
// don't allow the user to submit white space
|
||||
|
||||
Nui.send('phone:sendMessage', {
|
||||
Nui.send(MessageEvents.SEND_MESSAGE, {
|
||||
groupId: messageGroupId,
|
||||
message,
|
||||
});
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import React, { FormEvent, useCallback, useEffect, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Box, Button, TextField } from '@material-ui/core';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { Autocomplete } from '@material-ui/lab';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { Contact } from '../../../../../../typings/contact';
|
||||
import { MessageEvents } from '../../../../../../typings/messages';
|
||||
import { PHONE_NUMBER_REGEX } from '../../../../../../typings/phone';
|
||||
import { useSnackbar } from '../../../../ui/hooks/useSnackbar';
|
||||
|
||||
const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
const { addAlert } = useSnackbar();
|
||||
const [participants, setParticipants] = useState([]);
|
||||
const [label, setLabel] = useState('');
|
||||
const { getContactByNumber, contacts } = useContacts();
|
||||
@@ -24,31 +27,30 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
|
||||
const isGroupChat = participants.length > 1;
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
(event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
const handleSubmit = useCallback(() => {
|
||||
// handles phone numbers in a csv format and strips all spaces and
|
||||
// external characters out of them:
|
||||
// 123-4567, 987-6543, 333-4444
|
||||
const phoneNumbers = participants.map(({ number }) => number.replace(/[^0-9]/g, ''));
|
||||
const labelValue = isGroupChat ? label.trim() : null;
|
||||
|
||||
// handles phone numbers in a csv format and strips all spaces and
|
||||
// external characters out of them:
|
||||
// 123-4567, 987-6543, 333-4444
|
||||
const phoneNumbers = participants.map(({ number }) => number.replace(/[^0-9]/g, ''));
|
||||
const labelValue = isGroupChat ? label.trim() : null;
|
||||
|
||||
if (phoneNumbers.length) {
|
||||
Nui.send('phone:createMessageGroup', {
|
||||
phoneNumbers,
|
||||
label: labelValue,
|
||||
});
|
||||
setParticipants([]);
|
||||
history.push('/messages');
|
||||
}
|
||||
},
|
||||
[history, label, participants, isGroupChat],
|
||||
);
|
||||
if (phoneNumbers.length) {
|
||||
Nui.send(MessageEvents.CREATE_MESSAGE_GROUP, {
|
||||
phoneNumbers,
|
||||
label: labelValue,
|
||||
});
|
||||
setParticipants([]);
|
||||
history.push('/messages');
|
||||
}
|
||||
}, [history, label, participants, isGroupChat]);
|
||||
|
||||
const onAutocompleteChange = (_e, value: any) => {
|
||||
const lastIdx = value.length - 1;
|
||||
if (typeof value[lastIdx] === 'string') {
|
||||
const isValid = PHONE_NUMBER_REGEX.test(value[lastIdx]);
|
||||
if (!isValid) {
|
||||
return addAlert({ message: t('APPS_MESSAGES_INVALID_PHONE_NUMBER'), type: 'error' });
|
||||
}
|
||||
value.splice(lastIdx, 1, { number: value[lastIdx] });
|
||||
setParticipants(value);
|
||||
return;
|
||||
@@ -77,7 +79,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
const submitDisabled = !participants.length || (isGroupChat && !label);
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<Box>
|
||||
<Box px={2} py={3}>
|
||||
<Autocomplete<Contact, boolean, boolean, boolean>
|
||||
value={participants}
|
||||
@@ -102,6 +104,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
)}
|
||||
<Box px={2} py={3}>
|
||||
<Button
|
||||
onClick={() => handleSubmit()}
|
||||
disabled={submitDisabled}
|
||||
variant="contained"
|
||||
fullWidth
|
||||
@@ -111,7 +114,7 @@ const NewMessageGroupForm = ({ phoneNumber }: { phoneNumber?: string }) => {
|
||||
{t('APPS_MESSAGES_NEW_MESSAGE_GROUP_SUBMIT')}
|
||||
</Button>
|
||||
</Box>
|
||||
</form>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const MessageGroupItem = ({ messageGroup, handleClick }: IProps): any => {
|
||||
<ListItem key={messageGroup.groupId} onClick={handleClick(messageGroup)} divider button>
|
||||
<ListItemAvatar>
|
||||
<Badge color="error" variant="dot" invisible={!hasUnread}>
|
||||
<MuiAvatar src={messageGroup?.avatar} />
|
||||
<MuiAvatar src={messageGroup.avatar} />
|
||||
</Badge>
|
||||
</ListItemAvatar>
|
||||
<ListItemText>{messageGroup.label || messageGroup.groupDisplay}</ListItemText>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Box, List } from '@material-ui/core';
|
||||
import { MessageGroup } from '../../../../../../typings/messages';
|
||||
import { MessageEvents, MessageGroup } from '../../../../../../typings/messages';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import useMessages from '../../hooks/useMessages';
|
||||
import MessageGroupItem from './MessageGroupItem';
|
||||
@@ -15,7 +15,13 @@ const MessagesList = (): any => {
|
||||
const history = useHistory();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { messageGroups, createMessageGroupResult, clearMessageGroupResult } = useMessages();
|
||||
const {
|
||||
messageGroups,
|
||||
createMessageGroupResult,
|
||||
clearMessageGroupResult,
|
||||
getMessageGroupById,
|
||||
setActiveMessageGroup,
|
||||
} = useMessages();
|
||||
|
||||
const [searchValue, setSearchValue] = useState('');
|
||||
|
||||
@@ -32,18 +38,24 @@ const MessagesList = (): any => {
|
||||
|
||||
useEffect(() => {
|
||||
if (createMessageGroupResult?.groupId) {
|
||||
const findGroup = messageGroups.find((g) => g.groupId === createMessageGroupResult.groupId);
|
||||
const findGroup = getMessageGroupById(createMessageGroupResult.groupId);
|
||||
clearMessageGroupResult();
|
||||
if (findGroup) {
|
||||
goToConversation(findGroup, history);
|
||||
}
|
||||
}
|
||||
}, [messageGroups, createMessageGroupResult, clearMessageGroupResult, history]);
|
||||
}, [
|
||||
messageGroups,
|
||||
createMessageGroupResult,
|
||||
clearMessageGroupResult,
|
||||
history,
|
||||
setActiveMessageGroup,
|
||||
getMessageGroupById,
|
||||
]);
|
||||
|
||||
if (!messageGroups) return null;
|
||||
|
||||
const handleClick = (messageGroup: MessageGroup) => () => {
|
||||
Nui.send('phone:fetchMessages', { groupId: messageGroup.groupId });
|
||||
goToConversation(messageGroup, history);
|
||||
};
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useHistory, useLocation } from 'react-router-dom';
|
||||
import { ContextMenu } from '../../../../ui/components/ContextMenu';
|
||||
import { deleteQueryFromLocation } from '../../../../common/utils/deleteQueryFromLocation';
|
||||
import { PictureResponsive } from '../../../../ui/components/PictureResponsive';
|
||||
import { MessageEvents } from '../../../../../../typings/messages';
|
||||
|
||||
interface IProps {
|
||||
isOpen: boolean;
|
||||
@@ -34,7 +35,7 @@ export const MessageImageModal = ({ isOpen, messageGroupId, onClose, image }: IP
|
||||
|
||||
const sendImageMessage = useCallback(
|
||||
(m) => {
|
||||
Nui.send('phone:sendMessage', {
|
||||
Nui.send(MessageEvents.SEND_MESSAGE, {
|
||||
groupId: messageGroupId,
|
||||
message: m,
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import Modal from '../../../../ui/components/Modal';
|
||||
import { useContacts } from '../../../contacts/hooks/useContacts';
|
||||
import { useSimcard } from '../../../../os/simcard/hooks/useSimcard';
|
||||
import { MessageEvents } from '../../../../../../typings/messages';
|
||||
|
||||
const LARGE_HEADER_CHARS = 30;
|
||||
const MAX_HEADER_CHARS = 80;
|
||||
@@ -77,7 +78,6 @@ export const MessageModal = () => {
|
||||
|
||||
useEffect(() => {
|
||||
if (!groupId) return;
|
||||
|
||||
setActiveMessageGroup(groupId);
|
||||
}, [groupId, setActiveMessageGroup]);
|
||||
|
||||
@@ -93,7 +93,7 @@ export const MessageModal = () => {
|
||||
// sends all unread messages
|
||||
useEffect(() => {
|
||||
if (activeMessageGroup?.groupId && activeMessageGroup.unreadCount > 0) {
|
||||
Nui.send('phone:setReadMessages', {
|
||||
Nui.send(MessageEvents.SET_MESSAGE_READ, {
|
||||
groupId: activeMessageGroup.groupId,
|
||||
});
|
||||
}
|
||||
@@ -109,10 +109,11 @@ export const MessageModal = () => {
|
||||
|
||||
const handleAddContact = (number) => {
|
||||
const exists = getContactByNumber(number);
|
||||
const referal = encodeURIComponent(pathname);
|
||||
if (exists) {
|
||||
return history.push(`/contacts/${exists.id}/?referal=${pathname}`);
|
||||
return history.push(`/contacts/${exists.id}/?referal=${referal}`);
|
||||
}
|
||||
return history.push(`/contacts/-1/?addNumber=${number}&referal=${pathname}`);
|
||||
return history.push(`/contacts/-1/?addNumber=${number}&referal=${referal}`);
|
||||
};
|
||||
|
||||
const phoneNumbers = activeMessageGroup?.phoneNumbers || [];
|
||||
@@ -157,14 +158,14 @@ export const MessageModal = () => {
|
||||
</Button>
|
||||
) : null}
|
||||
{!activeMessageGroup?.isGroupChat &&
|
||||
getDisplayByNumber(targetNumber) == targetNumber ? (
|
||||
getDisplayByNumber(targetNumber) === targetNumber ? (
|
||||
<Button>
|
||||
<PersonAddIcon onClick={() => handleAddContact(targetNumber)} fontSize="large" />
|
||||
</Button>
|
||||
) : null}
|
||||
</Box>
|
||||
</Paper>
|
||||
{isLoaded ? (
|
||||
{isLoaded && activeMessageGroup ? (
|
||||
<Conversation
|
||||
onClickDisplay={handleAddContact}
|
||||
messages={messages}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { matchPath, useHistory } from 'react-router-dom';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
|
||||
import { goToConversation } from '../utils/goToConversation';
|
||||
@@ -10,13 +11,22 @@ const NOTIFICATION_ID = 'messages:broadcast';
|
||||
export const useMessageNotifications = () => {
|
||||
const { t } = useTranslation();
|
||||
const history = useHistory();
|
||||
const {
|
||||
removeId,
|
||||
addNotification,
|
||||
addNotificationAlert,
|
||||
} = useNotifications();
|
||||
const { removeId, addNotification, addNotificationAlert } = useNotifications();
|
||||
const { icon, notificationIcon } = useApp('MESSAGES');
|
||||
const { getMessageGroupById } = useMessages();
|
||||
const { getMessageGroupById, activeMessageGroup } = useMessages();
|
||||
|
||||
// Remove notifications from groups when opening them
|
||||
history.listen((location) => {
|
||||
if (
|
||||
activeMessageGroup?.groupId &&
|
||||
matchPath(location.pathname, {
|
||||
path: `/messages/conversations/${activeMessageGroup.groupId}`,
|
||||
exact: true,
|
||||
})
|
||||
) {
|
||||
removeId(`${NOTIFICATION_ID}:${activeMessageGroup.groupId}`);
|
||||
}
|
||||
});
|
||||
|
||||
const setNotification = ({ groupId, message }) => {
|
||||
const group = getMessageGroupById(groupId);
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useRecoilState, useSetRecoilState } from 'recoil';
|
||||
import { messageState } from './state';
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useMessageNotifications } from './useMessageNotifications';
|
||||
import { useCallback } from 'react';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useLocation } from 'react-router';
|
||||
import { MessageEvents } from '../../../../../typings/messages';
|
||||
import { TOptionsBase } from 'i18next';
|
||||
|
||||
export const useMessagesService = () => {
|
||||
const { pathname } = useLocation();
|
||||
const [activeMessageGroup, setActiveMessageGroup] = useRecoilState(
|
||||
messageState.activeMessageGroup,
|
||||
);
|
||||
const setMessageGroups = useSetRecoilState(messageState.messageGroups);
|
||||
const setMessages = useSetRecoilState(messageState.messages);
|
||||
const setCreateMessageGroupResult = useSetRecoilState(messageState.createMessageGroupResult);
|
||||
@@ -15,19 +23,45 @@ export const useMessagesService = () => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleAddAlert = useCallback(
|
||||
({ message, type }: IAlert) => {
|
||||
({ message, type, options = {} }: IAlert & { options: TOptionsBase }) => {
|
||||
addAlert({
|
||||
message: t(`APPS_${message}`),
|
||||
message: t(`${message}`, options),
|
||||
type,
|
||||
});
|
||||
},
|
||||
[addAlert, t],
|
||||
);
|
||||
|
||||
useNuiEvent('MESSAGES', 'phone:fetchMessageGroupsSuccess', setMessageGroups);
|
||||
useNuiEvent('MESSAGES', 'phone:fetchMessagesSuccess', setMessages);
|
||||
useNuiEvent('MESSAGES', 'phone:createMessageGroupSuccess', setCreateMessageGroupResult);
|
||||
useNuiEvent('MESSAGES', 'phone:createMessageGroupFailed', setCreateMessageGroupResult);
|
||||
useNuiEvent('MESSAGES', 'createMessagesBroadcast', setNotification);
|
||||
useNuiEvent('MESSAGES', 'phone:setMessagesAlert', handleAddAlert);
|
||||
const handleMessageBroadcast = useCallback(
|
||||
({ groupId, message }) => {
|
||||
if (groupId === activeMessageGroup?.groupId) {
|
||||
Nui.send(MessageEvents.FETCH_MESSAGES, { groupId: activeMessageGroup.groupId });
|
||||
if (pathname.includes('messages/conversations')) {
|
||||
// Dont trigger notification if conversation is open.
|
||||
return;
|
||||
}
|
||||
}
|
||||
setNotification({ groupId, message });
|
||||
},
|
||||
[activeMessageGroup, pathname, setNotification],
|
||||
);
|
||||
|
||||
const _setMessageGroups = useCallback(
|
||||
(groups) => {
|
||||
if (activeMessageGroup && activeMessageGroup.groupId) {
|
||||
setActiveMessageGroup(
|
||||
(curr) => groups.find((g) => g.groupId === activeMessageGroup.groupId) || curr,
|
||||
);
|
||||
}
|
||||
setMessageGroups(groups);
|
||||
},
|
||||
[activeMessageGroup, setActiveMessageGroup, setMessageGroups],
|
||||
);
|
||||
|
||||
useNuiEvent('MESSAGES', MessageEvents.FETCH_MESSAGE_GROUPS_SUCCESS, _setMessageGroups);
|
||||
useNuiEvent('MESSAGES', MessageEvents.FETCH_MESSAGES_SUCCESS, setMessages);
|
||||
useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_GROUP_SUCCESS, setCreateMessageGroupResult);
|
||||
useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_GROUP_FAILED, setCreateMessageGroupResult);
|
||||
useNuiEvent('MESSAGES', MessageEvents.CREATE_MESSAGE_BROADCAST, handleMessageBroadcast);
|
||||
useNuiEvent('MESSAGES', MessageEvents.ACTION_RESULT, handleAddAlert);
|
||||
};
|
||||
@@ -1,2 +1,8 @@
|
||||
export const goToConversation = (messageGroup, history) =>
|
||||
import { MessageEvents } from '../../../../../typings/messages';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
|
||||
export const goToConversation = (messageGroup, history) => {
|
||||
if (!messageGroup?.groupId || !history) return;
|
||||
history.push(`/messages/conversations/${messageGroup.groupId}`);
|
||||
Nui.send(MessageEvents.FETCH_MESSAGES, { groupId: messageGroup.groupId });
|
||||
};
|
||||
@@ -12,6 +12,7 @@ import useStyles from './notes.styles';
|
||||
import InjectDebugData from '../../os/debug/InjectDebugData';
|
||||
import { NotesThemeProvider } from './providers/NotesThemeProvider';
|
||||
import { Route, useHistory } from 'react-router-dom';
|
||||
import { NotesEvents } from '../../../../typings/notes';
|
||||
|
||||
export const NotesApp = () => {
|
||||
const classes = useStyles();
|
||||
@@ -43,7 +44,7 @@ export const NotesApp = () => {
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'NOTES',
|
||||
method: 'setNotes',
|
||||
method: NotesEvents.SEND_NOTE,
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { noteStates } from './state';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { NotesEvents } from '../../../../../typings/notes';
|
||||
|
||||
export const useNotesService = () => {
|
||||
const { addAlert } = useSnackbar();
|
||||
@@ -16,6 +17,6 @@ export const useNotesService = () => {
|
||||
});
|
||||
};
|
||||
|
||||
useNuiEvent('NOTES', 'setNotes', setNotes);
|
||||
useNuiEvent('NOTES', 'setAlert', handleAddAlert);
|
||||
useNuiEvent('NOTES', NotesEvents.SEND_NOTE, setNotes);
|
||||
useNuiEvent('NOTES', NotesEvents.SEND_ALERT, handleAddAlert);
|
||||
};
|
||||
@@ -16,6 +16,7 @@ import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { StatusButton } from '../../../ui/components/StatusButton';
|
||||
import { NotesEvents } from '../../../../../typings/notes';
|
||||
|
||||
export const NoteModal = () => {
|
||||
const classes = useStyles();
|
||||
@@ -31,14 +32,14 @@ export const NoteModal = () => {
|
||||
};
|
||||
|
||||
const handleNoteSave = () => {
|
||||
Nui.send('phone:addNote', detail);
|
||||
Nui.send(NotesEvents.ADD_NOTE, detail);
|
||||
setDetail(null);
|
||||
onClose();
|
||||
};
|
||||
|
||||
const handleDeleteNote = () => {
|
||||
const id = detail.id;
|
||||
Nui.send('phone:deleteNote', {
|
||||
Nui.send(NotesEvents.DELETE_NOTE, {
|
||||
id,
|
||||
});
|
||||
setDetail(null);
|
||||
@@ -46,7 +47,7 @@ export const NoteModal = () => {
|
||||
};
|
||||
|
||||
const handleUpdateNote = () => {
|
||||
Nui.send('phone:updateNote', detail);
|
||||
Nui.send(NotesEvents.UPDATE_NOTE, detail);
|
||||
setDetail(null);
|
||||
onClose();
|
||||
};
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import React from 'react';
|
||||
import { SelloutList } from './SelloutList';
|
||||
|
||||
export const SelloutListContainer = () => {
|
||||
return <SelloutList />;
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
import { createAppThemeProvider } from '../../../os/apps/utils/createAppThemeProvider';
|
||||
|
||||
import selloutTheme from '../sellout.theme';
|
||||
|
||||
export const SelloutThemeProvider = createAppThemeProvider(selloutTheme);
|
||||
@@ -10,7 +10,10 @@ import {
|
||||
Tooltip,
|
||||
Typography,
|
||||
Switch,
|
||||
TextField,
|
||||
} from '@material-ui/core';
|
||||
import CreateIcon from '@material-ui/icons/Create';
|
||||
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
|
||||
|
||||
interface ISettingItem {
|
||||
options?: any;
|
||||
@@ -106,3 +109,15 @@ export const SettingItemIconAction = ({
|
||||
</ListItem>
|
||||
</>
|
||||
);
|
||||
|
||||
export const SettingItemModal = ({ icon, label, secondary, onClick }) => (
|
||||
<ListItem divider>
|
||||
<ListItemIcon>{icon}</ListItemIcon>
|
||||
<ListItemText primary={label} secondary={secondary} />
|
||||
<ListItemSecondaryAction>
|
||||
<IconButton onClick={onClick}>
|
||||
<CreateIcon />
|
||||
</IconButton>
|
||||
</ListItemSecondaryAction>
|
||||
</ListItem>
|
||||
);
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { AppWrapper } from '../../../ui/components';
|
||||
import { AppTitle } from '../../../ui/components/AppTitle';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
SettingItemIconAction,
|
||||
SettingItemSlider,
|
||||
SettingSwitch,
|
||||
SettingItemModal,
|
||||
} from './SettingItem';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import VisibilityOffIcon from '@material-ui/icons/VisibilityOff';
|
||||
@@ -26,12 +27,15 @@ import {
|
||||
VolumeUp,
|
||||
FileCopy,
|
||||
Book,
|
||||
DeleteForever,
|
||||
} from '@material-ui/icons';
|
||||
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { ListSubheader } from '@material-ui/core';
|
||||
import { useSettings } from '../hooks/useSettings';
|
||||
import { useCustomWallpaperModal, useResetSettings, useSettings } from '../hooks/useSettings';
|
||||
import { setClipboard } from '../../../os/phone/hooks/useClipboard';
|
||||
import { useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { IContextMenuOption } from '../../../ui/components/ContextMenu';
|
||||
import WallpaperModal from './WallpaperModal';
|
||||
|
||||
const SubHeaderComp = (props: { text: string }) => (
|
||||
<ListSubheader color="primary" component="div" disableSticky>
|
||||
@@ -39,15 +43,31 @@ const SubHeaderComp = (props: { text: string }) => (
|
||||
</ListSubheader>
|
||||
);
|
||||
|
||||
const useStyles = makeStyles({
|
||||
backgroundModal: {
|
||||
background: 'black',
|
||||
opacity: '0.6',
|
||||
position: 'absolute',
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
zIndex: 5,
|
||||
},
|
||||
});
|
||||
|
||||
export const SettingsApp = () => {
|
||||
const settingsApp = useApp('SETTINGS');
|
||||
const [config] = useConfig();
|
||||
const simcard = useSimcard();
|
||||
const [settings, setSettings] = useSettings();
|
||||
const { t } = useTranslation();
|
||||
const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal();
|
||||
|
||||
const { addAlert } = useSnackbar();
|
||||
|
||||
const resetSettings = useResetSettings();
|
||||
|
||||
const handleSettingChange = (key: string | number, value: unknown) => {
|
||||
setSettings({ ...settings, [key]: value });
|
||||
};
|
||||
@@ -91,6 +111,23 @@ export const SettingsApp = () => {
|
||||
MapSettingItem(settings.language, (val: SettingOption) => handleSettingChange('language', val)),
|
||||
);
|
||||
|
||||
const handleResetOptions = () => {
|
||||
resetSettings();
|
||||
addAlert({
|
||||
message: t('SETTINGS.MESSAGES.SETTINGS_RESET'),
|
||||
type: 'success',
|
||||
});
|
||||
};
|
||||
|
||||
const resetSettingsOpts: IContextMenuOption[] = [
|
||||
{
|
||||
selected: false,
|
||||
onClick: () => handleResetOptions(),
|
||||
key: 'RESET_SETTINGS',
|
||||
label: t('SETTINGS.OPTIONS.RESET_SETTINGS'),
|
||||
},
|
||||
];
|
||||
|
||||
const handleCopyPhoneNumber = () => {
|
||||
setClipboard(simcard.number);
|
||||
addAlert({
|
||||
@@ -102,9 +139,12 @@ export const SettingsApp = () => {
|
||||
};
|
||||
|
||||
const [openMenu, closeMenu, ContextMenu, isMenuOpen] = useContextMenu();
|
||||
const classes = useStyles();
|
||||
return (
|
||||
<AppWrapper>
|
||||
<AppTitle app={settingsApp} />
|
||||
<WallpaperModal />
|
||||
<div className={customWallpaperModal ? classes.backgroundModal : undefined} />
|
||||
<AppContent backdrop={isMenuOpen} onClickBackdrop={closeMenu}>
|
||||
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.PHONE')} />}>
|
||||
<SettingItemIconAction
|
||||
@@ -173,6 +213,13 @@ export const SettingsApp = () => {
|
||||
onClick={openMenu}
|
||||
icon={<Wallpaper />}
|
||||
/>
|
||||
{/* CUSTOM BACKGROUND */}
|
||||
<SettingItemModal
|
||||
icon={<Wallpaper />}
|
||||
label={t('APPS_SETTINGS_OPTIONS_CUSTOM_WALLPAPER')}
|
||||
secondary={settings.customWallpaper}
|
||||
onClick={() => setCustomWallpaperModal(true)}
|
||||
/>
|
||||
<SettingItem
|
||||
label={t('APPS_SETTINGS_OPTION_FRAME')}
|
||||
value={settings.frame.label}
|
||||
@@ -210,6 +257,15 @@ export const SettingsApp = () => {
|
||||
icon={<VolumeUp />}
|
||||
/>
|
||||
</List>
|
||||
<List disablePadding subheader={<SubHeaderComp text={t('SETTINGS.CATEGORY.ACTIONS')} />}>
|
||||
<SettingItem
|
||||
label={t('SETTINGS.OPTIONS.RESET_SETTINGS')}
|
||||
value={`${t('SETTINGS.OPTIONS.RESET_SETTINGS_DESC')}`}
|
||||
icon={<DeleteForever />}
|
||||
onClick={openMenu}
|
||||
options={resetSettingsOpts}
|
||||
/>
|
||||
</List>
|
||||
</AppContent>
|
||||
<ContextMenu />
|
||||
</AppWrapper>
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import React, { useState } from 'react';
|
||||
import Modal from '../../../ui/components/Modal';
|
||||
import { useCustomWallpaperModal, useSettings } from '../hooks/useSettings';
|
||||
import { Box, Button, TextField } from '@material-ui/core';
|
||||
import { PictureThumbnail } from '../../../ui/components/PictureThumbnail';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { StatusButton } from '../../../ui/components/StatusButton';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
input: {
|
||||
marginTop: 10,
|
||||
marginBottom: 10,
|
||||
},
|
||||
inputProps: {
|
||||
fontSize: 18,
|
||||
},
|
||||
});
|
||||
|
||||
export default function WallpaperModal() {
|
||||
const { customWallpaperModal, setCustomWallpaperModal } = useCustomWallpaperModal();
|
||||
const [settings, setSettings] = useSettings();
|
||||
const { t } = useTranslation();
|
||||
const [value, setValue] = useState(settings.customWallpaper ? settings.customWallpaper : '');
|
||||
const classes = useStyles();
|
||||
|
||||
const isImage = (url) => {
|
||||
return /(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|png|jpeg|gif)/g.test(url);
|
||||
};
|
||||
|
||||
const handleCloseModal = () => {
|
||||
setCustomWallpaperModal(false);
|
||||
};
|
||||
|
||||
const handleSettingChange = (key: string | number, value: unknown) => {
|
||||
setSettings({ ...settings, [key]: value });
|
||||
};
|
||||
|
||||
const handleNewWallpaper = () => {
|
||||
handleSettingChange('customWallpaper', value);
|
||||
};
|
||||
|
||||
const handleRemoveWallpaper = () => {
|
||||
handleSettingChange('customWallpaper', '');
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal visible={customWallpaperModal} handleClose={handleCloseModal}>
|
||||
<Box
|
||||
display="flex"
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
textAlign="center"
|
||||
flexDirection="column"
|
||||
>
|
||||
{settings.customWallpaper && (
|
||||
<PictureThumbnail src={settings.customWallpaper} alt="chipisbest" />
|
||||
)}
|
||||
<TextField
|
||||
value={value}
|
||||
variant="outlined"
|
||||
className={classes.input}
|
||||
onChange={(e) => setValue(e.currentTarget.value)}
|
||||
inputProps={{
|
||||
className: classes.inputProps,
|
||||
}}
|
||||
placeholder="Image URL"
|
||||
/>
|
||||
<Button
|
||||
color="primary"
|
||||
variant="contained"
|
||||
disabled={!isImage(value)}
|
||||
onClick={handleNewWallpaper}
|
||||
style={{ marginBottom: 10 }}
|
||||
>
|
||||
{t('APPS_SETTINGS_SET_CUSTOM_WALLPAPER')}
|
||||
</Button>
|
||||
{settings.customWallpaper && (
|
||||
<StatusButton color="error" variant="contained" onClick={handleRemoveWallpaper}>
|
||||
{t('GENERIC_DELETE')}
|
||||
</StatusButton>
|
||||
)}
|
||||
</Box>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -1,33 +1,70 @@
|
||||
import { atom, DefaultValue, SetterOrUpdater, useRecoilState } from 'recoil';
|
||||
|
||||
import { atom, DefaultValue, useRecoilState, useResetRecoilState } from 'recoil';
|
||||
import { SETTINGS_ALL_TWEETS, SETTING_MENTIONS } from '../../../../../typings/twitter';
|
||||
import config from '../../../config/default.json';
|
||||
import { SettingOption } from '../../../ui/hooks/useContextMenu';
|
||||
import { Schema, Validator } from 'jsonschema';
|
||||
|
||||
const localStorageEffect = (key) => ({ setSelf, onSet }) => {
|
||||
const savedVal = localStorage.getItem(key);
|
||||
if (savedVal != null) {
|
||||
setSelf(JSON.parse(savedVal));
|
||||
}
|
||||
const NPWD_STORAGE_KEY = 'npwd_settings';
|
||||
|
||||
onSet((newValue) => {
|
||||
if (newValue instanceof DefaultValue) {
|
||||
localStorage.removeItem(key);
|
||||
} else {
|
||||
localStorage.setItem(key, JSON.stringify(newValue));
|
||||
}
|
||||
});
|
||||
const v = new Validator();
|
||||
|
||||
const settingOptionSchema: Schema = {
|
||||
id: '/SettingOption',
|
||||
type: 'object',
|
||||
properties: {
|
||||
label: { type: 'string' },
|
||||
val: { type: 'string' },
|
||||
},
|
||||
required: true,
|
||||
};
|
||||
|
||||
export const settingsState = atom({
|
||||
key: 'settings',
|
||||
default: config.defaultSettings,
|
||||
effects_UNSTABLE: [localStorageEffect('npwd_settings')],
|
||||
});
|
||||
const settingsSchema: Schema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
language: { $ref: '/SettingOption' },
|
||||
wallpaper: { $ref: '/SettingOption' },
|
||||
customWallpaper: { type: 'string' },
|
||||
frame: { $ref: '/SettingOption' },
|
||||
theme: { $ref: '/SettingOption' },
|
||||
zoom: { $ref: '/SettingOption' },
|
||||
streamerMode: { type: 'boolean' },
|
||||
ringtone: { $ref: '/SettingOption' },
|
||||
ringtoneVol: { type: 'number' },
|
||||
notiSound: { $ref: '/SettingOption' },
|
||||
notiSoundVol: { type: 'number' },
|
||||
TWITTER_notiFilter: { $ref: '/SettingOption' },
|
||||
TWITTER_notiSound: { $ref: '/SettingOption' },
|
||||
TWITTER_notiSoundVol: { type: 'number' },
|
||||
TWITTER_notifyNewFeedTweet: { type: 'boolean' },
|
||||
},
|
||||
required: true,
|
||||
};
|
||||
|
||||
v.addSchema(settingOptionSchema, '/SettingOption');
|
||||
|
||||
function isSchemaValid(schema: string): boolean {
|
||||
const storedSettings = JSON.parse(schema);
|
||||
const resp = v.validate(storedSettings, settingsSchema);
|
||||
return resp.valid;
|
||||
}
|
||||
|
||||
export function isSettingsSchemaValid(): boolean {
|
||||
const localStore = localStorage.getItem(NPWD_STORAGE_KEY);
|
||||
if (localStore) {
|
||||
try {
|
||||
const parsedSettings = JSON.parse(localStore);
|
||||
return v.validate(parsedSettings, settingsSchema).valid;
|
||||
} catch (e) {
|
||||
console.error('Unable to parse settings JSON', e);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export interface IPhoneSettings {
|
||||
language: SettingOption;
|
||||
wallpaper: SettingOption;
|
||||
customWallpaper: string;
|
||||
frame: SettingOption;
|
||||
theme: SettingOption;
|
||||
zoom: SettingOption;
|
||||
@@ -42,6 +79,53 @@ export interface IPhoneSettings {
|
||||
TWITTER_notifyNewFeedTweet: boolean;
|
||||
}
|
||||
|
||||
export const useSettings = (): [IPhoneSettings, SetterOrUpdater<any>] => {
|
||||
const localStorageEffect = (key) => ({ setSelf, onSet }) => {
|
||||
const savedVal = localStorage.getItem(key);
|
||||
if (savedVal) {
|
||||
try {
|
||||
const validString = isSchemaValid(savedVal);
|
||||
if (validString) {
|
||||
setSelf(JSON.parse(savedVal));
|
||||
} else {
|
||||
console.error('Settings Schema was invalid, applying default settings');
|
||||
setSelf(config.defaultSettings);
|
||||
}
|
||||
} catch (e) {
|
||||
// If we are unable to parse the json string, we set default settings
|
||||
console.error('Unable to parse JSON');
|
||||
setSelf(config.defaultSettings);
|
||||
}
|
||||
}
|
||||
|
||||
onSet((newValue) => {
|
||||
if (newValue instanceof DefaultValue) {
|
||||
localStorage.removeItem(key);
|
||||
} else {
|
||||
localStorage.setItem(key, JSON.stringify(newValue));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const settingsState = atom({
|
||||
key: 'settings',
|
||||
default: config.defaultSettings,
|
||||
effects_UNSTABLE: [localStorageEffect(NPWD_STORAGE_KEY)],
|
||||
});
|
||||
|
||||
const customWallpaperState = atom({
|
||||
key: 'customWallpaperState',
|
||||
default: false,
|
||||
});
|
||||
|
||||
export const useSettings = () => {
|
||||
return useRecoilState(settingsState);
|
||||
};
|
||||
|
||||
export const useResetSettings = () => {
|
||||
return useResetRecoilState(settingsState);
|
||||
};
|
||||
|
||||
export const useCustomWallpaperModal = () => {
|
||||
const [customWallpaperModal, setCustomWallpaperModal] = useRecoilState(customWallpaperState);
|
||||
return { customWallpaperModal, setCustomWallpaperModal };
|
||||
};
|
||||
@@ -1,4 +1,3 @@
|
||||
export const getRingtonePath = (name?: string) => `./media/ringtones/${name || 'pixel'}.ogg`;
|
||||
export const getRingtonePath = (name?: string) => `media/ringtones/${name || 'pixel'}.ogg`;
|
||||
|
||||
export const getNotificationPath = (name?: string) =>
|
||||
`./media/notifications/${name || 'online'}.ogg`;
|
||||
export const getNotificationPath = (name?: string) => `media/notifications/${name || 'online'}.ogg`;
|
||||
@@ -15,7 +15,7 @@ import ControlButtons from './buttons/ControlButtons';
|
||||
import IconButtons from './buttons/IconButtons';
|
||||
import { usePhone } from '../../../os/phone/hooks/usePhone';
|
||||
import { getNewLineCount } from '../utils/message';
|
||||
import { NewTweet } from '../../../../../typings/twitter';
|
||||
import { NewTweet, TwitterEvents } from '../../../../../typings/twitter';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -110,7 +110,7 @@ export const AddTweetModal = () => {
|
||||
images:
|
||||
images && images.length > 0 ? images.map((image) => image.link).join(IMAGE_DELIMITER) : '',
|
||||
};
|
||||
Nui.send('phone:createTweet', data);
|
||||
Nui.send(TwitterEvents.CREATE_TWEET, data);
|
||||
_handleClose();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState } from 'react';
|
||||
import { Switch, Route } from 'react-router-dom';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import { AppWrapper } from '../../../ui/components';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import TweetListContainer from './tweet/TweetListContainer';
|
||||
@@ -20,6 +19,7 @@ import { useProfile } from '../hooks/useProfile';
|
||||
import ProfilePrompt from './profile/ProfilePrompt';
|
||||
import InjectDebugData from '../../../os/debug/InjectDebugData';
|
||||
import { TwitterThemeProvider } from '../providers/TwitterThemeProvider';
|
||||
import { TwitterEvents } from '../../../../../typings/twitter';
|
||||
|
||||
const useStyles = makeStyles(() => ({
|
||||
backgroundModal: {
|
||||
@@ -34,31 +34,15 @@ const useStyles = makeStyles(() => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const TWEETS_REFRESH_RATE = 15000; // TODO move this to twitter config
|
||||
|
||||
export const TwitterApp = () => {
|
||||
const classes = useStyles();
|
||||
const { modalVisible, setModalVisible } = useModal();
|
||||
const [activePage, setActivePage] = useState(0);
|
||||
const { profile } = useProfile();
|
||||
|
||||
useEffect(() => {
|
||||
// this is a polling implementation. It is possible that
|
||||
// there is some interaction where, on a new tweet, all
|
||||
// clients are sent the updated query data. Until that can
|
||||
// be accomplished this is naive but robust.
|
||||
//
|
||||
// TODO don't call fetchTweets - implement a function that only
|
||||
// returns tweets that we don't already have
|
||||
const timeout = window.setTimeout(() => {
|
||||
Nui.send('phone:fetchTweets', {});
|
||||
}, TWEETS_REFRESH_RATE);
|
||||
return () => window.clearTimeout(timeout);
|
||||
}, []);
|
||||
|
||||
// before any other action can be taken by the user we force
|
||||
// them have a profile name
|
||||
const promptProfileName = profile && (!profile.profile_name || !profile.profile_name.trim());
|
||||
// them have a profile name.
|
||||
const promptProfileName = !profile || !profile.profile_name || !profile.profile_name.trim();
|
||||
|
||||
const openModal = () => setModalVisible(true);
|
||||
const handlePageChange = (e, page) => setActivePage(page);
|
||||
@@ -93,7 +77,7 @@ export const TwitterApp = () => {
|
||||
InjectDebugData([
|
||||
{
|
||||
app: 'TWITTER',
|
||||
method: 'getOrCreateTwitterProfile',
|
||||
method: TwitterEvents.GET_OR_CREATE_PROFILE,
|
||||
data: {
|
||||
profile_name: 'Angular_Dev',
|
||||
bio: 'Angular FTW',
|
||||
@@ -104,7 +88,7 @@ InjectDebugData([
|
||||
},
|
||||
{
|
||||
app: 'TWITTER',
|
||||
method: 'fetchTweets',
|
||||
method: TwitterEvents.FETCH_TWEETS,
|
||||
data: [
|
||||
{
|
||||
id: 59,
|
||||
@@ -165,7 +149,7 @@ InjectDebugData(
|
||||
[
|
||||
{
|
||||
app: 'TWITTER',
|
||||
method: 'createTweetBroadcast',
|
||||
method: TwitterEvents.CREATE_TWEET_BROADCAST,
|
||||
data: {
|
||||
id: 111,
|
||||
profile_id: 111,
|
||||
@@ -177,7 +161,7 @@ InjectDebugData(
|
||||
},
|
||||
{
|
||||
app: 'TWITTER',
|
||||
method: 'createTweetBroadcast',
|
||||
method: TwitterEvents.CREATE_TWEET_BROADCAST,
|
||||
data: {
|
||||
id: 111,
|
||||
profile_id: 111,
|
||||
|
||||
@@ -7,6 +7,7 @@ import TweetList from './tweet/TweetList';
|
||||
import Nui from '../../../os/nui-events/utils/Nui';
|
||||
import SearchButton from './buttons/SearchButton';
|
||||
import { useFilteredTweets } from '../hooks/useFilteredTweets';
|
||||
import { TwitterEvents } from '../../../../../typings/twitter';
|
||||
|
||||
const useStyles = makeStyles({
|
||||
root: {
|
||||
@@ -32,7 +33,7 @@ function TwitterSearch() {
|
||||
const cleanedSearchValue = searchValue.trim();
|
||||
if (!cleanedSearchValue) return;
|
||||
|
||||
Nui.send('phone:fetchTweetsFiltered', cleanedSearchValue);
|
||||
Nui.send(TwitterEvents.FETCH_TWEETS_FILTERED, cleanedSearchValue);
|
||||
};
|
||||
|
||||
const filteredTweets = tweets || [];
|
||||
|
||||
@@ -4,6 +4,7 @@ import FavoriteBorderIcon from '@material-ui/icons/FavoriteBorder';
|
||||
import FavoriteIcon from '@material-ui/icons/Favorite';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
const LOADING_TIME = 1250;
|
||||
|
||||
@@ -12,7 +13,7 @@ function LikeButton({ tweetId, isLiked }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleClick = () => {
|
||||
Nui.send('phone:toggleLike', tweetId);
|
||||
Nui.send(TwitterEvents.TOGGLE_LIKE, tweetId);
|
||||
setLoading(true);
|
||||
window.setTimeout(() => {
|
||||
setLiked(!liked);
|
||||
|
||||
@@ -1,45 +1,16 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import { Fab } from '@material-ui/core';
|
||||
import PublishIcon from '@material-ui/icons/Publish';
|
||||
import React from 'react';
|
||||
|
||||
import UpdateButton from '../../../../ui/components/UpdateButton';
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
position: 'absolute',
|
||||
bottom: '15px',
|
||||
right: '15px',
|
||||
},
|
||||
button: {
|
||||
background: '#00acee',
|
||||
},
|
||||
}));
|
||||
interface IProps {
|
||||
handleClick: () => void;
|
||||
}
|
||||
|
||||
const MINIMUM_LOAD_TIME = 750;
|
||||
|
||||
export function ProfileUpdateButton({ handleClick }) {
|
||||
const classes = useStyles();
|
||||
const [minimumLoadPassed, setMimimumLoadPassed] = useState(true);
|
||||
export function ProfileUpdateButton({ handleClick }: IProps) {
|
||||
const { updateProfileLoading } = useProfile();
|
||||
|
||||
useEffect(() => {
|
||||
setMimimumLoadPassed(false);
|
||||
const timeout = window.setTimeout(() => {
|
||||
setMimimumLoadPassed(true);
|
||||
}, MINIMUM_LOAD_TIME);
|
||||
return () => window.clearTimeout(timeout);
|
||||
}, [updateProfileLoading]);
|
||||
|
||||
const isLoading = updateProfileLoading || !minimumLoadPassed;
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<Fab className={classes.button} color="primary" onClick={handleClick} disabled={isLoading}>
|
||||
<PublishIcon />
|
||||
</Fab>
|
||||
</div>
|
||||
);
|
||||
return <UpdateButton loading={updateProfileLoading} handleClick={handleClick} />;
|
||||
}
|
||||
|
||||
export default ProfileUpdateButton;
|
||||
@@ -4,6 +4,7 @@ import { Button, CircularProgress, MenuItem } from '@material-ui/core';
|
||||
import DoneIcon from '@material-ui/icons/Done';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
const LOADING_TIME = 1250;
|
||||
|
||||
@@ -12,7 +13,7 @@ function ReportButton({ handleClose, tweetId, isReported }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleClick = () => {
|
||||
Nui.send('phone:reportTweet', tweetId);
|
||||
Nui.send(TwitterEvents.REPORT, tweetId);
|
||||
setLoading(true);
|
||||
window.setTimeout(() => {
|
||||
setLoading(false);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { CircularProgress, makeStyles, Button } from '@material-ui/core';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faRetweet } from '@fortawesome/free-solid-svg-icons';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
interface IProps {
|
||||
tweetId: number;
|
||||
@@ -33,7 +34,7 @@ export const RetweetButton = ({ tweetId, isRetweet, retweetId }: IProps) => {
|
||||
// if someone is retweeting something that is itself a retweet
|
||||
// then we want to retweet the original post (if we haven't already)
|
||||
const idToRetweet = isRetweet ? retweetId : tweetId;
|
||||
Nui.send('phone:retweet', idToRetweet);
|
||||
Nui.send(TwitterEvents.RETWEET, idToRetweet);
|
||||
setLoading(true);
|
||||
window.setTimeout(() => {
|
||||
setRetweeted(true);
|
||||
|
||||
@@ -7,7 +7,7 @@ const useStyles = makeStyles(() => ({
|
||||
root: {
|
||||
position: 'absolute',
|
||||
bottom: '75px',
|
||||
right: '15px',
|
||||
right: '10px',
|
||||
},
|
||||
button: {
|
||||
background: '#00acee',
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
import React from 'react';
|
||||
import { makeStyles } from '@material-ui/core/styles';
|
||||
import InputLabel from '@material-ui/core/InputLabel';
|
||||
import FormControl from '@material-ui/core/FormControl';
|
||||
import Select from '@material-ui/core/Select';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
|
||||
|
||||
interface IProps {
|
||||
handleUpdate: () => void;
|
||||
profileName: string;
|
||||
setProfileName: (name: string) => void;
|
||||
defaultProfileNames: string[];
|
||||
}
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
position: 'relative',
|
||||
width: '100%',
|
||||
height: '100%',
|
||||
padding: '15px',
|
||||
},
|
||||
formControl: {
|
||||
width: '100%',
|
||||
},
|
||||
}));
|
||||
|
||||
export function DefaultProfilePrompt({
|
||||
profileName,
|
||||
setProfileName,
|
||||
handleUpdate,
|
||||
defaultProfileNames,
|
||||
}: IProps): JSX.Element {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const handleChange = (event: React.ChangeEvent<any>): void => {
|
||||
event.preventDefault();
|
||||
setProfileName(event.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<FormControl className={classes.formControl}>
|
||||
<InputLabel htmlFor="profile-name">
|
||||
{t('APPS_TWITTER_EDIT_DEFAULT_PROFILE_NAME')}
|
||||
</InputLabel>
|
||||
<Select
|
||||
value={profileName}
|
||||
onChange={handleChange}
|
||||
inputProps={{
|
||||
name: 'profileName',
|
||||
id: 'profile-name',
|
||||
}}
|
||||
>
|
||||
<option value="" />
|
||||
{defaultProfileNames.map((name) => (
|
||||
<option key={name} value={name}>
|
||||
{name}
|
||||
</option>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
<ProfileUpdateButton handleClick={handleUpdate} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default DefaultProfilePrompt;
|
||||
@@ -5,9 +5,10 @@ import { useTranslation } from 'react-i18next';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
import Avatar from '../Avatar';
|
||||
import ProfileField from './ProfileField';
|
||||
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
import ProfileField from '../../../../ui/components/ProfileField';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -46,7 +47,7 @@ export function Profile() {
|
||||
location,
|
||||
job,
|
||||
};
|
||||
Nui.send('phone:updateTwitterProfile', data);
|
||||
Nui.send(TwitterEvents.UPDATE_PROFILE, data);
|
||||
};
|
||||
|
||||
// fetching the config is an asynchronous call so defend against it
|
||||
|
||||
@@ -3,9 +3,14 @@ import { makeStyles } from '@material-ui/core/styles';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import ProfileField from '../../../../ui/components/ProfileField';
|
||||
import { useProfile } from '../../hooks/useProfile';
|
||||
import ProfileField from './ProfileField';
|
||||
import ProfileUpdateButton from '../buttons/ProfileUpdateButton';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { twitterState } from '../../hooks/state';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
import DefaultProfilePrompt from './DefaultProfilePrompt';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -23,23 +28,43 @@ export function ProfilePrompt() {
|
||||
const classes = useStyles();
|
||||
const { t } = useTranslation();
|
||||
const { profile } = useProfile();
|
||||
const defaultProfileNames = useRecoilValue(twitterState.defaultProfileNames);
|
||||
const [profileName, setProfileName] = useState(profile?.profile_name || '');
|
||||
const { config } = usePhone();
|
||||
|
||||
const [name, handleNameChange] = useState(profile.profile_name || '');
|
||||
const showDefaultProfileNames = !config.twitter.allowEdtiableProfileName && !profile;
|
||||
const eventName = showDefaultProfileNames
|
||||
? TwitterEvents.CREATE_PROFILE
|
||||
: TwitterEvents.UPDATE_PROFILE;
|
||||
|
||||
const handleUpdate = () => {
|
||||
const data = {
|
||||
Nui.send(eventName, {
|
||||
...profile,
|
||||
profile_name: name,
|
||||
};
|
||||
Nui.send('phone:updateTwitterProfile', data);
|
||||
profile_name: profileName,
|
||||
});
|
||||
};
|
||||
|
||||
// case where profile doesn't exist, couldn't be created automatically
|
||||
// and the player is not allowed to edit their own profile name
|
||||
if (showDefaultProfileNames) {
|
||||
return (
|
||||
<DefaultProfilePrompt
|
||||
profileName={profileName}
|
||||
defaultProfileNames={defaultProfileNames}
|
||||
setProfileName={setProfileName}
|
||||
handleUpdate={handleUpdate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// case where profile doesn't exist, couldn't be created automatically
|
||||
// but the player IS allowed to edit their own profile name
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<ProfileField
|
||||
label={t('APPS_TWITTER_EDIT_PROFILE_NAME')}
|
||||
value={name}
|
||||
handleChange={handleNameChange}
|
||||
value={profileName}
|
||||
handleChange={setProfileName}
|
||||
allowChange
|
||||
/>
|
||||
<ProfileUpdateButton handleClick={handleUpdate} />
|
||||
|
||||
@@ -5,6 +5,7 @@ import MoreIcon from '@material-ui/icons/MoreVert';
|
||||
import { usePhone } from '../../../../os/phone/hooks/usePhone';
|
||||
import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import ReportButton from '../buttons/ReportButton';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
export const ShowMore = ({ id, isReported, isMine }) => {
|
||||
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
|
||||
@@ -23,7 +24,7 @@ export const ShowMore = ({ id, isReported, isMine }) => {
|
||||
};
|
||||
|
||||
const handleDeleteTweet = () => {
|
||||
Nui.send('phone:deleteTweet', id);
|
||||
Nui.send(TwitterEvents.DELETE_TWEET, id);
|
||||
handleClose();
|
||||
};
|
||||
|
||||
@@ -36,7 +37,12 @@ export const ShowMore = ({ id, isReported, isMine }) => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button aria-controls="simple-menu" aria-haspopup="true" onClick={_handleClick}>
|
||||
<Button
|
||||
aria-controls="simple-menu"
|
||||
aria-haspopup="true"
|
||||
onClick={_handleClick}
|
||||
style={{ marginRight: 15 }}
|
||||
>
|
||||
<MoreIcon />
|
||||
</Button>
|
||||
<Menu
|
||||
|
||||
@@ -4,13 +4,14 @@ import Nui from '../../../../os/nui-events/utils/Nui';
|
||||
import { useTweets } from '../../hooks/useTweets';
|
||||
import { useTwitterNotifications } from '../../hooks/useTwitterNotifications';
|
||||
import TweetList from './TweetList';
|
||||
import { TwitterEvents } from '../../../../../../typings/twitter';
|
||||
|
||||
export function TweetListContainer() {
|
||||
const { tweets } = useTweets();
|
||||
const { setUnreadCount } = useTwitterNotifications();
|
||||
|
||||
useEffect(() => {
|
||||
Nui.send('phone:fetchTweets', {});
|
||||
Nui.send(TwitterEvents.FETCH_TWEETS, {});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -5,6 +5,10 @@ export const twitterState = {
|
||||
key: 'profile',
|
||||
default: null,
|
||||
}),
|
||||
defaultProfileNames: atom({
|
||||
key: 'defaultProfileNames',
|
||||
default: null,
|
||||
}),
|
||||
tweets: atom({
|
||||
key: 'tweets',
|
||||
default: null,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { Tweet, Profile } from '../../../../../typings/twitter';
|
||||
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import { useNotifications } from '../../../os/notifications/hooks/useNotifications';
|
||||
@@ -11,7 +12,7 @@ import { twitterState } from './state';
|
||||
const NOTIFICATION_ID = 'twitter:broadcast';
|
||||
|
||||
function isMentioned(profileName: string, message: string) {
|
||||
return !message.toLowerCase().includes(profileName.toLowerCase());
|
||||
return message.toLowerCase().includes(profileName.toLowerCase());
|
||||
}
|
||||
|
||||
export const useTwitterNotifications = () => {
|
||||
@@ -24,14 +25,21 @@ export const useTwitterNotifications = () => {
|
||||
const { icon, notificationIcon } = useApp('TWITTER');
|
||||
|
||||
const [unreadCount, setUnreadCount] = useRecoilState(twitterState.unreadTweetsCount);
|
||||
const profile = useRecoilValue(twitterState.profile);
|
||||
const profile: Profile | null = useRecoilValue(twitterState.profile);
|
||||
|
||||
const setNotification = ({ profile_name, message, isRetweet }) => {
|
||||
const setNotification = ({ profile_name, message, isRetweet }: Tweet) => {
|
||||
const titleStr = isRetweet
|
||||
? 'APPS_TWITTER_NEW_RETWEET_BROADCAST'
|
||||
: 'APPS_TWITTER_NEW_BROADCAST';
|
||||
|
||||
const currentProfileName = profile.profile_name;
|
||||
// profile defaults to null, if for some reason it is not initialized
|
||||
// defend against this case
|
||||
if (!profile) return;
|
||||
|
||||
// Prevents a crash if there is no current profile
|
||||
// set and a Twitter broadcast occurs.
|
||||
const currentProfileName = profile?.profile_name;
|
||||
|
||||
// we don't want notifications of our own tweets
|
||||
if (currentProfileName === profile_name) return;
|
||||
|
||||
@@ -39,7 +47,7 @@ export const useTwitterNotifications = () => {
|
||||
// mentioned in
|
||||
if (
|
||||
settings.TWITTER_notiFilter.value === SETTING_MENTIONS &&
|
||||
isMentioned(currentProfileName, message)
|
||||
!isMentioned(currentProfileName, message)
|
||||
)
|
||||
return;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useSetRecoilState } from 'recoil';
|
||||
import { useRecoilState, useSetRecoilState } from 'recoil';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
@@ -8,13 +8,14 @@ import { twitterState } from './state';
|
||||
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
||||
import { useTwitterNotifications } from './useTwitterNotifications';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Tweet, FormattedTweet, Profile, TwitterEvents } from '../../../../../typings/twitter';
|
||||
|
||||
/**
|
||||
* Perform all necessary processing/transforms from the raw database
|
||||
* data to what the frontend expects
|
||||
* @param {object} tweet - full JSON returned from the server/database
|
||||
*/
|
||||
function processTweet(tweet) {
|
||||
function processTweet(tweet: Tweet): FormattedTweet {
|
||||
// we store images in the database as a varchar field with
|
||||
// comma separated links to images, so here we split them
|
||||
// back into their distinct members
|
||||
@@ -23,6 +24,23 @@ function processTweet(tweet) {
|
||||
return { ...tweet, images };
|
||||
}
|
||||
|
||||
/**
|
||||
* in the case a tweet is broadcasted we can make some assumptions
|
||||
* that it is brand new and hasn't been liked. We should also need
|
||||
* to overwrite isMine since that will be true (sourced from another
|
||||
* player's tweet)
|
||||
}
|
||||
* @param tweet - tweet to process
|
||||
* @param playerIdentifier - the current player's identifier
|
||||
* @returns Formatted Tweet
|
||||
*/
|
||||
function processBroadcastedTweet(tweet: Tweet, profile: Profile): FormattedTweet {
|
||||
const processedTweet = processTweet(tweet);
|
||||
const isLiked = false;
|
||||
const isMine = profile?.identifier === tweet.identifier;
|
||||
return { ...processedTweet, isMine, isLiked };
|
||||
}
|
||||
|
||||
/**
|
||||
* Service to handle all NUI <> client interactions. We take
|
||||
* this opportunity to act as a middleware layer between the
|
||||
@@ -35,12 +53,13 @@ export const useTwitterService = () => {
|
||||
const { setNotification } = useTwitterNotifications();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const setProfile = useSetRecoilState(twitterState.profile);
|
||||
const [profile, setProfile] = useRecoilState<Profile>(twitterState.profile);
|
||||
const setUpdateProfileLoading = useSetRecoilState(twitterState.updateProfileLoading);
|
||||
|
||||
const setTweets = useSetRecoilState(twitterState.tweets);
|
||||
const [currentTweets, setTweets] = useRecoilState(twitterState.tweets);
|
||||
const setFilteredTweets = useSetRecoilState(twitterState.filteredTweets);
|
||||
const setCreateLoading = useSetRecoilState(twitterState.createTweetLoading);
|
||||
const setDefaultProfileNames = useSetRecoilState(twitterState.defaultProfileNames);
|
||||
|
||||
const _setTweets = (tweets) => {
|
||||
setTweets(tweets.map(processTweet));
|
||||
@@ -49,6 +68,14 @@ export const useTwitterService = () => {
|
||||
setFilteredTweets(tweets.map(processTweet));
|
||||
};
|
||||
|
||||
// these tweets are coming directly from other player clients
|
||||
const handleTweetBroadcast = (tweet: Tweet) => {
|
||||
setNotification(tweet);
|
||||
const processedTweet = processBroadcastedTweet(tweet, profile);
|
||||
const updatedTweets = [processedTweet].concat(currentTweets);
|
||||
setTweets(updatedTweets);
|
||||
};
|
||||
|
||||
const handleAddAlert = ({ message, type }: IAlert) => {
|
||||
addAlert({
|
||||
message: t(`APPS_${message}`),
|
||||
@@ -56,13 +83,15 @@ export const useTwitterService = () => {
|
||||
});
|
||||
};
|
||||
|
||||
useNuiEvent(APP_TWITTER, 'getOrCreateTwitterProfile', setProfile);
|
||||
useNuiEvent(APP_TWITTER, 'updateProfileLoading', setUpdateProfileLoading);
|
||||
useNuiEvent(APP_TWITTER, 'updateProfileResult', handleAddAlert);
|
||||
useNuiEvent(APP_TWITTER, 'fetchTweets', _setTweets);
|
||||
useNuiEvent(APP_TWITTER, 'fetchTweetsFiltered', _setFilteredTweets);
|
||||
useNuiEvent(APP_TWITTER, 'createTweetLoading', setCreateLoading);
|
||||
useNuiEvent(APP_TWITTER, 'createTweetResult', handleAddAlert);
|
||||
useNuiEvent(APP_TWITTER, 'createTweetBroadcast', setNotification);
|
||||
useNuiEvent(APP_TWITTER, 'phone:retweetExists', handleAddAlert);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.GET_OR_CREATE_PROFILE, setProfile);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.GET_OR_CREATE_PROFILE_NULL, setDefaultProfileNames);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.CREATE_PROFILE_RESULT, handleAddAlert);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.UPDATE_PROFILE_LOADING, setUpdateProfileLoading);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.UPDATE_PROFILE_RESULT, handleAddAlert);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.FETCH_TWEETS, _setTweets);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.FETCH_TWEETS_FILTERED, _setFilteredTweets);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.CREATE_TWEET_LOADING, setCreateLoading);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.CREATE_TWEET_RESULT, handleAddAlert);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.CREATE_TWEET_BROADCAST, handleTweetBroadcast);
|
||||
useNuiEvent(APP_TWITTER, TwitterEvents.RETWEET_EXISTS, handleAddAlert);
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
export const IMG_DEFAULT_AVATAR = './media/twitter/egg.png';
|
||||
export const IMG_INVALID_AVATAR = './media/twitter/invalid.png';
|
||||
export const IMG_DEFAULT_AVATAR = 'media/twitter/egg.png';
|
||||
export const IMG_INVALID_AVATAR = 'media/twitter/invalid.png';
|
||||
export const APP_TWITTER = 'TWITTER';
|
||||
|
||||
export const SETTING_MENTIONS = 'mentions';
|
||||
|
||||
Loaded 100 of 167 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user