mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
fix: remove unused file creation date retrieval and clean up SortMenu component
This commit is contained in:
@@ -3,10 +3,9 @@ import logging
|
||||
import os
|
||||
import yaml
|
||||
from .utils import (get_category_directory, load_yaml_file, validate,
|
||||
save_yaml_file, update_yaml_file, get_file_created_date,
|
||||
get_file_modified_date, test_regex_pattern,
|
||||
test_format_conditions, check_delete_constraints,
|
||||
filename_to_display)
|
||||
save_yaml_file, update_yaml_file, get_file_modified_date,
|
||||
test_regex_pattern, test_format_conditions,
|
||||
check_delete_constraints, filename_to_display)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logger.setLevel(logging.INFO)
|
||||
@@ -34,8 +33,6 @@ def retrieve_all(category):
|
||||
file_name,
|
||||
"content":
|
||||
content,
|
||||
"created_date":
|
||||
get_file_created_date(file_path),
|
||||
"modified_date":
|
||||
get_file_modified_date(file_path)
|
||||
})
|
||||
@@ -77,8 +74,6 @@ def handle_item(category, name):
|
||||
file_name,
|
||||
"content":
|
||||
content,
|
||||
"created_date":
|
||||
get_file_created_date(file_path),
|
||||
"modified_date":
|
||||
get_file_modified_date(file_path)
|
||||
}), 200
|
||||
|
||||
@@ -67,16 +67,6 @@ def _setup_yaml_quotes():
|
||||
yaml.add_representer(str, str_presenter)
|
||||
|
||||
|
||||
def get_file_created_date(file_path: str) -> str:
|
||||
"""Get file creation date in ISO format"""
|
||||
try:
|
||||
stats = os.stat(file_path)
|
||||
return datetime.fromtimestamp(stats.st_ctime).isoformat()
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting creation date for {file_path}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_file_modified_date(file_path: str) -> str:
|
||||
"""Get file last modified date in ISO format"""
|
||||
try:
|
||||
|
||||
@@ -1,70 +1,86 @@
|
||||
// SortMenu.jsx
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import {useState, useRef, useEffect} from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
function SortMenu({ sortBy, setSortBy }) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const dropdownRef = useRef(null);
|
||||
function SortMenu({sortBy, setSortBy}) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const dropdownRef = useRef(null);
|
||||
|
||||
const options = [
|
||||
{ value: 'title', label: 'Sort by Title' },
|
||||
{ value: 'dateCreated', label: 'Sort by Date Created' },
|
||||
{ value: 'dateModified', label: 'Sort by Date Modified' },
|
||||
];
|
||||
const options = [
|
||||
{value: 'title', label: 'Sort by Title'},
|
||||
{value: 'dateModified', label: 'Sort by Date Modified'}
|
||||
];
|
||||
|
||||
useEffect(() => {
|
||||
function handleClickOutside(event) {
|
||||
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
function handleClickOutside(event) {
|
||||
if (
|
||||
dropdownRef.current &&
|
||||
!dropdownRef.current.contains(event.target)
|
||||
) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
}
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () =>
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="relative inline-block text-left" ref={dropdownRef}>
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex justify-between items-center w-full rounded-md border border-gray-600 shadow-sm px-4 py-2 bg-gray-700 text-sm font-medium text-white hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white"
|
||||
onClick={() => setIsOpen(!isOpen)}
|
||||
>
|
||||
{options.find(option => option.value === sortBy)?.label}
|
||||
<svg className="-mr-1 ml-2 h-5 w-5" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
|
||||
<path fillRule="evenodd" d="M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z" clipRule="evenodd" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
return (
|
||||
<div className='relative inline-block text-left' ref={dropdownRef}>
|
||||
<div>
|
||||
<button
|
||||
type='button'
|
||||
className='inline-flex justify-between items-center w-full rounded-md border border-gray-600 shadow-sm px-4 py-2 bg-gray-700 text-sm font-medium text-white hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-800 focus:ring-white'
|
||||
onClick={() => setIsOpen(!isOpen)}>
|
||||
{options.find(option => option.value === sortBy)?.label}
|
||||
<svg
|
||||
className='-mr-1 ml-2 h-5 w-5'
|
||||
xmlns='http://www.w3.org/2000/svg'
|
||||
viewBox='0 0 20 20'
|
||||
fill='currentColor'
|
||||
aria-hidden='true'>
|
||||
<path
|
||||
fillRule='evenodd'
|
||||
d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'
|
||||
clipRule='evenodd'
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{isOpen && (
|
||||
<div className="origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-gray-700 ring-1 ring-black ring-opacity-5 z-50">
|
||||
<div className="py-1" role="menu" aria-orientation="vertical" aria-labelledby="options-menu">
|
||||
{options.map((option) => (
|
||||
<button
|
||||
key={option.value}
|
||||
onClick={() => {
|
||||
setSortBy(option.value);
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={`${
|
||||
sortBy === option.value ? 'bg-gray-600 text-white' : 'text-gray-200'
|
||||
} block w-full text-left px-4 py-2 text-sm hover:bg-gray-600 hover:text-white`}
|
||||
role="menuitem"
|
||||
>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{isOpen && (
|
||||
<div className='origin-top-right absolute right-0 mt-2 w-56 rounded-md shadow-lg bg-gray-700 ring-1 ring-black ring-opacity-5 z-50'>
|
||||
<div
|
||||
className='py-1'
|
||||
role='menu'
|
||||
aria-orientation='vertical'
|
||||
aria-labelledby='options-menu'>
|
||||
{options.map(option => (
|
||||
<button
|
||||
key={option.value}
|
||||
onClick={() => {
|
||||
setSortBy(option.value);
|
||||
setIsOpen(false);
|
||||
}}
|
||||
className={`${
|
||||
sortBy === option.value
|
||||
? 'bg-gray-600 text-white'
|
||||
: 'text-gray-200'
|
||||
} block w-full text-left px-4 py-2 text-sm hover:bg-gray-600 hover:text-white`}
|
||||
role='menuitem'>
|
||||
{option.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
SortMenu.propTypes = {
|
||||
sortBy: PropTypes.string.isRequired,
|
||||
setSortBy: PropTypes.func.isRequired,
|
||||
sortBy: PropTypes.string.isRequired,
|
||||
setSortBy: PropTypes.func.isRequired
|
||||
};
|
||||
|
||||
export default SortMenu;
|
||||
export default SortMenu;
|
||||
|
||||
Reference in New Issue
Block a user