From a62d0aceb44804f186349efa00ccc189f955077b Mon Sep 17 00:00:00 2001 From: N0VA-code Date: Tue, 14 Nov 2023 15:20:50 -0600 Subject: [PATCH 1/4] auto generating BoardID --- .../src/routes/login/username/+page.svelte | 80 +++++++++---------- 1 file changed, 37 insertions(+), 43 deletions(-) diff --git a/scorebored/src/routes/login/username/+page.svelte b/scorebored/src/routes/login/username/+page.svelte index 0c6f605..5a3bd8e 100644 --- a/scorebored/src/routes/login/username/+page.svelte +++ b/scorebored/src/routes/login/username/+page.svelte @@ -15,16 +15,8 @@ let timeTarget = 0; let lastEdited = new Date(); let Username = ''; // 사용자 컬렉션에 추가할 필드 - let loading = false; - let isAvailable = false; - let debounceTimer; let currentUser = null; - const re = /^(?=[a-zA-Z0-9._]{3,16}$)(?!.*[_.]{2})[^_.].*[^_.]$/; - $: isValid = BoardID?.length > 2 && BoardID.length < 16 && re.test(BoardID); - $: isTouched = BoardID.length > 0; - $: isTaken = isValid && !isAvailable && !loading; - onMount(() => { const auth = getAuth(); onAuthStateChanged(auth, (user) => { @@ -36,16 +28,20 @@ }); }); - async function checkAvailability() { - isAvailable = false; - clearTimeout(debounceTimer); - loading = true; - debounceTimer = setTimeout(async () => { - const ref = doc(db, "user", BoardID); - const docSnap = await getDoc(ref); - isAvailable = !docSnap.exists(); - loading = false; - }, 500); + function generateRandomId(length) { + let result = ''; + const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; + const charactersLength = characters.length; + for (let i = 0; i < length; i++) { + result += characters.charAt(Math.floor(Math.random() * charactersLength)); + } + return result; + } + + async function isIdUnique(id) { + const ref = doc(db, "scoreboard", id); + const docSnap = await getDoc(ref); + return !docSnap.exists(); } async function confirmBoardID() { @@ -53,6 +49,13 @@ console.error("User not found"); return; } + + let uniqueIdFound = false; + while (!uniqueIdFound) { + BoardID = generateRandomId(10); + uniqueIdFound = await isIdUnique(BoardID); + } + const uid = currentUser.uid; const batch = writeBatch(db); @@ -71,36 +74,28 @@ try { await batch.commit(); + // 폼 제출 후 필드 초기화 + BoardID = ''; + BoardName = ''; + datapoints = []; + isQuantity = false; + X_axis = ''; + Y_axis = ''; + numTarget = 0; + timeTarget = 0; + lastEdited = new Date(); + Username = ''; } catch (error) { console.error("Error in batch commit:", error); } - - BoardID = ''; - BoardName = ''; - datapoints = []; - isQuantity = false; - X_axis = ''; - Y_axis = ''; - numTarget = 0; - timeTarget = 0; - lastEdited = new Date(); - Username = ''; - isAvailable = false; }
- +
+ Board ID: {BoardID || 'Generating...'} +
- - + -
From c0204f132da0693ece9118e507a12c917c440be4 Mon Sep 17 00:00:00 2001 From: N0VA-code Date: Tue, 14 Nov 2023 17:21:40 -0600 Subject: [PATCH 2/4] new BoardID generating functionality using firebase --- .../src/routes/login/username/+page.svelte | 61 ++++++------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/scorebored/src/routes/login/username/+page.svelte b/scorebored/src/routes/login/username/+page.svelte index 5a3bd8e..ffdc5f0 100644 --- a/scorebored/src/routes/login/username/+page.svelte +++ b/scorebored/src/routes/login/username/+page.svelte @@ -1,7 +1,7 @@ From 306438abecd121df6548a983cce99abdb82aac38 Mon Sep 17 00:00:00 2001 From: N0VA-code Date: Sun, 26 Nov 2023 02:59:52 -0600 Subject: [PATCH 3/4] implemented nesting features --- scorebored/src/lib/firebase/firebase.ts | 2 +- .../src/routes/login/username/+page.svelte | 237 ++++++++++++------ 2 files changed, 159 insertions(+), 80 deletions(-) diff --git a/scorebored/src/lib/firebase/firebase.ts b/scorebored/src/lib/firebase/firebase.ts index c04656a..c9599a7 100644 --- a/scorebored/src/lib/firebase/firebase.ts +++ b/scorebored/src/lib/firebase/firebase.ts @@ -6,7 +6,7 @@ import { writable, derived } from "svelte/store"; // Your web app's Firebase configuration (Replace with your actual config) const firebaseConfig = { - apiKey: import.meta.env.VITE_APIKEY, + apiKey: "AIzaSyDGP9glve5aN5Ba0gUM43NnmzxFo5CTEJ4", authDomain: "scorebored2-e7ffd.firebaseapp.com", databaseURL: "https://scorebored2-e7ffd-default-rtdb.firebaseio.com", projectId: "scorebored2-e7ffd", diff --git a/scorebored/src/routes/login/username/+page.svelte b/scorebored/src/routes/login/username/+page.svelte index ffdc5f0..d630c1e 100644 --- a/scorebored/src/routes/login/username/+page.svelte +++ b/scorebored/src/routes/login/username/+page.svelte @@ -1,21 +1,22 @@
- Board ID: {BoardID || 'Generating...'} + Board ID: + +
- - - - Is Quantity? - - - - - + + Is Quantity? + + + + + +
+ + {#each datapoints as datapoint, index} +
+ {#if isQuantity} + + {:else} + + + {/if} + +
+ {/each} +
+ +
From e2d492e59bffec402fd7bb957b1fb360b772e636 Mon Sep 17 00:00:00 2001 From: N0VA-code Date: Sun, 26 Nov 2023 03:07:30 -0600 Subject: [PATCH 4/4] nested features --- scorebored/src/lib/firebase/firebase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scorebored/src/lib/firebase/firebase.ts b/scorebored/src/lib/firebase/firebase.ts index c9599a7..0f56d61 100644 --- a/scorebored/src/lib/firebase/firebase.ts +++ b/scorebored/src/lib/firebase/firebase.ts @@ -6,7 +6,7 @@ import { writable, derived } from "svelte/store"; // Your web app's Firebase configuration (Replace with your actual config) const firebaseConfig = { - apiKey: "AIzaSyDGP9glve5aN5Ba0gUM43NnmzxFo5CTEJ4", + apiKey: import.meta.env.VITE_API_KEY, authDomain: "scorebored2-e7ffd.firebaseapp.com", databaseURL: "https://scorebored2-e7ffd-default-rtdb.firebaseio.com", projectId: "scorebored2-e7ffd",