mirror of
				https://github.com/tormachris/cf-workers-status-page.git
				synced 2025-11-03 20:36:24 +01:00 
			
		
		
		
	feat: add monitor filter field
This commit is contained in:
		@@ -5,11 +5,28 @@ import {
 | 
			
		||||
  getLastUpdate,
 | 
			
		||||
  getMonitors,
 | 
			
		||||
  getMonitorsHistory,
 | 
			
		||||
  useKeyPress,
 | 
			
		||||
} from '../src/functions/helpers'
 | 
			
		||||
 | 
			
		||||
import config from '../config.yaml'
 | 
			
		||||
import MonitorStatusLabel from '../src/components/monitorStatusLabel'
 | 
			
		||||
import MonitorStatusHeader from '../src/components/monitorStatusHeader'
 | 
			
		||||
import MonitorFilter from '../src/components/monitorFilter'
 | 
			
		||||
 | 
			
		||||
import { Store } from 'laco'
 | 
			
		||||
import { useStore } from 'laco-react'
 | 
			
		||||
 | 
			
		||||
const MonitorStore = new Store(
 | 
			
		||||
  {
 | 
			
		||||
    monitors: config.monitors,
 | 
			
		||||
    visible: config.monitors,
 | 
			
		||||
    activeFilter: false
 | 
			
		||||
  }
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const filterByTerm = (term) => MonitorStore.set(
 | 
			
		||||
  state => ({ visible: state.monitors.filter((monitor) => monitor.name.toLowerCase().includes(term)) })
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
export async function getEdgeProps() {
 | 
			
		||||
  // get KV data
 | 
			
		||||
@@ -50,6 +67,9 @@ export default function Index({
 | 
			
		||||
  monitorsOperational,
 | 
			
		||||
  kvLastUpdate,
 | 
			
		||||
}) {
 | 
			
		||||
  const state = useStore(MonitorStore)
 | 
			
		||||
  const slash = useKeyPress('/')
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <div>
 | 
			
		||||
      <Head>
 | 
			
		||||
@@ -62,18 +82,24 @@ export default function Index({
 | 
			
		||||
        <link rel="stylesheet" href="./main.css" />
 | 
			
		||||
      </Head>
 | 
			
		||||
      <div className="ui basic segment container">
 | 
			
		||||
        <h1 className="ui huge title header">
 | 
			
		||||
          <img
 | 
			
		||||
            className="ui middle aligned tiny image"
 | 
			
		||||
            src={config.settings.logo}
 | 
			
		||||
        <div className="horizontal flex between">
 | 
			
		||||
          <h1 className="ui huge marginless title header">
 | 
			
		||||
            <img
 | 
			
		||||
              className="ui middle aligned tiny image"
 | 
			
		||||
              src={config.settings.logo}
 | 
			
		||||
            />
 | 
			
		||||
            {config.settings.title}
 | 
			
		||||
          </h1>
 | 
			
		||||
          <MonitorFilter
 | 
			
		||||
            active={slash}
 | 
			
		||||
            callback={filterByTerm}
 | 
			
		||||
          />
 | 
			
		||||
          {config.settings.title}
 | 
			
		||||
        </h1>
 | 
			
		||||
        </div>
 | 
			
		||||
        <MonitorStatusHeader
 | 
			
		||||
          operational={monitorsOperational}
 | 
			
		||||
          lastUpdate={kvLastUpdate}
 | 
			
		||||
        />
 | 
			
		||||
        {config.monitors.map((monitor, key) => {
 | 
			
		||||
        {state.visible.map((monitor, key) => {
 | 
			
		||||
          return (
 | 
			
		||||
            <div key={key} className="ui segment">
 | 
			
		||||
              <div
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user