#what would the correct folder name be for a file

31 messages · Page 1 of 1 (latest)

slender agate
#

lowkey a silly question but im not sure lol.

what folder should I put this under

export const toggleFollowFunc = (id: string) => {
  const trpcUtils = api.useContext();
  return api.profile.toggleFollow.useMutation({
    onSuccess: ({ addedFollow }) => {
      trpcUtils.profile.getById.setData({ id }, (oldData) => {
        if (oldData == null) return;

        const countModifier = addedFollow ? 1 : -1;
        return {
          ...oldData,
          isFollowing: addedFollow,
          followersCount: oldData.followersCount + countModifier,
        }
      })
    }
  });
}```

thanks in advance 😄
dapper quartz
#

i usually end up centralizing all of the client-side code that makes HTTP requests in one place (either a single file if the API surface area is small, or a folder with a file per domain type if it's bigger)

i also wouldn't usually have the code for the server live in a folder within what appears to be the client code (even if i'm using a monorepo setup… in that case the client and server would usually be folders living next to eachother)

slender agate
#

oh the project just came like setup as one repo

slender agate
#

or should I put it in the same file as the api call

dapper quartz
#

what's in the server folder right now?

slender agate
dapper quartz
#

was i correct in assuming that is the actual server implementation (and it has its own main script that you run)?

slender agate
#

yup

dapper quartz
#

sorry i didn't mean what files, i meant what is it for

#

okay, then i would definitely not put code for the client into the folder for the server

slender agate
#

yeah

#

its the backend stuff

dapper quartz
#

those should be totally separate. you should also probably make sure you aren't bundling the server code into your client

#

(or vice versa)

slender agate
#

how do I check

dapper quartz
#

otherwise you'll have lots of unnecessary bloat, or worse case security problems since users of your frontend will be able to see all of your server code (and maybe its config, depending on how things are set up)

slender agate
#

im 95% sure its good

dapper quartz
#

look at the build output. sorry i can't be more specific without knowing more about the project setup

slender agate
#

its a T3 project

dapper quartz
#

i don't know what that is 🙂

slender agate
#

yea

#

so erm where would you put the file 😭

#

assuming its client side

#

components seemed like the wrong choice

dapper quartz
#

i guess i would follow whatever T3's conventions are. looking at their docs it definitely doesn't align with how i normally arrange things, so i don't think my opinions are really valid unless you want to totally reorganize stuff

#

don't be afraid to just make a new folder though if it doesn't fit anywhere naturally

#

ultimately the project should be organized in whatever way makes the most sense to you

slender agate
#

oh true I didnt know docs would say to do that