From d4a51c658e7176d973f85e188ee254dfba5e6626 Mon Sep 17 00:00:00 2001
From: EricW <99090141+EricWang228@users.noreply.github.com>
Date: Fri, 11 Oct 2024 15:55:26 -0400
Subject: [PATCH] Inital Linter Setup with Actions (#88)

* Inital Linter Setup

* Fixed Linting Errors From Eslint
---
 .github/workflows/linter.yaml      | 25 +++++++++++++++++++++++++
 client/contexts/DarkModeContext.js | 17 ++++++++++++++---
 client/package-lock.json           |  1 +
 client/package.json                |  1 +
 client/services/sms.js             |  4 ++++
 5 files changed, 45 insertions(+), 3 deletions(-)
 create mode 100644 .github/workflows/linter.yaml

diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml
new file mode 100644
index 0000000..ab2cbdd
--- /dev/null
+++ b/.github/workflows/linter.yaml
@@ -0,0 +1,25 @@
+name: Linter
+on: 
+  push: 
+    branches: 
+      - main
+
+jobs:
+  eslint:
+    name: Lint Code Base
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout Source Code
+        uses: actions/checkout@v2
+      - name: Set up Node.js
+        uses: actions/setup-node@v3
+        with:
+          node-version: '16'
+      - name: Install dependencies
+        run: |
+          cd client
+          npm install
+      - name: Run eslint
+        run: |
+          cd client
+          npm run lint -- --fix
diff --git a/client/contexts/DarkModeContext.js b/client/contexts/DarkModeContext.js
index ea654e2..989e8dd 100644
--- a/client/contexts/DarkModeContext.js
+++ b/client/contexts/DarkModeContext.js
@@ -1,4 +1,5 @@
-import React, { createContext, useState, useContext } from 'react';
+import React, { createContext, useState, useContext, useMemo, useCallback } from 'react';
+import PropTypes from 'prop-types';
 
 const DarkModeContext = createContext();
 
@@ -9,11 +10,21 @@ export function useDarkMode() {
 export function DarkModeProvider({ children }) {
   const [isDarkMode, setIsDarkMode] = useState(false);
 
-  const toggleSwitch = () => setIsDarkMode(!isDarkMode);
+  // Wrap toggleSwitch in useCallback to prevent re-creation on every render
+  const toggleSwitch = useCallback(() => {
+    setIsDarkMode((prev) => !prev);
+  }, []);
+
+  // Memoize the context value
+  const value = useMemo(() => ({ isDarkMode, toggleSwitch }), [isDarkMode, toggleSwitch]);
 
   return (
-    <DarkModeContext.Provider value={{ isDarkMode, toggleSwitch }}>
+    <DarkModeContext.Provider value={value}>
       {children}
     </DarkModeContext.Provider>
   );
 }
+
+DarkModeProvider.propTypes = {
+  children: PropTypes.node.isRequired,
+};
diff --git a/client/package-lock.json b/client/package-lock.json
index 66b4a00..9c6f554 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -20,6 +20,7 @@
         "expo-notifications": "^0.28.16",
         "expo-sms": "^12.0.1",
         "expo-status-bar": "^1.12.1",
+        "prop-types": "^15.8.1",
         "react": "18.2.0",
         "react-dom": "18.2.0",
         "react-native": "^0.74.5",
diff --git a/client/package.json b/client/package.json
index f26940b..50c71ae 100644
--- a/client/package.json
+++ b/client/package.json
@@ -25,6 +25,7 @@
     "expo-notifications": "^0.28.16",
     "expo-sms": "^12.0.1",
     "expo-status-bar": "^1.12.1",
+    "prop-types": "^15.8.1",
     "react": "18.2.0",
     "react-dom": "18.2.0",
     "react-native": "^0.74.5",
diff --git a/client/services/sms.js b/client/services/sms.js
index 2a7e09b..7dc1ac2 100644
--- a/client/services/sms.js
+++ b/client/services/sms.js
@@ -1,3 +1,6 @@
+// Function not used, please finish implementation
+
+/* 
 import * as SMS from 'expo-sms';
 
 const sendAlarmNotification = async (phoneNumber) => {
@@ -6,3 +9,4 @@ const sendAlarmNotification = async (phoneNumber) => {
     await SMS.sendSMSAsync(phoneNumber, 'Alarm missed! Wake up!');
   }
 };
+*/