Skip to content
The Chat Archive
gpt-4-1106-preview· OpenAI WildChat-4.8M (AI2)

import { FolderType } from "@openchat/types" import { useFolders } from "@openchat/ui"…

  1. User

    import { FolderType } from "@openchat/types" import { useFolders } from "@openchat/ui" import React, { useEffect, useState } from "react" import { TouchableOpacity, View } from "react-native" import { StyledText } from "../../../ui-components/styled-text/styled-text" import { NestableDraggableFlatList, NestableScrollContainer, RenderItemParams, } from "react-native-draggable-flatlist" import { AppConfig } from "../../../app/app.config" import { AppController } from "../../../app/app.globals" import { NavigationRef } from "../../../navigation/navigation.hooks" import { Button } from "../../../ui-components/button/button.component" import { Icon } from "../../../ui-components/icon/icon.component" import { StickyHeader } from "../../../ui-components/sticky-header/sticky-header.component" import { TemplateText } from "../../../ui-components/template-text/template-text.component" import { FolderMangePopup } from "./folder-manage-popup" import { useStyles } from "./folder-manage-style" import { StickyFooter } from "../../../ui-components/sticky-footer/sticky-footer.component" import { MenuOpener } from "../../../ui-components/menu/menu-opener.provider"

    export const FolderManage = () => { // --------------------------------------------------------------------------- // variables // ---------------------------------------------------------------------------

    const styles = useStyles() const folders = useFolders() // const [reorderedFolders, setReorderedFolders] = useState<FolderType[]>([]) // const [folder, setFolder] = useState<FolderType[]>(folders)

    // --------------------------------------------------------------------------- // effects // ---------------------------------------------------------------------------

    // useEffect(() => { // setFolder(folders) // }, [folder])

    // --------------------------------------------------------------------------- // functions // ---------------------------------------------------------------------------

    const renderItem = ({ item, drag, isActive, }: RenderItemParams) => ( <View style={{ flexDirection: "row", gap: 10, alignItems: "center" }}> <TouchableOpacity onLongPress={() => { drag() }} > {isActive ? ( ) : ( )} {item.name}

      <MenuOpener content={<FolderMangePopup folder={item} />}>
        <Icon
          name="fa-regular fa-ellipsis-vertical"
          size={18}
          fill={"#8592AA"}
        />
      </MenuOpener>
    </View>
    

    )

    // --------------------------------------------------------------------------- return ( <View style={AppConfig.isTablet ? styles.tabletContainer : styles.container} > <StickyHeader goBack={true} background="pattern" type="modal" title="Manage Folders" onPress={() => NavigationRef.goBack()} header={Manage Folders} > Create folders for different groups of chats and quickly switch between them

          {/* --------------------------------------------------------------------------- */}
          {/* FOLDER LIST */}
          {/* --------------------------------------------------------------------------- */}
    
          {folders.length > 0 && (
            <View style={{ marginTop: 20 }}>
              <NestableScrollContainer>
                <NestableDraggableFlatList
                  scrollEnabled={true}
                  data={folders}
                  renderItem={renderItem}
                  keyExtractor={(item) => item.id}
                  onDragEnd={async ({ data }) => {
                    await AppController.folder.reorder({
                      folderIds: data.map((folder) => folder.id),
                    })
                  }}
                />
              </NestableScrollContainer>
            </View>
          )}
    
          {/* --------------------------------------------------------------------------- */}
          {/* EMPTY LIST MESSAGE */}
          {/* --------------------------------------------------------------------------- */}
    
          {folders.length === 0 && (
            <View style={styles.emptyResult}>
              <TemplateText
                title="You don't have folders"
                description={
                  <StyledText>
                    Press
                    <TouchableOpacity
                      style={styles.addFolderWrapper}
                      onPress={() => NavigationRef.navigate("FolderUpsert", {})}
                    >
                      <StyledText style={styles.addFolderText}>
                        add folder
                      </StyledText>
                    </TouchableOpacity>
                    button to create a new folder.
                  </StyledText>
                }
                style={{ alignItems: "center" }}
              />
            </View>
          )}
        </View>
      </StickyHeader>
    
      {/* --------------------------------------------------------------------------- */}
      {/* FOOTER & BUTTON */}
      {/* --------------------------------------------------------------------------- */}
    
      <StickyFooter size="small" withLine>
        <Button
          containerStyle={styles.btnWrapper}
          type="outline"
          icon="folder"
          onPress={() => NavigationRef.navigate("FolderUpsert", {})}
        >
          Add folder
        </Button>
      </StickyFooter>
    </View>
    

    ) } the issue drag and drop not working. How to fix it ?

  2. Assistant

    Drag and drop functionality issues in React Native can arise from various causes. Without more specific error information, it's tough to pinpoint the exact problem, but here are some common troubleshooting steps you can take:

    1. Ensure NestableDraggableFlatList Props Are Correct: Verify that all necessary props are being passed correctly to NestableDraggableFlatList. For example, onDragEnd should receive a function that updates the state with the new data order.

    2. State Update: The commented code for state update (useState, useEffect) suggests that you wanted to manage folder state locally but then commented it out. If you're relying on an external source like useFolders, ensure it provides the updated list after drag-and-drop operations.

    3. Drag Handle: Ensure the TouchableOpacity which you're using as the drag handle is functioning correctly. If the drag gesture is not recognized, the drag operation will not initiate. Check if the onLongPress callback is firing correctly by adding a console log or debugger statement.

    4. List Key: Every item in your list should have a unique key for React to correctly identify which items have changed. The key extractor seems to use item.id which should be fine as long as item.id is unique.

    5. Gesture Handling: If you're using React Navigation, there might be gesture handler conflicts. Make sure that the gesture handling in React Navigation doesn't interfere with the drag-and-drop gestures.

    6. Native Modules: The react-native-draggable-flatlist library may have native dependencies. If so, ensure they've been linked correctly if you're not using autolinking (mostly for older React Native versions). If you recently installed or updated the package, you may need to rebuild your project to make sure all native modules are correctly linked.

    7. Check Library Issues: Look at the react-native-draggable-flatlist GitHub issues page for similar problems reported by other users. It’s possible that you may be encountering a known bug with a solution already provided.

    8. Permissions and Android Version: If you are testing on an Android device, some versions have improved support for certain gestures. Also, for certain features or libraries to work, you might need to grant the appropriate permissions in your AndroidManifest.xml.

    9. Debugging Logs: Add logging throughout your drag-and-drop callbacks to ensure the functions are being called correctly and the order of the folders is being set as expected.

    10. Library Versions: Check that you are using compatible versions of react-native-draggable-flatlist and your React Native version.

    Test each of these steps one by one. If the problem is still not resolved, you may need to provide additional code context or error output for further assistance.