-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
093b5db
commit 3a64abf
Showing
14 changed files
with
398 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
Oops, something went wrong.