Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous fixes #105

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ export default function SearchComponent({
}) {
const [loading, setLoading] = useState(false);
const [open, setOpen] = useState(false);
const [filters, { addFilter, removeFilter, updateFilter, resetFilters }] = useFilters();
const [queryParams, setQueryParams] = useQueryParams();
const [query, setQuery] = useState("");
const [ready, setReady] = useState(false);

// Filters
const [filters, { addFilter, removeFilter, updateFilter, resetFilters }] = useFilters();
const activeFilters = filters.filter((f) => f.value !== "");

// Load the search state from the URL
useEffect(() => {
if (queryParams && !ready) {
Expand Down Expand Up @@ -122,7 +125,8 @@ export default function SearchComponent({
{open &&
filters.map((filter: Filter, index: number) => (
<div
key={filter.value}
// eslint-disable-next-line react/no-array-index-key
key={`${filter.value || filter.type}-${index}`}
className="flex flex-row items-stretch divide-x-1 overflow-x-scroll px-3"
>
<button
Expand Down Expand Up @@ -155,7 +159,7 @@ export default function SearchComponent({
<button
className={clsx(
"my-3 flex cursor-pointer flex-row items-center gap-2",
filters.length > 0 && "text-blue-400"
activeFilters.length > 0 && "text-blue-400"
)}
onClick={() => {
if (filters.length === 0) addFilter();
Expand All @@ -165,9 +169,11 @@ export default function SearchComponent({
>
<MdFilterAlt className="text-xl" />
<span className="text-xs font-semibold">
{filters.length === 0
{activeFilters.length === 0
? "Add a filter"
: `${filters.length} filters active, click here to edit them`}
: `${activeFilters.length} filter${
activeFilters.length > 1 ? "s" : ""
} active, click here to edit them`}
</span>
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function useQueryParams(): [

const encodeFilters = (filters: Filter[]): string => {
return filters
.filter((filter) => filter.value !== "")
.reduce((acc: string[], filter) => {
const { type, value } = filter;
return acc.concat([`${type}:${value}`]);
Expand Down Expand Up @@ -72,7 +73,8 @@ export default function useQueryParams(): [

// Filters
rawParams.delete("filters");
if (filters && filters.length > 0) rawParams.set("filters", encodeFilters(filters));
if (filters && filters.length > 0 && filters.some((filter) => filter.value !== ""))
rawParams.set("filters", encodeFilters(filters));

const base = window.location.pathname;

Expand Down
39 changes: 31 additions & 8 deletions src/construct/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Box:
containers: list = field(default_factory=list)
syntax: str = None
defective: bool = False
ambiguous: bool = False
ref: Box = None

def __hash__(self):
Expand Down Expand Up @@ -95,20 +96,30 @@ def get_all_boxes(json_file):


def search_box(fourcc, type=None, ref=None):
result = None
matches = 0
for value in BOXES.values():
for _box in value:
if type is not None:
if _box.fourcc == fourcc and _box.type == type:
return _box
result = _box
matches += 1
else:
if _box.fourcc == fourcc:
return _box

return Box(
fourcc=fourcc,
defective=True,
ref=ref,
)
result = _box
matches += 1

if matches == 1:
return result
if matches > 1:
result.ambiguous = True
return result
if matches == 0:
return Box(
fourcc=fourcc,
defective=True,
ref=ref,
)


def update_container(_spec, _box):
Expand Down Expand Up @@ -189,6 +200,18 @@ def main():
BOXES[spec] = set()
BOXES[spec] = BOXES[spec].union(extensions)

# List ambiguous boxes
buffer = []
for boxes in BOXES.values():
for _box in boxes:
if _box.ambiguous and _box.fourcc != "file":
buffer.append(_box.fourcc)

if len(buffer) > 0:
logger.error(
f"Ambiguous containers found ({len(set(buffer))}): {set(sorted(buffer))}"
)

# List defective boxes
buffer = []
for boxes in BOXES.values():
Expand Down
Loading