import { Fragment } from 'inferno';
import { useBackend, useLocalState } from '../backend';
import { Box, Button, Icon, Input, LabeledList, Section, Tabs } from '../components';
import { ComplexModal, modalOpen } from './common/ComplexModal';
import { Window } from '../layouts';
import { LoginInfo } from './common/LoginInfo';
import { LoginScreen } from './common/LoginScreen';
import { TemporaryNotice } from './common/TemporaryNotice';
import { createSearch } from 'common/string';
import { filter } from 'common/collections';
import { flow } from 'common/fp';
const doEdit = (context, field) => {
modalOpen(context, 'edit', {
field: field.edit,
value: field.value,
});
};
export const GeneralRecords = (_properties, context) => {
const { data } = useBackend(context);
const { authenticated, screen } = data;
if (!authenticated) {
return (
);
}
let body;
if (screen === 2) {
// List Records
body = ;
} else if (screen === 3) {
// Record Maintenance
body = ;
} else if (screen === 4) {
// View Records
body = ;
}
return (
);
};
/**
* Record selector.
*
* Filters records, applies search terms and sorts the alphabetically.
*/
const selectRecords = (records, searchText = '') => {
const nameSearch = createSearch(searchText, (record) => record.name);
const idSearch = createSearch(searchText, (record) => record.id);
const dnaSearch = createSearch(searchText, (record) => record.b_dna);
let fl = flow([
// Optional search term
searchText &&
filter((record) => {
return nameSearch(record) || idSearch(record) || dnaSearch(record);
}),
])(records);
return fl;
};
const GeneralRecordsList = (_properties, context) => {
const { act, data } = useBackend(context);
const [searchText, setSearchText] = useLocalState(context, 'searchText', '');
const records = selectRecords(data.records, searchText);
return (
setSearchText(value)} />
{records.map((record, i) => (
);
};
const GeneralRecordsMaintenance = (_properties, context) => {
const { act } = useBackend(context);
return act('del_all')} />;
};
const GeneralRecordsView = (_properties, context) => {
const { act, data } = useBackend(context);
const { general, printing } = data;
return (
act('del_r')}
/>
);
};
const GeneralRecordsViewGeneral = (_properties, context) => {
const { act, data } = useBackend(context);
const { general } = data;
if (!general || !general.fields) {
return (
General record lost!
act('new')} />
);
}
return (
{general.fields.map((field, i) => (
{field.value}
{!!field.edit && doEdit(context, field)} />}
))}
{general.skills || 'No data found.'}
{general.comments.length === 0 ? (
No comments found.
) : (
general.comments.map((comment, i) => (
{comment.header}
{comment.text}
act('del_c', { del_c: i + 1 })} />
))
)}
modalOpen(context, 'add_c')}
/>
{!!general.has_photos &&
general.photos.map((p, i) => (
Photo #{i + 1}
))}
);
};
const GeneralRecordsNavigation = (_properties, context) => {
const { act, data } = useBackend(context);
const { screen } = data;
return (
act('screen', { screen: 2 })}>
List Records
act('screen', { screen: 3 })}>
Record Maintenance
);
};