Skip to content

Commit dfc0e7b

Browse files
authored
Removed unnecessary dependency. Updated dependencies. Fixed Bootstrap build. Added light / dark / auto switch. Added Bootstrap Icons. (#112)
1 parent 2b2b6cc commit dfc0e7b

16 files changed

+1130
-1139
lines changed

.github/workflows/codeql-analysis.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
name: "CodeQL"
8+
9+
on:
10+
push:
11+
branches: [ "release", "master" ]
12+
pull_request:
13+
# The branches below must be a subset of the branches above
14+
branches: [ "release", "master" ]
15+
schedule:
16+
- cron: '38 4 * * 5'
17+
18+
jobs:
19+
analyze:
20+
name: Analyze
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 360
23+
permissions:
24+
actions: read
25+
contents: read
26+
security-events: write
27+
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
language: [ 'javascript' ]
32+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
33+
# Learn more:
34+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
35+
36+
steps:
37+
- name: Checkout repository
38+
uses: actions/checkout@v3
39+
40+
# Initializes the CodeQL tools for scanning.
41+
- name: Initialize CodeQL
42+
uses: github/codeql-action/init@v2
43+
with:
44+
languages: ${{ matrix.language }}
45+
# If you wish to specify custom queries, you can do so here or in a config file.
46+
# By default, queries listed here will override any specified in a config file.
47+
# Prefix the list here with "+" to use these queries and those in the config file.
48+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
49+
50+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
51+
# If this step fails, then you should remove it and run the build manually (see below)
52+
# - name: Autobuild
53+
# uses: github/codeql-action/autobuild@v1
54+
55+
# ℹ️ Command-line programs to run using the OS shell.
56+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
57+
58+
# If the Autobuild fails above, remove it and uncomment the following three lines.
59+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
60+
61+
# - run: |
62+
# echo "Run, Build Application using script"
63+
# ./location_of_script_within_repo/buildscript.sh
64+
65+
- name: Perform CodeQL Analysis
66+
uses: github/codeql-action/analyze@v2
67+
with:
68+
category: "/language:${{matrix.language}}"
69+

.mocharc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require:
55
spec:
66
- 'test/unit/index.js'
77
- 'test/integration/index.js'
8-
timeout: 10000 # Give Sails some breathing room... We are building schemas / data fixtures.
8+
timeout: 60000 # Give Sails some breathing room... We are building schemas / data fixtures.
99
checkLeaks: true
1010
global:
1111
- '_' # Lodash global

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
# Changelog
2+
3+
## [v4.2.4](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v4.2.3...v4.2.4) (2023-10-30)
4+
### Features
5+
6+
* Fixed Bootstrap build. (Missing dark-mode file.)
7+
* Built light / dark / auto switch for admin.
8+
* Updated dependencies.
9+
210
## [v4.2.3](https://github.com/neonexus/sails-react-bootstrap-webpack/compare/v4.2.2...v4.2.3) (2023-10-03)
311
### Features
412

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM node:18.17
1+
FROM node:18-slim
22
MAINTAINER NeoNexus DeMortis
33

44
RUN mkdir /var/www && mkdir /var/www/myapp

README.md

+17-4
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,27 @@ I manually check the changes when a package has a new version, to verify there i
8989

9090
## How to Use
9191

92-
This repo is not installable via `npm`. Instead, GitHub provides a handy "Use this template" (green) button at the top of this page. That will create a special clone of this repo (so there is a single,
93-
init commit, instead of the commit history from this repo).
92+
You can quickly download / install dependencies using [`drfg` (Download Release From GitHub)](https://www.npmjs.com/package/drfg) via NPX (if you have Node.js installed, you have NPX):
9493

95-
Or, you can download a copy of the [latest release](https://github.com/neonexus/sails-react-bootstrap-webpack/releases/latest).
94+
```shell
95+
npx drfg neonexus/sails-react-bootstrap-webpack
96+
```
97+
98+
This will download this repo's latest version, extract it, then install the dependencies into the folder `sails-react-bootstrap-webpack` in the current working directory.
99+
If you want to install in a different location, just supply the new folder name as the second parameter:
100+
101+
```shell
102+
npx drfg neonexus/sails-react-bootstrap-webpack my-new-site
103+
```
104+
105+
Or, GitHub provides a handy "Use this template" (green) button at the top of this page. That will create a special clone of this repo (so there is a single, init commit,
106+
instead of the commit history from this repo).
107+
108+
Or, you can download a copy of the [latest release](https://github.com/neonexus/sails-react-bootstrap-webpack/releases/latest) manually.
96109

97110
## Configuration
98111

99-
In the `config` folder, there is the [`local.js.sample`](config/local.js.sample) file, which is meant to be copied to `local.js`. This file (`local.js`, not the sample) is ignored by Git, and intended
112+
In the [`config` folder](config), there is the [`local.js.sample`](config/local.js.sample) file, which is meant to be copied to `local.js`. This file (`local.js`, not the sample) is ignored by Git, and intended
100113
for use in local development, NOT remote servers. Generally one would use environment variables for remote server configuration (and this repo is already setup to handle environment variable
101114
configuration for both DEV and PROD). See [Environment Variables](#environment-variables) for more.
102115

assets/src/Admin/NavBar.jsx

+74-9
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,119 @@
1-
import { useState, useContext } from 'react';
1+
import {useState, useContext, useEffect} from 'react';
22
import PropTypes from 'prop-types';
33

44
import {Button, Nav, Navbar, NavDropdown} from 'react-bootstrap';
55
import {NavLink as ReactNavLink} from 'react-router-dom';
66

77
import UserContext from '../data/UserContext';
88

9+
function scrollListener() {
10+
const nav = document.querySelector('nav');
11+
12+
if (nav) {
13+
if (window.scrollY > 0 && window.scrollY < 26) {
14+
nav.classList.add('shadow-sm');
15+
nav.classList.remove('shadow');
16+
} else if (window.scrollY > 25) {
17+
nav.classList.add('shadow');
18+
nav.classList.remove('shadow-sm');
19+
} else {
20+
nav.classList.remove('shadow');
21+
nav.classList.remove('shadow-sm');
22+
}
23+
}
24+
}
25+
926
function NavBar(props) {
1027
const [isExpanded, setIsExpanded] = useState(false);
1128
const user = useContext(UserContext);
1229

30+
const [lightOrDark, setLightOrDark] = useState(window.localStorage.getItem('theme'));
31+
let lightDarkAutoClass = 'bi-circle-half';
32+
33+
if (lightOrDark === 'dark') {
34+
lightDarkAutoClass = 'bi-moon-fill';
35+
} else if (lightOrDark === 'light') {
36+
lightDarkAutoClass = 'bi-sun-fill';
37+
}
38+
1339
function closeNavbar() {
1440
setIsExpanded(false);
1541
}
1642

43+
function switchTheme(e) {
44+
const newTheme = e.target.getAttribute('data-theme-set');
45+
46+
setLightOrDark(newTheme);
47+
window.localStorage.setItem('theme', newTheme);
48+
49+
tellBootstrapAboutTheme(newTheme);
50+
}
51+
52+
function tellBootstrapAboutTheme(newTheme) {
53+
if (newTheme === 'light' || newTheme === 'dark') {
54+
document.documentElement.setAttribute('data-bs-theme', newTheme);
55+
} else {
56+
document.documentElement.setAttribute('data-bs-theme', window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
57+
}
58+
}
59+
60+
function themeListener() {
61+
tellBootstrapAboutTheme(lightOrDark);
62+
}
63+
64+
useEffect(() => {
65+
window.addEventListener('scroll', scrollListener);
66+
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', themeListener);
67+
68+
// If we don't do this, and the page loads with "auto" and the user wants it dark, it won't change.
69+
tellBootstrapAboutTheme(lightOrDark);
70+
71+
return () => {
72+
window.removeEventListener('scroll', scrollListener);
73+
window.matchMedia('(prefers-color-scheme: dark)').removeEventListener('change', themeListener);
74+
};
75+
});
76+
1777
return (
1878
<Navbar
19-
bg="dark"
20-
variant="dark"
79+
bg="body-tertiary"
2180
expand="sm"
2281
sticky="top"
23-
className="mb-3 ps-3 pe-3"
82+
className="mb-3 ps-3 pe-3 border-bottom"
2483
expanded={isExpanded}
2584
onToggle={() => setIsExpanded(!isExpanded)}
2685
>
2786
<Navbar.Brand>{appConfig.appName}</Navbar.Brand>
2887
<Navbar.Toggle aria-controls="basic-navbar-nav" />
2988
<Navbar.Collapse id="basic-navbar-nav">
30-
<Nav className="me-auto">
89+
<Nav className="me-auto" navbarScroll>
3190
<Nav.Link as={ReactNavLink} to="/admin/dashboard" onClick={closeNavbar}>Home</Nav.Link>
3291
{
3392
(user.info.role === 'admin')
3493
? <Nav.Link as={ReactNavLink} to="/admin/users" onClick={closeNavbar}>Users</Nav.Link>
3594
: null
3695
}
3796
<Nav.Link as={ReactNavLink} to="/admin/404" onClick={closeNavbar}>404 Page</Nav.Link>
38-
<NavDropdown title="Settings" id="basic-nav-dropdown" menuVariant="dark">
39-
<NavDropdown.Item className="ps-3 pe-3" as={ReactNavLink} to="/admin/settings/profile" onClick={closeNavbar}>Profile</NavDropdown.Item>
40-
<NavDropdown.Item className="ps-3 pe-3" as={ReactNavLink} to="/admin/settings/security" onClick={closeNavbar}>Security</NavDropdown.Item>
97+
<NavDropdown title="Settings" id="basic-nav-dropdown">
98+
<NavDropdown.Item className="ps-3 pe-3" as={ReactNavLink} to="/admin/settings/profile" onClick={closeNavbar}><i className="bi bi-person-fill" /> Profile</NavDropdown.Item>
99+
<NavDropdown.Item className="ps-3 pe-3" as={ReactNavLink} to="/admin/settings/security" onClick={closeNavbar}><i className="bi bi-shield-lock-fill" /> Security</NavDropdown.Item>
41100
</NavDropdown>
42101
</Nav>
43102

44103
{
45104
user.isLoggedIn ?
46105
<>
47-
<span className="text-white d-none d-md-block">Welcome, {user.info.firstName} &nbsp; &nbsp; </span>
106+
<Navbar.Text>Welcome, {user.info.firstName} &nbsp; &nbsp; </Navbar.Text>
48107
<Button variant="danger" onClick={() => props.handleLogout()} size="sm" className="mt-2 mt-sm-0 mb-2 mb-sm-0">Logout</Button>
49108
</>
50109
: null
51110
}
111+
112+
<NavDropdown title={<i className={'bi ' + lightDarkAutoClass}/>} id="light-or-dark-toggle" className="ms-3 right-align-menu">
113+
<NavDropdown.Item className="bi bi-sun-fill" active={lightOrDark === 'light'} data-theme-set="light" onClick={switchTheme}>Light</NavDropdown.Item>
114+
<NavDropdown.Item className="bi bi-moon-fill" active={lightOrDark === 'dark'} data-theme-set="dark" onClick={switchTheme}>Dark</NavDropdown.Item>
115+
<NavDropdown.Item className="bi bi-circle-half" active={lightOrDark !== 'light' && lightOrDark !== 'dark'} data-theme-set="auto" onClick={switchTheme}>Auto</NavDropdown.Item>
116+
</NavDropdown>
52117
</Navbar.Collapse>
53118
</Navbar>
54119
);

assets/styles/admin/_global.scss

+27
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,30 @@
55
.ls-25 {
66
letter-spacing: .25rem;
77
}
8+
9+
nav {
10+
transition: all .5s;
11+
12+
.dropdown-menu {
13+
min-width: 5rem;
14+
15+
.dropdown-item.bi::before {
16+
padding-right: .35rem;
17+
}
18+
}
19+
20+
.right-align-menu .dropdown-menu {
21+
left: unset;
22+
right: 0;
23+
}
24+
25+
.navbar-nav .nav-link {
26+
&.active, &:hover {
27+
color: var(--#{$prefix}link-color);
28+
29+
@include color-mode(dark) {
30+
color: $white;
31+
}
32+
}
33+
}
34+
}

assets/styles/admin/admin.scss

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
@import "bootstrap-variable-overrides";
44
@import "~bootstrap/scss/variables";
5+
@import "~bootstrap/scss/variables-dark";
56

67
@import "~bootstrap/scss/maps";
7-
88
@import "~bootstrap/scss/mixins";
9+
@import "~bootstrap/scss/utilities";
910

1011
@import "../common/bootstrap";
11-
1212
@import "../common/reboot";
13-
1413
@import "../common/common";
1514

1615
@import "global";

0 commit comments

Comments
 (0)