public int[] ArrayDiff(int[] arrayA, int[] arrayB)
{
HashSet<int> bSet = new HashSet<int>(arrayB);
return arrayA.Where(v => !bSet.Contains(v)).ToArray();
}
import axios from "axios";
import { useRef } from "react";
import "./register.css";
import { useHistory } from "react-router";
export default function Register() {
const username = useRef();
const email = useRef();
const password = useRef();
const passwordAgain = useRef();
const history = useHistory();
const handleClick = async (e) => {
e.preventDefault();
if (passwordAgain.current.value !== password.current.value) {
passwordAgain.current.setCustomValidity("Passwords don't match!");
} else {
const user = {
username: username.current.value,
email: email.current.value,
password: password.current.value,
};
try {
await axios.post("/auth/register", user);
history.push("/login");
} catch (err) {
console.log(err);
}
}
};
import AuthReducer from "./AuthReducer";
const INITIAL_STATE = {
user:JSON.parse(localStorage.getItem("user")) || null,
isFetching: false,
error: false,
};
export const AuthContext = createContext(INITIAL_STATE);
export const AuthContextProvider = ({ children }) => {
const [state, dispatch] = useReducer(AuthReducer, INITIAL_STATE);
useEffect(()=>{
localStorage.setItem("user", JSON.stringify(state.user))
},[state.user])
return (
<AuthContext.Provider
value={{
user: state.user,
isFetching: state.isFetching,
error: state.error,
dispatch,
}}
>
{children}
</AuthContext.Provider>
);
};
const AuthReducer = (state, action) => {
switch (action.type) {
case "LOGIN_START":
return {
user: null,
isFetching: true,
error: false,
};
case "LOGIN_SUCCESS":
return {
user: action.payload,
isFetching: false,
error: false,
};
case "LOGIN_FAILURE":
return {
user: null,
isFetching: false,
error: true,
};
export const LoginStart = (userCredentials) => ({
type: "LOGIN_START",
});
export const LoginSuccess = (user) => ({
type: "LOGIN_SUCCESS",
payload: user,
});
export const LoginFailure = () => ({
type: "LOGIN_FAILURE",
});
import Home from "./pages/home/Home";
import Login from "./pages/login/Login";
import Profile from "./pages/profile/Profile";
import Register from "./pages/register/Register";
import {
BrowserRouter as Router,
Switch,
Route,
Redirect,
} from "react-router-dom";
import { useContext } from "react";
import { AuthContext } from "./context/AuthContext";
import Messenger from "./pages/messenger/Messenger";
function App() {
const { user } = useContext(AuthContext);
return (
<Router>
<Switch>
<Route exact path="/">
{user ? <Home /> : <Register />}
</Route>
<Route path="/login">{user ? <Redirect to="/" /> : <Login />}</Route>
<Route path="/register">
{user ? <Redirect to="/" /> : <Register />}
</Route>
<Route path="/messenger">
{!user ? <Redirect to="/" /> : <Messenger />}
</Route>
<Route path="/profile/:username">
<Profile />
</Route>
</Switch>
</Router>
);
}
export default App;
import axios from "axios";
export const loginCall = async (userCredential, dispatch) => {
dispatch({ type: "LOGIN_START" });
try {
const res = await axios.post("/auth/login", userCredential);
dispatch({ type: "LOGIN_SUCCESS", payload: res.data });
} catch (err) {
dispatch({ type: "LOGIN_FAILURE", payload: err });
}
};
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { AuthContextProvider } from "./context/AuthContext";
ReactDOM.render(
<React.StrictMode>
<AuthContextProvider>
<App />
</AuthContextProvider>
</React.StrictMode>,
document.getElementById("root")
);
private void DrStrof(Graphics Grf, Color clr)
{
//Plot MyPlot = new Plot();
double x;
double y;
double a = 2;
double t;
//MyPlot.ClientArea = ClientSize;
//MyPlot.SetPlotPort(-20, 20, -20, 20);
for ( t = -100; t < 100; t += 0.005)
{
if (t * t - 1 != 0)
{
x = a * (t * t - 1) / (t * t + 1);
y = a * t *(t * t - 1) / (t * t + 1);
x *= DrawGrid.PIX_IN_ONE;
y *= DrawGrid.PIX_IN_ONE;
Circle.PutPixel(Grf, clr, (int)x, (int)y, 255);
//MyPlot.PlotPixel(x, y, Color.Black, Grf);
}
else
continue;
}
//это в другом классе у меня
public static void PutPixel(Graphics g, Color col, int x, int y, int alpha)
{
g.FillRectangle(new SolidBrush(Color.FromArgb(alpha, col)), x, y, 1, 1);
}