mirror of
https://github.com/stashapp/stash.git
synced 2025-12-17 12:24:38 +03:00
Add scene duration filter (#313)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect } from "react";
|
||||
import { Button, ButtonGroup, InputGroup, Form } from "react-bootstrap";
|
||||
import { Icon } from "src/components/Shared";
|
||||
import { TextUtils } from "src/utils";
|
||||
import { DurationUtils } from "src/utils";
|
||||
|
||||
interface IProps {
|
||||
disabled?: boolean;
|
||||
@@ -11,67 +11,21 @@ interface IProps {
|
||||
}
|
||||
|
||||
export const DurationInput: React.FC<IProps> = (props: IProps) => {
|
||||
const [value, setValue] = useState<string>(
|
||||
secondsToString(props.numericValue)
|
||||
);
|
||||
const [value, setValue] = useState<string>(DurationUtils.secondsToString(props.numericValue));
|
||||
|
||||
useEffect(() => {
|
||||
setValue(secondsToString(props.numericValue));
|
||||
setValue(DurationUtils.secondsToString(props.numericValue));
|
||||
}, [props.numericValue]);
|
||||
|
||||
function secondsToString(seconds: number) {
|
||||
let ret = TextUtils.secondsToTimestamp(seconds);
|
||||
|
||||
if (ret.startsWith("00:")) {
|
||||
ret = ret.substr(3);
|
||||
|
||||
if (ret.startsWith("0")) {
|
||||
ret = ret.substr(1);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
function stringToSeconds(v: string) {
|
||||
if (!v) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const splits = v.split(":");
|
||||
|
||||
if (splits.length > 3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let seconds = 0;
|
||||
let factor = 1;
|
||||
while (splits.length > 0) {
|
||||
const thisSplit = splits.pop();
|
||||
if (thisSplit === undefined) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const thisInt = parseInt(thisSplit, 10);
|
||||
if (Number.isNaN(thisInt)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
seconds += factor * thisInt;
|
||||
factor *= 60;
|
||||
}
|
||||
|
||||
return seconds;
|
||||
}
|
||||
|
||||
function increment() {
|
||||
let seconds = stringToSeconds(value);
|
||||
let seconds = DurationUtils.stringToSeconds(value);
|
||||
seconds += 1;
|
||||
props.onValueChange(seconds);
|
||||
}
|
||||
|
||||
function decrement() {
|
||||
let seconds = stringToSeconds(value);
|
||||
let seconds = DurationUtils.stringToSeconds(value);
|
||||
seconds -= 1;
|
||||
props.onValueChange(seconds);
|
||||
}
|
||||
@@ -112,7 +66,7 @@ export const DurationInput: React.FC<IProps> = (props: IProps) => {
|
||||
disabled={props.disabled}
|
||||
value={value}
|
||||
onChange={(e: any) => setValue(e.target.value)}
|
||||
onBlur={() => props.onValueChange(stringToSeconds(value))}
|
||||
onBlur={() => props.onValueChange(DurationUtils.stringToSeconds(value))}
|
||||
placeholder="hh:mm:ss"
|
||||
/>
|
||||
<InputGroup.Append>
|
||||
|
||||
Reference in New Issue
Block a user