formatting

This commit is contained in:
erik-sn committed 2020-10-18 13:38:01 -04:00
1 parent e48263838f
commit 3a1bd75f97
23 files changed
+309 -236

No files matched your search

@@ -1,42 +1,47 @@
import React from 'react';
import { shallow } from 'enzyme';
import TwitterNotification from './TwitterNotification';
import React from "react";
import { shallow } from "enzyme";
import TwitterNotification from "./TwitterNotification";
jest.mock('react-i18next', () => ({
useTranslation: () => ({t: key => key})
jest.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key) => key }),
}));
jest.mock('../../../../os/phone/hooks/usePhone', () => ({
usePhone: jest.fn().mockReturnValue({ config: {
twitter: {
showNotifications: true,
}
} })
jest.mock("../../../../os/phone/hooks/usePhone", () => ({
usePhone: jest.fn().mockReturnValue({
config: {
twitter: {
showNotifications: true,
},
},
}),
}));
jest.mock('../../hooks/useTwitterNotification', () => ({
useTwitterNotification: jest.fn().mockReturnValue({ notification: {
profile_name: 'test',
message: 'test message'
} })
jest.mock("../../hooks/useTwitterNotification", () => ({
useTwitterNotification: jest.fn().mockReturnValue({
notification: {
profile_name: "test",
message: "test message",
},
}),
}));
describe("TwitterNotification", () => {
let wrapper;
describe('TwitterNotification', () => {
let wrapper;
beforeEach(() => {
wrapper = shallow(<TwitterNotification />);
});
it("renders", () => {
expect(wrapper).toBeDefined();
});
beforeEach(() => {
wrapper = shallow(<TwitterNotification />)
})
it('renders', () => {
expect(wrapper).toBeDefined();
});
it("renders profile name", () => {
expect(wrapper.find(".makeStyles-profileName-5").text()).toEqual("@test");
});
it('renders profile name', () => {
expect(wrapper.find('.makeStyles-profileName-5').text()).toEqual('@test');
});
it('renders message', () => {
expect(wrapper.find('.makeStyles-message-7').text()).toEqual('test message');
});
it("renders message", () => {
expect(wrapper.find(".makeStyles-message-7").text()).toEqual(
"test message"
);
});
});
@@ -1,48 +1,48 @@
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { makeStyles, createStyles, Theme } from "@material-ui/core/styles";
import TwitterIcon from '@material-ui/icons/Twitter';
import { useTwitterNotification } from '../../hooks/useTwitterNotification';
import Notification from '../../../../ui/components/Notification';
import TwitterIcon from "@material-ui/icons/Twitter";
import { useTwitterNotification } from "../../hooks/useTwitterNotification";
import Notification from "../../../../ui/components/Notification";
import { usePhone } from "../../../../os/phone/hooks/usePhone";
const useStyles = makeStyles((theme: Theme) =>
const useStyles = makeStyles((theme: Theme) =>
createStyles({
content: {
padding: theme.spacing(2),
overflowY: 'hidden'
overflowY: "hidden",
},
title: {
display: 'flex',
flexFlow: 'row nowrap',
justifyContent: 'space-between',
alignItems: 'center'
display: "flex",
flexFlow: "row nowrap",
justifyContent: "space-between",
alignItems: "center",
},
titleLeft: {
display: 'flex',
flexFlow: 'row nowrap',
justifyContent: 'flex-start',
alignItems: 'center'
display: "flex",
flexFlow: "row nowrap",
justifyContent: "flex-start",
alignItems: "center",
},
icon: {
marginTop: '3px',
marginRight: '5px'
marginTop: "3px",
marginRight: "5px",
},
profileName: {
marginBottom: '3px',
marginBottom: "3px",
},
justNow: {
fontSize: '18px',
fontStyle: 'italic',
paddingRight: '3px',
fontSize: "18px",
fontStyle: "italic",
paddingRight: "3px",
},
message: {
fontSize: '16px',
overflow: 'hidden',
display: '-webkit-box',
fontSize: "16px",
overflow: "hidden",
display: "-webkit-box",
WebkitLineClamp: 2,
WebkitBoxOrient: 'vertical',
}
WebkitBoxOrient: "vertical",
},
})
);
@@ -57,18 +57,24 @@ function TwitterNotification() {
if (notification) {
setVisible(true);
}
}, [notification?.id])
}, [notification?.id]);
if (!config?.twitter.showNotifications || !notification) return null;
const profileName = `@${notification.profile_name?.trim()}`;
return (
<Notification key={notification.id} open={visible} handleClose={() => setVisible(false)}>
<Notification
key={notification.id}
open={visible}
handleClose={() => setVisible(false)}
>
<div className={classes.content}>
<div className={classes.title}>
<div className={classes.titleLeft}>
<div className={classes.icon}><TwitterIcon /></div>
<div className={classes.icon}>
<TwitterIcon />
</div>
<div className={classes.profileName}>{profileName}</div>
</div>
<div className={classes.justNow}>{t("APPS_TWITTER_JUST_NOW")}</div>
@@ -79,5 +85,4 @@ function TwitterNotification() {
);
}
export default TwitterNotification;
+2 -2
View File
@@ -38,7 +38,7 @@ export const twitterState = {
default: null,
}),
notification: atom({
key: 'notification',
key: "notification",
default: null,
})
}),
};
@@ -4,7 +4,7 @@ import { Tweet } from "../interfaces";
import { twitterState } from "./state";
interface ITwitterNotification {
notification: Tweet | null;
notification: Tweet | null;
}
export const useTwitterNotification = (): ITwitterNotification => {
@@ -6,7 +6,6 @@ import { IMAGE_DELIMITER } from "../utils/images";
import { APP_TWITTER } from "../utils/constants";
import { twitterState } from "./state";
/**
* Perform all necessary processing/transforms from the raw database
* data to what the frontend expects
@@ -59,7 +58,7 @@ export const useTwitterService = () => {
const _setNotification = (tweet) => {
setNotification(tweet);
}
};
const _setTweets = (tweets) => {
setTweets(tweets.map(processTweet));
@@ -75,5 +74,5 @@ export const useTwitterService = () => {
useNuiEvent(APP_TWITTER, "fetchTweetsFiltered", _setFilteredTweets);
useNuiEvent(APP_TWITTER, "createTweetLoading", setCreateLoading);
useNuiEvent(APP_TWITTER, "createTweetResult", _setCreateSuccess);
useNuiEvent(APP_TWITTER, 'createTweetBroadcast', _setNotification)
useNuiEvent(APP_TWITTER, "createTweetBroadcast", _setNotification);
};
+9 -9
View File
@@ -1,10 +1,10 @@
export interface Tweet {
id: number;
profile_name?: string;
avatar_url?: string;
message: string;
createdAt?: string;
updatedAt?: string;
images?: string;
likes?: number;
}
id: number;
profile_name?: string;
avatar_url?: string;
message: string;
createdAt?: string;
updatedAt?: string;
images?: string;
likes?: number;
}