<commit_before>/*
 @author <NAME>
 @component AppStorage
 */

screens.app.storage = function AppStorage(me, { core, ui, widget, storage, react }) {
    const {
        DropDown,
        Item,
        Bar,
        Field,
        Element,
        Direction,
        Language,
        Text,
        Input,
        Clone,
        Path,
        Modal,
        Separator,
        TextArea,
        List,
        Menu,
        ProgressRing,
        Spinner
    } = react;

    const HomeFolder = () => (<>
        <Text language="eng">Home</Text>
        <Text language="heb">בית</Text>
    </>);

    const AppToolbar = ({ state }) => {
        const { filterState, pathState, languageState, sortState, searchState, sortDirectionState } = state;
        const [path] = pathState;
        const languageItems = (me.languages || []).map(language => {
            const name = core.string.title(language.name);
            return (<Item key={language.id} id={language.id}>{name}</Item>);
        });
        const sortItems = (me.sort || []).map(sort => {
            return (<Item key={sort.id} id={sort.id}>{sort.name}</Item>);
        });
        const filterItems = (me.filter || []).map(filter => {
            return (<Item key={filter.id} id={filter.id}>{filter.name}</Item>);
        });
        const sortDirectionItems = (me.sortDirection || []).map(sort => {
            return (<Item key={sort.id} id={sort.id}>{sort.name}</Item>);
        });
        const pathItems = (path || []).map((name, idx) => {
            return (<Item key={idx} id={idx + 1}>{name}</Item>);
        });
        const rootItem = (<Item id={0}>
            <HomeFolder />
        </Item>);
        const noneItem = (<Item id="none" multiple={false}>
            <Text language="eng">None</Text>
            <Text language="heb">אין</Text>
        </Item>);
        const isMobile = core.device.isMobile();
        const PathOrDropDown = isMobile ? DropDown : Path;
        return (
            <Bar>
                <Field label={
                    <>
                        <Text language="eng">Language</Text>
                        <Text language="heb">שפה</Text>
                    </>
                }>
                    <DropDown state={languageState}>
                        {languageItems}
                    </DropDown>
                </Field>
                <Field label={
                    <>
                        <Text language="eng">Sort</Text>
                        <Text language="heb">מיון</Text>
                    </>
                }>
                    <DropDown state={sortState}>
                        {sortItems}
                        <Separator />
                        <Clone state={sortDirectionState} hideCurrent={true}>
                            {sortDirectionItems}
                        </Clone>
                    </DropDown>
                </Field>
                <Field label={
                    <>
                        <Text language="eng">Filter</Text>
                        <Text language="heb">סינון</Text>
                    </>
                }>
                    <DropDown state={filterState}>
                        {noneItem}
                        {filterItems}
                    </DropDown>
                </Field>
                <Field label={
                    <>
                        <Text language="eng">Path</Text>
                        <Text language="heb">נתיב</Text>
                    </>
                }>
                    <PathOrDropDown state={pathState} path={true}>
                        {rootItem}
                        {pathItems}
                    </PathOrDropDown>
                </Field>
                <Element style={{ flex: 1 }}></Element>
                <Field label={
                    <>
                        <Text language="eng">Search</Text>
                        <Text language="heb">חיפוש</Text>
                    </>
                }>
                    <Input size="1em" type="Search" state={searchState} />
                </Field>
            </Bar>
        );
    };

    const MenuActions = ({ name, state, type, parent = false, root = false }) => {
        const { dialogState, pathState, updateState, itemsState } = state;
        const [path, setPath] = pathState;
        const [, setDialog] = dialogState;
        const [items] = itemsState;
        const [, setUpdateCounter] = updateState;
        let parentPath = path.join("/");
        if (parent) {
            parentPath = path.slice(0, -1).join("/");
        }
        const item = items.find(item => item.name === name);
        const dialogObject = {
            path: core.path.normalize(parentPath, name),
            items: [item].filter(Boolean),
            name,
            parent,
            context: path.join("/"),
            type,
            cancel: () => {
                setDialog(null);
            }
        };
        const createFolder = async () => {
            setDialog({ mode: "create", type: "folder", name: "" });
        };
        const createFile = async () => {
            setDialog({ mode: "create", type: "file", name: "" });
        };
        const gotoFolder = () => {
            setPath(path.slice(0, path.length - 1));
        };
        const renameItem = async () => {
            setDialog({ ...dialogObject, mode: "rename" });
        };
        const organizeItems = async () => {
            setDialog({
                ...dialogObject, query: "", mode: "organize", done: async ({ state }) => {
                    const { queryState } = state;
                    const [query] = queryState;
                    const items = await storage.fs.list(dialogObject.path);
                    for (const item of items) {
                        const { name, path } = item;
                        const result = name.match(core.string.regex(query));
                        if (result && result.length > 1) {
                            const targetPath = dialogObject.path + "/" + result.slice(1).join("/") + "/" + name;
                            await storage.fs.createPath(dialogObject.path, targetPath);
                            await storage.fs.rename(path, targetPath);
                        }
                    }
                    setDialog(null);
                    setUpdateCounter(counter => counter + 1);
                }<commit_msg>bug fix<commit_after>/*
 @author <NAME>
 @component AppStorage
 */

screens.app.storage = function AppStorage(me, { core, ui, widget, storage, react }) {
    const {
        DropDown,
        Item,
        Bar,
        Field,
        Element,
        Direction,
        Language,
        Text,
        Input,
        Clone,
        Path,
        Modal,
        Separator,
        TextArea,
        List,
        Menu,
        ProgressRing,
        Spinner
    } = react;

    const HomeFolder = () => (<>
        <Text language="eng">Home</Text>
        <Text language="heb">בית</Text>
    </>);

    const AppToolbar = ({ state }) => {
        const { filterState, pathState, languageState, sortState, searchState, sortDirectionState } = state;
        const [path] = pathState;
        const languageItems = (me.languages || []).map(language => {
            const name = core.string.title(language.name);
            return (<Item key={language.id} id={language.id}>{name}</Item>);
        });
        const sortItems = (me.sort || []).map(sort => {
            return (<Item key={sort.id} id={sort.id}>{sort.name}</Item>);
        });
        const filterItems = (me.filter || []).map(filter => {
            return (<Item key={filter.id} id={filter.id}>{filter.name}</Item>);
        });
        const sortDirectionItems = (me.sortDirection || []).map(sort => {
            return (<Item key={sort.id} id={sort.id}>{sort.name}</Item>);
        });
        const pathItems = (path || []).map((name, idx) => {
            return (<Item key={idx} id={idx + 1}>{name}</Item>);
        });
        const rootItem = (<Item id={0}>
            <HomeFolder />
        </Item>);
        const noneItem = (<Item id="none" multiple={false}>
            <Text language="eng">None</Text>
            <Text language="heb">אין</Text>
        </Item>);
        const isMobile = core.device.isMobile();
        const PathOrDropDown = isMobile ? DropDown : Path;
        return (
            <Bar>
                <Field label={
                    <>
                        <Text language="eng">Language</Text>
                        <Text language="heb">שפה</Text>
                    </>
                }>
                    <DropDown state={languageState}>
                        {languageItems}
                    </DropDown>
                </Field>
                <Field label={
                    <>
                        <Text language="eng">Sort</Text>
                        <Text language="heb">מיון</Text>
                    </>
                }>
                    <DropDown state={sortState}>
                        {sortItems}
                        <Separator />
                        <Clone state={sortDirectionState} hideCurrent={true}>
                            {sortDirectionItems}
                        </Clone>
                    </DropDown>
                </Field>
                <Field label={
                    <>
                        <Text language="eng">Filter</Text>
                        <Text language="heb">סינון</Text>
                    </>
                }>
                    <DropDown state={filterState}>
                        {noneItem}
                        {filterItems}
                    </DropDown>
                </Field>
                <Field label={
                    <>
                        <Text language="eng">Path</Text>
                        <Text language="heb">נתיב</Text>
                    </>
                }>
                    <PathOrDropDown state={pathState} path={true}>
                        {rootItem}
                        {pathItems}
                    </PathOrDropDown>
                </Field>
                <Element style={{ flex: 1 }}></Element>
                <Field label={
                    <>
                        <Text language="eng">Search</Text>
                        <Text language="heb">חיפוש</Text>
                    </>
                }>
                    <Input size="1em" type="Search" state={searchState} />
                </Field>
            </Bar>
        );
    };

    const MenuActions = ({ name, state, type, parent = false, root = false }) => {
        const { dialogState, pathState, updateState, itemsState } = state;
        const [path, setPath] = pathState;
        const [, setDialog] = dialogState;
        const [items] = itemsState;
        const [, setUpdateCounter] = updateState;
        let parentPath = path.join("/");
        if (parent) {
            parentPath = path.slice(0, -1).join("/");
        }
        const item = items.find(item => item.name === name);
        const dialogObject = {
            path: core.path.normalize(parentPath, name),
            items: [item].filter(Boolean),
            name,
            parent,
            context: path.join("/"),
            type,
            cancel: () => {
                setDialog(null);
            }
        };
        const createFolder = async () => {
            setDialog({ mode: "create", type: "folder", name: "" });
        };
        const createFile = async () => {
            setDialog({ mode: "create", type: "file", name: "" });
        };
        const gotoFolder = () => {
            setPath(path.slice(0, path.length - 1));
        };
        const renameItem = async () => {
            setDialog({ ...dialogObject, mode: "rename" });
        };
        const organizeItems = async () => {
            setDialog({
                ...dialogObject, query: "", mode: "organize", done: async ({ state }) => {
                    const { queryState } = state;
                    const [query] = queryState;
                    const items = await storage.fs.list(dialogObject.path);
                    for (const item of items) {
                        const { name, path } = item;
                        const result = name.match(core.string.regex(query));
                        if (result && result.length > 1) {
                            const targetPath = dialogObject.path + "/" + result.slice(1).join("/");
                            await storage.fs.createPath(dialogObject.path, targetPath);
                            await storage.fs.rename(path, targetPath + "/" + name);
                        }
                    }
                    setDialog(null);
                    setUpdateCounter(counter => counter + 1);
                }
{'fraction_non_alphanumeric': 0.13848555815768931, 'fraction_numerical': 0.001717408274785324, 'mean_word_length': 1.200446581930608, 'pattern_counts': {'":': 0, '<': 167, '<?xml version=': 0, '>': 203, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7052095', 'n_tokens_mistral': 3331, 'n_tokens_neox': 3153, 'n_words': 663}