Skip to content

Commit

Permalink
added random name generator if name is less than 3 char
Browse files Browse the repository at this point in the history
  • Loading branch information
Koltheguy committed Apr 17, 2024
1 parent a19c6d2 commit b4212dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"reactfire": "^4.2.3",
"unique-names-generator": "^4.7.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
28 changes: 23 additions & 5 deletions src/ReactFireProvider.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import React from "react";
import React, { useState } from "react";
import { collection, query } from "firebase/firestore";
import { getAuth, updateProfile } from "firebase/auth";
import { useFirestore, useFirestoreCollectionData, useUser } from "reactfire";
import {
uniqueNamesGenerator,
adjectives,
colors,
animals,
} from "unique-names-generator";

import {
TextCensor,
Expand All @@ -25,9 +31,10 @@ export default function ReactFireStoreProvider(props) {
let displayName, uid;
if (status !== "loading") {
({ displayName, uid } = data);
console.log(displayName);
}

const [refresh, setRefresh] = useState(true);

const firestore = useFirestore();
const UserCollection = collection(firestore, "User");
const UserQuery = query(UserCollection);
Expand All @@ -39,11 +46,22 @@ export default function ReactFireStoreProvider(props) {

const changeUserName = async (name) => {
const matches = obscenityMatcher.getAllMatches(name);
const censored = censor.applyTo(name, matches);
console.log(censored);
let censored = censor.applyTo(name, matches);

if (censored.length < 3) {
censored = uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals],
separator: "",
style: "capital",
seed: Date.now(),
});
}
console.log("change", censored);

await updateProfile(auth.currentUser, {
displayName: name,
displayName: censored,
}).then(() => {
setRefresh(!refresh);
});
};
const joinGame = async () => {};
Expand Down

0 comments on commit b4212dc

Please sign in to comment.