Skip to content

Commit

Permalink
update styling
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven-Harris committed Sep 14, 2024
1 parent 093b5db commit 3a64abf
Show file tree
Hide file tree
Showing 14 changed files with 398 additions and 311 deletions.
10 changes: 1 addition & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ pnpm-debug.log*

# Vite build output
dist/
public/assets/
public/*.js
public/*.css
public/*.png
public/*.ico
public/*.webmanifest
public/index.html
public/*.br
!public/*.svg
public/

# Firebase
.firebase/
Expand Down
26 changes: 14 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@
<head>
<title>GitHelm</title>
<meta name="theme-color" content="#111827">
<link rel="icon" href="/favicon.ico" sizes="48x48">
<link rel="icon" href="/favicon.svg" sizes="any" type="image/svg+xml">
<link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png">
<link rel="icon" href="/assets/favicon.ico" sizes="48x48">
<link rel="icon" href="src/assets/helm.svg" sizes="any" type="image/svg+xml">
<link rel="apple-touch-icon" href="/assets/apple-touch-icon-180x180.png">

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="src/style.css" rel="stylesheet" />
<script defer type="module" src="src/main.ts"></script>
</head>

<body class="h-full text-white flex flex-col bg-gray-900">
<header class="flex justify-between items-center p-5 -pb-5 sticky top-0 z-10">
<h1 class="text-4xl font-bold">GitHelm</h1>
<div id="header" class="flex ">
<img src="src/assets/helm.svg" width="50" height="50" class="mr-2" />
<h1 class="text-4xl font-bold">GitHelm</h1>
</div>
<div id="buttons" class="flex space-x-4">
<button id="login-button" class="nav-button">
Login with GitHub
Expand All @@ -31,26 +35,23 @@ <h1 class="text-4xl font-bold">GitHelm</h1>
<button id="tab-actions" class="tab-button">Actions</button>
</div>
<div id="content" class="content grid grid-cols-1 md:grid-cols-2 gap-4">
<div id="loading" class="fixed mt-20 inset-0 flex items-center justify-center bg-gray-900 bg-opacity-50 z-50 hidden">
<img class="spinner" src="src/assets/helm.svg" width="10" height="10"/>
</div>
<section id="pull-requests-section" class="glow bg-gray-800 p-5 rounded-lg">
<h2 class="text-xl font-bold mb-4 lg:sticky top-0 z-10 bg-gray-800">
Pull Requests
<button id="edit-pull-requests" class="hover:underline" title="edit pull requests configuration"><img src="src/assets/edit.svg" width="20" height="20" class="-mb-1"/> </button>
<!-- <button id="edit-pull-requests" class="hover:underline" title="edit pull requests configuration"><img src="src/assets/edit.svg" width="20" height="20" class="-mb-1"/> </button> -->
</h2>
<div id="pull-requests"></div>
<div id="loading-pulls" class="h-full flex items-center justify-center">
<div class="spinner"></div>
</div>
</section>

<section id="actions-section" class="glow bg-gray-800 p-5 rounded-lg hidden md:block">
<h2 class="text-xl font-bold mb-4 lg:sticky top-0 z-10 bg-gray-800">
Actions
<button id="edit-actions" class="hover:underline" title="edit actions configuration"><img src="src/assets/edit.svg" width="20" height="20" class="-mb-1"/> </button>
<!-- <button id="edit-actions" class="hover:underline" title="edit actions configuration"><img src="src/assets/edit.svg" width="20" height="20" class="-mb-1"/> </button> -->
</h2>
<div id="actions"></div>
<div id="loading-actions" class="h-full flex items-center justify-center">
<div class="spinner"></div>
</div>
</section>
</div>
</div>
Expand Down Expand Up @@ -86,6 +87,7 @@ <h2 class="text-2xl font-bold mb-4">Pull Requests Config</h2>
<p>&copy; <span id="copyright">
<script>document.getElementById('copyright').appendChild(document.createTextNode(new Date().getFullYear()))</script>
</span> GitHelm. All rights reserved.</p>
<label id="last-updated" class="text-gray-400">Last updated 0s ago</label>
<a href="https://www.flaticon.com" title="rudder edit icons" class="hover:underline"
target="_blank">Icons created by Flat Icons </a>
</footer>
Expand Down
84 changes: 0 additions & 84 deletions public/favicon.svg

This file was deleted.

2 changes: 1 addition & 1 deletion pwa-assets.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default defineConfig({
preset: '2023',
},
preset,
images: ['public/favicon.svg'],
images: ['public/assets/helm.svg'],
})
233 changes: 233 additions & 0 deletions src/assets/helm.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
159 changes: 34 additions & 125 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,153 +1,62 @@
import { loadContent, setNoContent } from './modules/ui';
import {
loadContent,
LOGIN_BUTTON,
LOGOUT_BUTTON,
setNoContent,
showContent,
LastUpdated
} from './modules/ui';
import { initPWA } from './pwa';
import { Firebase, fetchDataAndSaveToLocalStorage, getSiteData, clearSiteData, getUserRepos } from './modules/services';
import './style.css';
import Sortable from 'sortablejs';
import { Firebase, fetchDataAndSaveToLocalStorage, getSiteData, clearSiteData } from './modules/services';

const firebase = new Firebase();
const lastUpdated = new LastUpdated();
document.addEventListener("DOMContentLoaded", async function () {
const firebase = new Firebase();
initPWA(document.getElementById('app')!);
LOGIN_BUTTON.addEventListener('click', async () => {
const signedIn = await firebase.signIn();
if (!signedIn) { return; }
showContent();
await updateLocalStorageAndLoadContent();
});

const configEntriesContainer = document.getElementById('config-entries');
if (configEntriesContainer) {
Sortable.create(configEntriesContainer, {
animation: 150,
handle: '.config-entry', // Handle to drag the config entry
ghostClass: 'sortable-ghost', // Class name for the drop placeholder
});
}
LOGOUT_BUTTON.addEventListener('click', () => {
firebase.signOut();
clearSiteData();
window.location.reload();
});

wireUpButtons(firebase);
// EDIT_PULL_REQUESTS_BUTTON.addEventListener('click', () => {
// console.log('Edit pull requests');
// });

// EDIT_ACTIONS_BUTTON.addEventListener('click', () => {
// console.log('Edit actions');
// });

const isSignedIn = Firebase.signedIn();
const localStorageData = getSiteData();

setInterval(async () => {
if (!isSignedIn) { return; }
if (!Firebase.signedIn()) { return; }
await updateLocalStorageAndLoadContent();
}, 60 * 1000);

if (!isSignedIn) { return; }
if (!Firebase.signedIn()) { return; }
showContent();
if (localStorageData) {
await loadContent(localStorageData);
lastUpdated.startTimer();
} else {
await updateLocalStorageAndLoadContent();
}
});

function wireUpButtons(firebase: Firebase) {
const loginButton = document.getElementById('login-button')!;
const logoutButton = document.getElementById('logout-button')!;
const editPullRequestsButton = document.getElementById('edit-pull-requests')!;
const editActionsButton = document.getElementById('edit-actions')!;

loginButton.addEventListener('click', async () => {
const firebase = new Firebase();
const signedIn = await firebase.signIn();
if (!signedIn) { return; }
await updateLocalStorageAndLoadContent();
});

logoutButton.addEventListener('click', () => {
const firebase = new Firebase();
firebase.signOut();
clearSiteData();
window.location.reload();
});

editPullRequestsButton.addEventListener('click', () => {
console.log('Edit pull requests');
if (document.getElementById('config-entries')!.children.length === 0) {
initializePullRequestsConfig(firebase);
}
document.getElementById('config-modal')!.classList.remove('hidden');
});

editActionsButton.addEventListener('click', () => {
console.log('Edit actions');
initializeActionsConfig(firebase);
document.getElementById('config-modal')!.classList.remove('hidden');
});

document.getElementById('add-entry')!.addEventListener('click', () => {
addConfigEntry();
});

document.getElementById('close-modal')!.addEventListener('click', () => {
document.getElementById('config-modal')!.classList.add('hidden');
});
;

document.getElementById('pull-requests-config-form')!.addEventListener('submit', async (event) => {
event.preventDefault();
const form = event.target as HTMLFormElement;
const entries = Array.from(form.querySelectorAll('.config-entry')).map(entry => {
const repo = (entry.querySelector('select[name="repo"]') as HTMLSelectElement).value;
const [org, repoName] = repo.split('/');
return {
org,
repo: repoName,
filter: (entry.querySelector('input[name="filter"]') as HTMLInputElement).value,
};
});

const currentConfig = await firebase.getConfig();

await firebase.saveConfig([...entries], currentConfig.actions);
document.getElementById('config-modal')!.classList.add('hidden');
});

}


async function updateLocalStorageAndLoadContent() {
await fetchDataAndSaveToLocalStorage();
const updatedData = getSiteData();
if (!updatedData) {
setNoContent();
}
await loadContent(updatedData);
}


export function sanitizeInput(input: string): string {
const div = document.createElement('div');
div.textContent = input;
return div.innerHTML;
}

function addConfigEntry(repos: string[], org = '', repo = '', filter = '') {
const entry = document.createElement('div');
entry.classList.add('config-entry', 'config-group', 'mb-4');
entry.setAttribute('draggable', 'true');
entry.innerHTML = `
<label class="block text-sm font-medium mb-1">Repository</label>
<select name="repo" class="w-full p-2 bg-gray-700 rounded">
${repos.map(repo => `<option value="${repo}">${repo}</option>`).join('')}
</select>
<label class="block text-sm font-medium mb-1 mt-2">Filter</label>
<input type="text" name="filter" class="w-full p-2 bg-gray-700 rounded" value="${filter}">
`;
console.log(document.getElementById('config-entries'));
document.getElementById('config-entries')!.appendChild(entry);
}

async function initializePullRequestsConfig(firebase: Firebase) {
const config = await firebase.getConfig();
console.log(config);
const repos = await getUserRepos();
console.log(repos);
config.pullRequests.forEach(prConfig => {
addConfigEntry(repos, prConfig.org, prConfig.repo, prConfig.filter);
});
document.getElementById('config-modal')!.classList.remove('hidden');
}

async function initializeActionsConfig(firebase: Firebase) {
const config = await firebase.getConfig();
const repos = await getUserRepos();
config.actions.forEach(actionConfig => {
addConfigEntry(repos, actionConfig.repo, actionConfig.filter);
});
document.getElementById('config-modal')!.classList.remove('hidden');
lastUpdated.startTimer();
}
5 changes: 5 additions & 0 deletions src/modules/services/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
export const config = `
{
"pullRequests": [
{
"org": "JHADigitalCore",
"repo": "general-ledger",
"filter": ""
},
{
"org": "JHADigitalCore",
"repo": "general-ledger-service",
Expand Down
66 changes: 35 additions & 31 deletions src/modules/ui/elements.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
export const AUTHORIZED = document.getElementById('authorized');
export const LOGIN_BUTTON = document.getElementById('login-button');
export const LOGOUT_BUTTON = document.getElementById('logout-button');
export const SETTINGS_BUTTON = document.getElementById('settings-button');
export const TAB_PULL_REQUESTS = document.getElementById('tab-pull-requests');
export const TAB_ACTIONS = document.getElementById('tab-actions');
export const PULL_REQUESTS_SECTION = document.getElementById('pull-requests-section');
export const ACTIONS_SECTION = document.getElementById('actions-section');
export const PULL_REQUESTS_DIV = document.getElementById('pull-requests');
export const ACTIONS_DIV = document.getElementById('actions');
export const LOADING_PULLS = document.getElementById('loading-pulls');
export const LOADING_ACTIONS = document.getElementById('loading-actions');
export const AUTHORIZED = document.getElementById('authorized')!;
export const LOGIN_BUTTON = document.getElementById('login-button')!;
export const LOGOUT_BUTTON = document.getElementById('logout-button')!;
export const TAB_PULL_REQUESTS = document.getElementById('tab-pull-requests')!;
export const TAB_ACTIONS = document.getElementById('tab-actions')!;
export const PULL_REQUESTS_SECTION = document.getElementById('pull-requests-section')!;
export const ACTIONS_SECTION = document.getElementById('actions-section')!;
export const PULL_REQUESTS_DIV = document.getElementById('pull-requests')!;
export const ACTIONS_DIV = document.getElementById('actions')!;
export const LOADING = document.getElementById('loading')!;
export const EDIT_PULL_REQUESTS_BUTTON = document.getElementById('edit-pull-requests')!;
export const EDIT_ACTIONS_BUTTON = document.getElementById('edit-actions')!;
export const LAST_UPDATED = document.getElementById('last-updated')!;

export function toggleLogin(isAuthorized: boolean) {
if (isAuthorized) {
AUTHORIZED?.classList.remove('hidden');
LOGIN_BUTTON?.classList.add('hidden');
LOGOUT_BUTTON?.classList.remove('hidden');
SETTINGS_BUTTON?.classList.remove('hidden');
AUTHORIZED.classList.remove('hidden');
LOGIN_BUTTON.classList.add('hidden');
LOGOUT_BUTTON.classList.remove('hidden');
} else {
AUTHORIZED?.classList.add('hidden');
LOGIN_BUTTON?.classList.remove('hidden');
LOGOUT_BUTTON?.classList.add('hidden');
SETTINGS_BUTTON?.classList.add('hidden');
AUTHORIZED.classList.add('hidden');
LOGIN_BUTTON.classList.remove('hidden');
LOGOUT_BUTTON.classList.add('hidden');
}
}

export function removeLoadingIndicators() {
LOADING_PULLS?.remove();
LOADING_ACTIONS?.remove();


export function hideLoading() {
LOADING.classList.add('hidden');
}

export function showLoading() {
LOADING.classList.remove('hidden');
}

export function handleTabs() {
TAB_PULL_REQUESTS?.addEventListener('click', () => switchTab(TAB_PULL_REQUESTS));
TAB_ACTIONS?.addEventListener('click', () => switchTab(TAB_ACTIONS));
TAB_PULL_REQUESTS.addEventListener('click', () => switchTab(TAB_PULL_REQUESTS));
TAB_ACTIONS.addEventListener('click', () => switchTab(TAB_ACTIONS));
}

function switchTab(activeTab: HTMLElement | null) {
activeTab?.classList.add('active');
if (activeTab === TAB_PULL_REQUESTS) {
PULL_REQUESTS_SECTION?.classList.remove('hidden');
ACTIONS_SECTION?.classList.add('hidden');
TAB_ACTIONS?.classList.remove('active');
PULL_REQUESTS_SECTION.classList.remove('hidden');
ACTIONS_SECTION.classList.add('hidden');
TAB_ACTIONS.classList.remove('active');
} else {
ACTIONS_SECTION?.classList.remove('hidden');
PULL_REQUESTS_SECTION?.classList.add('hidden');
TAB_PULL_REQUESTS?.classList.remove('active');
ACTIONS_SECTION.classList.remove('hidden');
PULL_REQUESTS_SECTION.classList.add('hidden');
TAB_PULL_REQUESTS.classList.remove('active');
}
}
5 changes: 3 additions & 2 deletions src/modules/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { LOGIN_BUTTON, LOGOUT_BUTTON } from './elements';
export * from './ui';
export * from './elements';
export * from './ui';
export * from './timer';
Loading

0 comments on commit 3a64abf

Please sign in to comment.