<commit_before>module App exposing (..)

import String exposing (isEmpty)
import Html exposing (..)
import Html.Events exposing (onSubmit, onInput, onClick)
import Html.Attributes exposing (id, class, type_, placeholder, value, autocomplete)
import Dict exposing (Dict)
import Dict as D

import Task exposing (Task)
import Dom.Scroll exposing (toBottom)


main =
  Html.program {
    init = ( model, Cmd.none ),
    view = view,
    update = update,
    subscriptions = \_ -> Sub.none
  }


-- Model
type alias Line =
  {
    nick : String,
    text : String
  }

type alias Channel =
  {
    logs : List Line,
    newLine : String
  }

type alias Model =
  {
    nick : String,
    currentName : String,
    newName : String,
    channels : Dict String Channel
  }

model : Model
model = Model "알파카" "#a" "" (D.fromList [
  ("#a", Channel [] ""),
  ("#b", Channel [] ""),
  ("#c", Channel [] "")
  ])

getCurrentChannel : Model -> Channel
getCurrentChannel model =
  case D.get model.currentName model.channels of
    Nothing -> Channel [Line "NOTICE" "Currently not in a (valid) channel."] ""
    Just channel -> channel


-- Update
type Msg = SendLine
         | TypeNewLine String
         | TypeNewName String
         | CreateChannel
         | ChangeChannel String
         | CloseChannel String
         | Noop

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
  let currentChannel = getCurrentChannel model in
  case msg of
    SendLine ->
        if isEmpty currentChannel.newLine
        then ( model, Cmd.none )
        else (
          updateCurrentChannel model { currentChannel | newLine = "",
          logs = currentChannel.logs ++ [Line model.nick currentChannel.newLine]
          }, Task.attempt (\_ -> Noop) (toBottom "logs")
        )
    TypeNewLine msg ->
      (updateCurrentChannel model { currentChannel | newLine = msg }, Cmd.none)
    TypeNewName msg ->
      ( { model | newName = msg }, Cmd.none )
    CreateChannel ->
      if (D.member model.newName model.channels || model.newName == "")
      then ( model, Cmd.none ) {- Error notification logic should be added -}
      else (
        { model
        | channels = (D.insert model.newName (Channel [] "") model.channels), newName = ""
        }, Task.perform identity (Task.succeed (ChangeChannel model.newName))
        )
    ChangeChannel name ->
      ( { model | currentName = name }, Task.attempt (\_ -> Noop) (toBottom "logs") )
    CloseChannel name ->
      let
        remainingChannels = D.filter (\channelName _ -> channelName /= name) model.channels
        newCurrentName =
          case List.head (D.keys remainingChannels) of
            Just newCurrentName -> newCurrentName
            Nothing -> ""
      in
        ( { model | channels = remainingChannels }
          , Task.perform identity (Task.succeed (ChangeChannel newCurrentName)))
    Noop -> ( model, Cmd.none )

updateCurrentChannel : Model -> Channel -> Model
updateCurrentChannel model updatedCurrentChannel =
  { model<commit_msg>Use String.isEmpty for empty string check<commit_after>module App exposing (..)

import String exposing (isEmpty)
import Html exposing (..)
import Html.Events exposing (onSubmit, onInput, onClick)
import Html.Attributes exposing (id, class, type_, placeholder, value, autocomplete)
import Dict exposing (Dict)
import Dict as D

import Task exposing (Task)
import Dom.Scroll exposing (toBottom)


main =
  Html.program {
    init = ( model, Cmd.none ),
    view = view,
    update = update,
    subscriptions = \_ -> Sub.none
  }


-- Model
type alias Line =
  {
    nick : String,
    text : String
  }

type alias Channel =
  {
    logs : List Line,
    newLine : String
  }

type alias Model =
  {
    nick : String,
    currentName : String,
    newName : String,
    channels : Dict String Channel
  }

model : Model
model = Model "알파카" "#a" "" (D.fromList [
  ("#a", Channel [] ""),
  ("#b", Channel [] ""),
  ("#c", Channel [] "")
  ])

getCurrentChannel : Model -> Channel
getCurrentChannel model =
  case D.get model.currentName model.channels of
    Nothing -> Channel [Line "NOTICE" "Currently not in a (valid) channel."] ""
    Just channel -> channel


-- Update
type Msg = SendLine
         | TypeNewLine String
         | TypeNewName String
         | CreateChannel
         | ChangeChannel String
         | CloseChannel String
         | Noop

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
  let currentChannel = getCurrentChannel model in
  case msg of
    SendLine ->
        if isEmpty currentChannel.newLine
        then ( model, Cmd.none )
        else (
          updateCurrentChannel model { currentChannel | newLine = "",
          logs = currentChannel.logs ++ [Line model.nick currentChannel.newLine]
          }, Task.attempt (\_ -> Noop) (toBottom "logs")
        )
    TypeNewLine msg ->
      (updateCurrentChannel model { currentChannel | newLine = msg }, Cmd.none)
    TypeNewName msg ->
      ( { model | newName = msg }, Cmd.none )
    CreateChannel ->
      if (D.member model.newName model.channels || isEmpty model.newName)
      then ( model, Cmd.none ) {- Error notification logic should be added -}
      else (
        { model
        | channels = (D.insert model.newName (Channel [] "") model.channels), newName = ""
        }, Task.perform identity (Task.succeed (ChangeChannel model.newName))
        )
    ChangeChannel name ->
      ( { model | currentName = name }, Task.attempt (\_ -> Noop) (toBottom "logs") )
    CloseChannel name ->
      let
        remainingChannels = D.filter (\channelName _ -> channelName /= name) model.channels
        newCurrentName =
          case List.head (D.keys remainingChannels) of
            Just newCurrentName -> newCurrentName
            Nothing -> ""
      in
        ( { model | channels = remainingChannels }
          , Task.perform identity (Task.succeed (ChangeChannel newCurrentName)))
    Noop -> ( model, Cmd.none )

updateCurrentChannel : Model -> Channel -> Model
updateCurrentChannel model updatedCurrentChannel =
  { model
{'fraction_non_alphanumeric': 0.11083581103402709, 'fraction_numerical': 0.0, 'mean_word_length': 2.491926182237601, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 43, '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': '1411387', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1706, 'n_words': 523}